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>
This commit is contained in:
Doug Davis 2015-02-20 13:26:11 -08:00
parent f2d2862459
commit 92c353582c
2 changed files with 40 additions and 2 deletions

View File

@ -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

View File

@ -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")
}