From b4ba575a2882953781616b6bb273419e829fb791 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Sat, 13 Aug 2016 14:07:53 -0700 Subject: [PATCH] Suppress verbose "Sending build context" messages in non tty scenarios This fix tries to address the issue raised in 25661 where verbose "Sending build context" messages were not suppressed in non tty (e.g. log file) sencarios. This fix suppress the "Sending build context" message (other than the last one) if the output is not a tty. The last update of the "Sending build context" message is still sent to the output. This fix has been tested manually: ``` docker build -t tmp . > build.log ``` The output is (only one "Sending build context"): ``` Sending build context to Docker daemon 249.4 MB Step 1 : FROM busybox ---> 2b8fd9751c4c Step 2 : RUN echo 'test' ---> Using cache ---> 7db298b6c493 Successfully built 7db298b6c493 ``` This fix fixes 25661. Signed-off-by: Yong Tang --- api/client/image/build.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/api/client/image/build.go b/api/client/image/build.go index 8cc0736446..e3d3f034fc 100644 --- a/api/client/image/build.go +++ b/api/client/image/build.go @@ -104,6 +104,22 @@ func NewBuildCommand(dockerCli *client.DockerCli) *cobra.Command { return cmd } +// lastProgressOutput is the same as progress.Output except +// that it only output with the last update. It is used in +// non terminal scenarios to depresss verbose messages +type lastProgressOutput struct { + output progress.Output +} + +// WriteProgress formats progress information from a ProgressReader. +func (out *lastProgressOutput) WriteProgress(prog progress.Progress) error { + if !prog.LastUpdate { + return nil + } + + return out.output.WriteProgress(prog) +} + func runBuild(dockerCli *client.DockerCli, options buildOptions) error { var ( @@ -211,6 +227,9 @@ func runBuild(dockerCli *client.DockerCli, options buildOptions) error { // Setup an upload progress bar progressOutput := streamformatter.NewStreamFormatter().NewProgressOutput(progBuff, true) + if !dockerCli.IsTerminalOut() { + progressOutput = &lastProgressOutput{output: progressOutput} + } var body io.Reader = progress.NewProgressReader(buildCtx, progressOutput, 0, "", "Sending build context to Docker daemon")