Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(modules.kafka): Use broker container IP instead of host IP for advertised broker listener #1989

Merged
merged 10 commits into from May 8, 2024
1 change: 1 addition & 0 deletions container.go
Expand Up @@ -62,6 +62,7 @@ type Container interface {
CopyFileToContainer(ctx context.Context, hostFilePath string, containerFilePath string, fileMode int64) error
CopyFileFromContainer(ctx context.Context, filePath string) (io.ReadCloser, error)
GetLogProductionErrorChannel() <-chan error
Hostname(ctx context.Context) (string, error)
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
}

// ImageBuildInfo defines what is needed to build an image
Expand Down
9 changes: 9 additions & 0 deletions docker.go
Expand Up @@ -392,6 +392,15 @@ func (c *DockerContainer) Name(ctx context.Context) (string, error) {
return inspect.Name, nil
}

// Hostname gets the name of the container.
func (c *DockerContainer) Hostname(ctx context.Context) (string, error) {
inspect, err := c.inspectContainer(ctx)
if err != nil {
return "", err
}
return inspect.Config.Hostname, nil
}

// State returns container's running state
func (c *DockerContainer) State(ctx context.Context) (*types.ContainerState, error) {
inspect, err := c.inspectRawContainer(ctx)
Expand Down
4 changes: 2 additions & 2 deletions modules/kafka/kafka.go
Expand Up @@ -72,7 +72,7 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
return err
}

ip, err := c.ContainerIP(ctx)
hostname, err := c.Hostname(ctx)
if err != nil {
return err
}
Expand All @@ -82,7 +82,7 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
return err
}

scriptContent := fmt.Sprintf(starterScriptContent, host, port.Int(), ip)
scriptContent := fmt.Sprintf(starterScriptContent, host, port.Int(), hostname)

return c.CopyToContainer(ctx, []byte(scriptContent), starterScript, 0o755)
},
Expand Down