From 015f243412c98b55fd6a1b742b814bddc7effe92 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 11 Jul 2013 15:12:25 -0900 Subject: [PATCH 1/4] Add verbose output to docker build Verbose output is enabled by default and the flag -q can be used to suppress the verbose output. Upstream-commit: 474191dd7bca9eedaccb9de1771eecfce7dfebbb Component: engine --- components/engine/api.go | 9 ++++++++- components/engine/buildfile.go | 11 ++++++++++- components/engine/buildfile_test.go | 2 +- components/engine/commands.go | 6 ++++++ .../engine/docs/sources/commandline/command/build.rst | 1 + 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/components/engine/api.go b/components/engine/api.go index c4a5222dc6..9e51f4de77 100644 --- a/components/engine/api.go +++ b/components/engine/api.go @@ -756,6 +756,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ } remoteURL := r.FormValue("remote") repoName := r.FormValue("t") + rawSuppressOutput := r.FormValue("q") tag := "" if strings.Contains(repoName, ":") { remoteParts := strings.Split(repoName, ":") @@ -802,7 +803,13 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ } context = c } - b := NewBuildFile(srv, utils.NewWriteFlusher(w)) + + suppressOutput, err := getBoolParam(rawSuppressOutput) + if err != nil { + return err + } + + b := NewBuildFile(srv, utils.NewWriteFlusher(w), !suppressOutput) id, err := b.Build(context) if err != nil { fmt.Fprintf(w, "Error build: %s\n", err) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 38e6c330d6..02ef00a854 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -28,6 +28,7 @@ type buildFile struct { maintainer string config *Config context string + verbose bool lastContainer *Container tmpContainers map[string]struct{} @@ -303,6 +304,13 @@ func (b *buildFile) run() (string, error) { return "", err } + if b.verbose { + err = <-c.Attach(nil, nil, b.out, b.out) + if err != nil { + return "", err + } + } + // Wait for it to finish if ret := c.Wait(); ret != 0 { return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, ret) @@ -450,7 +458,7 @@ func (b *buildFile) Build(context io.Reader) (string, error) { return "", fmt.Errorf("An error occured during the build\n") } -func NewBuildFile(srv *Server, out io.Writer) BuildFile { +func NewBuildFile(srv *Server, out io.Writer, verbose bool) BuildFile { return &buildFile{ builder: NewBuilder(srv.runtime), runtime: srv.runtime, @@ -459,5 +467,6 @@ func NewBuildFile(srv *Server, out io.Writer) BuildFile { out: out, tmpContainers: make(map[string]struct{}), tmpImages: make(map[string]struct{}), + verbose: verbose, } } diff --git a/components/engine/buildfile_test.go b/components/engine/buildfile_test.go index 9250f73765..0bd5a3d1c4 100644 --- a/components/engine/buildfile_test.go +++ b/components/engine/buildfile_test.go @@ -117,7 +117,7 @@ func TestBuild(t *testing.T) { pushingPool: make(map[string]struct{}), } - buildfile := NewBuildFile(srv, ioutil.Discard) + buildfile := NewBuildFile(srv, ioutil.Discard, false) if _, err := buildfile.Build(mkTestContext(ctx.dockerfile, ctx.files, t)); err != nil { t.Fatal(err) } diff --git a/components/engine/commands.go b/components/engine/commands.go index feab558259..4a69fb9108 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -157,6 +157,8 @@ func mkBuildContext(dockerfile string, files [][2]string) (Archive, error) { func (cli *DockerCli) CmdBuild(args ...string) error { cmd := Subcmd("build", "[OPTIONS] PATH | URL | -", "Build a new container image from the source code at PATH") tag := cmd.String("t", "", "Tag to be applied to the resulting image in case of success") + suppressOutput := cmd.Bool("q", false, "Suppress verbose build output") + if err := cmd.Parse(args); err != nil { return nil } @@ -194,6 +196,10 @@ func (cli *DockerCli) CmdBuild(args ...string) error { // Upload the build context v := &url.Values{} v.Set("t", *tag) + + if *suppressOutput { + v.Set("q", "1") + } if isRemote { v.Set("remote", cmd.Arg(0)) } diff --git a/components/engine/docs/sources/commandline/command/build.rst b/components/engine/docs/sources/commandline/command/build.rst index 1645002ba2..45b6d2ec8e 100644 --- a/components/engine/docs/sources/commandline/command/build.rst +++ b/components/engine/docs/sources/commandline/command/build.rst @@ -11,6 +11,7 @@ Usage: docker build [OPTIONS] PATH | URL | - Build a new container image from the source code at PATH -t="": Tag to be applied to the resulting image in case of success. + -q=false: Suppress verbose build output. When a single Dockerfile is given as URL, then no context is set. When a git repository is set as URL, the repository is used as context From 7bf5a45cfe77c9237723e1a4fccaff0a4e461fc4 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 11 Jul 2013 15:37:26 -0900 Subject: [PATCH 2/4] Fix buildfile tests after rebase Upstream-commit: 49044a96089487b9df075fa972e83e4c05c7fae8 Component: engine --- components/engine/buildfile_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/engine/buildfile_test.go b/components/engine/buildfile_test.go index 0bd5a3d1c4..514d2f89dc 100644 --- a/components/engine/buildfile_test.go +++ b/components/engine/buildfile_test.go @@ -137,7 +137,7 @@ func TestVolume(t *testing.T) { pushingPool: make(map[string]struct{}), } - buildfile := NewBuildFile(srv, ioutil.Discard) + buildfile := NewBuildFile(srv, ioutil.Discard, false) imgId, err := buildfile.Build(mkTestContext(` from %s VOLUME /test @@ -153,7 +153,7 @@ CMD Hello world if len(img.Config.Volumes) == 0 { t.Fail() } - for key, _ := range img.Config.Volumes { + for key := range img.Config.Volumes { if key != "/test" { t.Fail() } From 89646a08c959d6720c4d7e6f92490179f5fe464d Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 11 Jul 2013 15:52:08 -0900 Subject: [PATCH 3/4] Revert changes from PR 1030 With streaming output of the build changes in 1030 are no longer required. Upstream-commit: 1104d443cc49fd2a6b9c94a2c9724468f9860799 Component: engine --- components/engine/buildfile.go | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/components/engine/buildfile.go b/components/engine/buildfile.go index 02ef00a854..7ade058c69 100644 --- a/components/engine/buildfile.go +++ b/components/engine/buildfile.go @@ -30,7 +30,6 @@ type buildFile struct { context string verbose bool - lastContainer *Container tmpContainers map[string]struct{} tmpImages map[string]struct{} @@ -255,7 +254,6 @@ func (b *buildFile) CmdAdd(args string) error { return err } b.tmpContainers[container.ID] = struct{}{} - b.lastContainer = container if err := container.EnsureMounted(); err != nil { return err @@ -291,7 +289,6 @@ func (b *buildFile) run() (string, error) { return "", err } b.tmpContainers[c.ID] = struct{}{} - b.lastContainer = c fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(c.ID)) // override the entry point that may have been picked up from the base image @@ -345,7 +342,6 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error { return err } b.tmpContainers[container.ID] = struct{}{} - b.lastContainer = container fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(container.ID)) id = container.ID if err := container.EnsureMounted(); err != nil { @@ -373,29 +369,6 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error { } func (b *buildFile) Build(context io.Reader) (string, error) { - defer func() { - // If we have an error and a container, the display the logs - if b.lastContainer != nil { - fmt.Fprintf(b.out, "******** Logs from last container (%s) *******\n", b.lastContainer.ShortID()) - - cLog, err := b.lastContainer.ReadLog("stdout") - if err != nil { - utils.Debugf("Error reading logs (stdout): %s", err) - } - if _, err := io.Copy(b.out, cLog); err != nil { - utils.Debugf("Error streaming logs (stdout): %s", err) - } - cLog, err = b.lastContainer.ReadLog("stderr") - if err != nil { - utils.Debugf("Error reading logs (stderr): %s", err) - } - if _, err := io.Copy(b.out, cLog); err != nil { - utils.Debugf("Error streaming logs (stderr): %s", err) - } - fmt.Fprintf(b.out, "************* End of logs for %s *************\n", b.lastContainer.ShortID()) - } - }() - // FIXME: @creack any reason for using /tmp instead of ""? // FIXME: @creack "name" is a terrible variable name name, err := ioutil.TempDir("/tmp", "docker-build") @@ -448,7 +421,6 @@ func (b *buildFile) Build(context io.Reader) (string, error) { return "", ret.(error) } - b.lastContainer = nil fmt.Fprintf(b.out, " ---> %v\n", utils.TruncateID(b.image)) } if b.image != "" { From 3442b5e984e38f6d8005ccfb7706ffb264490c67 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 12 Jul 2013 06:22:56 -0900 Subject: [PATCH 4/4] Add param to api docs for verbose build output Upstream-commit: d0c73c28df5627bc7158fd54860f6751b4dab0f9 Component: engine --- components/engine/docs/sources/api/docker_remote_api_v1.3.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/components/engine/docs/sources/api/docker_remote_api_v1.3.rst b/components/engine/docs/sources/api/docker_remote_api_v1.3.rst index b0955ce496..7f7c7db8a8 100644 --- a/components/engine/docs/sources/api/docker_remote_api_v1.3.rst +++ b/components/engine/docs/sources/api/docker_remote_api_v1.3.rst @@ -881,6 +881,7 @@ Build an image from Dockerfile via stdin The Content-type header should be set to "application/tar". :query t: tag to be applied to the resulting image in case of success + :query q: suppress verbose build output :statuscode 200: no error :statuscode 500: server error