Skip to content

Commit

Permalink
fix: single BuildLogWriter method for ImageBuildInfo interface
Browse files Browse the repository at this point in the history
  • Loading branch information
zenkovev committed Dec 18, 2024
1 parent b2ec50b commit 17530fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
15 changes: 7 additions & 8 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ type ImageBuildInfo interface {
GetDockerfile() string // the relative path to the Dockerfile, including the file itself
GetRepo() string // get repo label for image
GetTag() string // get tag label for image
ShouldPrintBuildLog() bool // allow build log to be printed
GetBuildLogWriter() io.Writer // for output of build log if ShouldPrintBuildLog is true
BuildLogWriter() io.Writer // for output of build log, use io.Discard to disable the output
ShouldBuildImage() bool // return true if the image needs to be built
GetBuildArgs() map[string]*string // return the environment args used to build the from Dockerfile
GetAuthConfigs() map[string]registry.AuthConfig // Deprecated. Testcontainers will detect registry credentials automatically. Return the auth configs to be able to pull from an authenticated docker registry
Expand Down Expand Up @@ -412,16 +411,16 @@ func (c *ContainerRequest) ShouldKeepBuiltImage() bool {
return c.FromDockerfile.KeepImage
}

func (c *ContainerRequest) ShouldPrintBuildLog() bool {
return c.FromDockerfile.PrintBuildLog
}

func (c *ContainerRequest) GetBuildLogWriter() io.Writer {
func (c *ContainerRequest) BuildLogWriter() io.Writer {
if c.FromDockerfile.BuildLogWriter == nil {
c.FromDockerfile.BuildLogWriter = os.Stderr
}

return c.FromDockerfile.BuildLogWriter
if c.FromDockerfile.PrintBuildLog {
return c.FromDockerfile.BuildLogWriter
} else {
return io.Discard
}
}

// BuildOptions returns the image build options when building a Docker image from a Dockerfile.
Expand Down
5 changes: 1 addition & 4 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,7 @@ func (p *DockerProvider) BuildImage(ctx context.Context, img ImageBuildInfo) (st
}
defer resp.Body.Close()

output := io.Discard
if img.ShouldPrintBuildLog() {
output = img.GetBuildLogWriter()
}
output := img.BuildLogWriter()

// Always process the output, even if it is not printed
// to ensure that errors during the build process are
Expand Down

0 comments on commit 17530fa

Please sign in to comment.