Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions cli/command/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"runtime"

Expand Down Expand Up @@ -166,15 +167,16 @@ func (out *lastProgressOutput) WriteProgress(prog progress.Progress) error {
// nolint: gocyclo
func runBuild(dockerCli command.Cli, options buildOptions) error {
var (
buildCtx io.ReadCloser
dockerfileCtx io.ReadCloser
err error
contextDir string
tempDir string
relDockerfile string
progBuff io.Writer
buildBuff io.Writer
remote string
buildCtx io.ReadCloser
dockerfileCtx io.ReadCloser
err error
contextDir string
tempDir string
relDockerfile string
progBuff io.Writer
buildBuff io.Writer
remote string
quietOutputBuffer *bytes.Buffer
)

if options.dockerfileFromStdin() {
Expand All @@ -189,7 +191,8 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
buildBuff = dockerCli.Out()
if options.quiet {
progBuff = bytes.NewBuffer(nil)
buildBuff = bytes.NewBuffer(nil)
quietOutputBuffer = bytes.NewBuffer(nil)
buildBuff = quietOutputBuffer
}
if options.imageIDFile != "" {
// Avoid leaving a stale file if we eventually fail
Expand Down Expand Up @@ -262,7 +265,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
// if streaming and dockerfile was not from stdin then read from file
// to the same reader that is usually stdin
if options.stream && dockerfileCtx == nil {
dockerfileCtx, err = os.Open(relDockerfile)
dockerfileCtx, err = os.Open(filepath.Join(contextDir, relDockerfile))
if err != nil {
return errors.Wrapf(err, "failed to open %s", relDockerfile)
}
Expand All @@ -284,7 +287,8 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
buildCtx = replaceDockerfileTarWrapper(ctx, buildCtx, relDockerfile, translator, &resolvedTags)
} else if dockerfileCtx != nil {
// if there was not archive context still do the possible replacements in Dockerfile
newDockerfile, _, err := rewriteDockerfileFrom(ctx, dockerfileCtx, translator)
var newDockerfile []byte
newDockerfile, resolvedTags, err = rewriteDockerfileFrom(ctx, dockerfileCtx, translator)
if err != nil {
return err
}
Expand Down Expand Up @@ -415,7 +419,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
jerr.Code = 1
}
if options.quiet {
fmt.Fprintf(dockerCli.Err(), "%s%s", progBuff, buildBuff)
fmt.Fprintf(dockerCli.Err(), "%s%s", progBuff, quietOutputBuffer)
}
return cli.StatusError{Status: jerr.Message, StatusCode: jerr.Code}
}
Expand All @@ -435,7 +439,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
// Everything worked so if -q was provided the output from the daemon
// should be just the image ID and we'll print that to stdout.
if options.quiet {
imageID = fmt.Sprintf("%s", buildBuff)
imageID = quietOutputBuffer.String()
fmt.Fprintf(dockerCli.Out(), imageID)
}

Expand Down