Browse code

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 <dug@us.ibm.com>

Doug Davis authored on 2015/02/21 06:26:11
Showing 2 changed files
... ...
@@ -555,8 +555,11 @@ func (b *Builder) run(c *daemon.Container) error {
555 555
 		return err
556 556
 	}
557 557
 
558
-	if err := <-errCh; err != nil {
559
-		return err
558
+	if b.Verbose {
559
+		// Block on reading output from container, stop on err or chan closed
560
+		if err := <-errCh; err != nil {
561
+			return err
562
+		}
560 563
 	}
561 564
 
562 565
 	// Wait for it to finish
... ...
@@ -4901,3 +4901,38 @@ func TestBuildDotDotFile(t *testing.T) {
4901 4901
 	}
4902 4902
 	logDone("build - ..file")
4903 4903
 }
4904
+
4905
+func TestBuildNotVerbose(t *testing.T) {
4906
+	defer deleteAllContainers()
4907
+	defer deleteImages("verbose")
4908
+
4909
+	ctx, err := fakeContext("FROM busybox\nENV abc=hi\nRUN echo $abc there", map[string]string{})
4910
+	if err != nil {
4911
+		t.Fatal(err)
4912
+	}
4913
+	defer ctx.Close()
4914
+
4915
+	// First do it w/verbose - baseline
4916
+	buildCmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", "verbose", ".")
4917
+	buildCmd.Dir = ctx.Dir
4918
+	out, _, err := runCommandWithOutput(buildCmd)
4919
+	if err != nil {
4920
+		t.Fatalf("failed to build the image w/o -q: %s, %v", out, err)
4921
+	}
4922
+	if !strings.Contains(out, "hi there") {
4923
+		t.Fatalf("missing output:%s\n", out)
4924
+	}
4925
+
4926
+	// Now do it w/o verbose
4927
+	buildCmd = exec.Command(dockerBinary, "build", "--no-cache", "-q", "-t", "verbose", ".")
4928
+	buildCmd.Dir = ctx.Dir
4929
+	out, _, err = runCommandWithOutput(buildCmd)
4930
+	if err != nil {
4931
+		t.Fatalf("failed to build the image w/ -q: %s, %v", out, err)
4932
+	}
4933
+	if strings.Contains(out, "hi there") {
4934
+		t.Fatalf("Bad output, should not contain 'hi there':%s", out)
4935
+	}
4936
+
4937
+	logDone("build - not verbose")
4938
+}