From 92c353582c210ebc351f7f5911273af76398a2a8 Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Fri, 20 Feb 2015 13:26:11 -0800 Subject: [PATCH] Build w/o verbose hangs w/RUN `docker build -q .` where Dockerfile contains a RUN cmd will hang on the RUN. It waits for the output stream to close but because of -q we never attached to the container and end up waiting forever. The fact that no one noticed this tells me that people may not actually use -q and if so I wonder if it would make sense to make -q work the may it does for other commands (like `docker ps`) and make it so it only shows the container ID at the end. A -q/quiet option that only hides the container RUN output apparently isn't really that useful since no one is using it. See: https://github.com/docker/docker/issues/4094 Signed-off-by: Doug Davis --- builder/internals.go | 7 +++-- integration-cli/docker_cli_build_test.go | 35 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/builder/internals.go b/builder/internals.go index 1c26babc1d..cc79debb3f 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -555,8 +555,11 @@ func (b *Builder) run(c *daemon.Container) error { return err } - if err := <-errCh; err != nil { - return err + if b.Verbose { + // Block on reading output from container, stop on err or chan closed + if err := <-errCh; err != nil { + return err + } } // Wait for it to finish diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index b94a9e147a..34b7448348 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -4901,3 +4901,38 @@ func TestBuildDotDotFile(t *testing.T) { } logDone("build - ..file") } + +func TestBuildNotVerbose(t *testing.T) { + defer deleteAllContainers() + defer deleteImages("verbose") + + ctx, err := fakeContext("FROM busybox\nENV abc=hi\nRUN echo $abc there", map[string]string{}) + if err != nil { + t.Fatal(err) + } + defer ctx.Close() + + // First do it w/verbose - baseline + buildCmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", "verbose", ".") + buildCmd.Dir = ctx.Dir + out, _, err := runCommandWithOutput(buildCmd) + if err != nil { + t.Fatalf("failed to build the image w/o -q: %s, %v", out, err) + } + if !strings.Contains(out, "hi there") { + t.Fatalf("missing output:%s\n", out) + } + + // Now do it w/o verbose + buildCmd = exec.Command(dockerBinary, "build", "--no-cache", "-q", "-t", "verbose", ".") + buildCmd.Dir = ctx.Dir + out, _, err = runCommandWithOutput(buildCmd) + if err != nil { + t.Fatalf("failed to build the image w/ -q: %s, %v", out, err) + } + if strings.Contains(out, "hi there") { + t.Fatalf("Bad output, should not contain 'hi there':%s", out) + } + + logDone("build - not verbose") +}