Browse code

Add verbose output to docker build

Verbose output is enabled by default and
the flag -q can be used to suppress the verbose output.

Michael Crosby authored on 2013/07/12 09:12:25
Showing 5 changed files
... ...
@@ -756,6 +756,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
756 756
 	}
757 757
 	remoteURL := r.FormValue("remote")
758 758
 	repoName := r.FormValue("t")
759
+	rawSuppressOutput := r.FormValue("q")
759 760
 	tag := ""
760 761
 	if strings.Contains(repoName, ":") {
761 762
 		remoteParts := strings.Split(repoName, ":")
... ...
@@ -802,7 +803,13 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
802 802
 		}
803 803
 		context = c
804 804
 	}
805
-	b := NewBuildFile(srv, utils.NewWriteFlusher(w))
805
+
806
+	suppressOutput, err := getBoolParam(rawSuppressOutput)
807
+	if err != nil {
808
+		return err
809
+	}
810
+
811
+	b := NewBuildFile(srv, utils.NewWriteFlusher(w), !suppressOutput)
806 812
 	id, err := b.Build(context)
807 813
 	if err != nil {
808 814
 		fmt.Fprintf(w, "Error build: %s\n", err)
... ...
@@ -28,6 +28,7 @@ type buildFile struct {
28 28
 	maintainer string
29 29
 	config     *Config
30 30
 	context    string
31
+	verbose    bool
31 32
 
32 33
 	lastContainer *Container
33 34
 	tmpContainers map[string]struct{}
... ...
@@ -303,6 +304,13 @@ func (b *buildFile) run() (string, error) {
303 303
 		return "", err
304 304
 	}
305 305
 
306
+	if b.verbose {
307
+		err = <-c.Attach(nil, nil, b.out, b.out)
308
+		if err != nil {
309
+			return "", err
310
+		}
311
+	}
312
+
306 313
 	// Wait for it to finish
307 314
 	if ret := c.Wait(); ret != 0 {
308 315
 		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) {
450 450
 	return "", fmt.Errorf("An error occured during the build\n")
451 451
 }
452 452
 
453
-func NewBuildFile(srv *Server, out io.Writer) BuildFile {
453
+func NewBuildFile(srv *Server, out io.Writer, verbose bool) BuildFile {
454 454
 	return &buildFile{
455 455
 		builder:       NewBuilder(srv.runtime),
456 456
 		runtime:       srv.runtime,
... ...
@@ -459,5 +467,6 @@ func NewBuildFile(srv *Server, out io.Writer) BuildFile {
459 459
 		out:           out,
460 460
 		tmpContainers: make(map[string]struct{}),
461 461
 		tmpImages:     make(map[string]struct{}),
462
+		verbose:       verbose,
462 463
 	}
463 464
 }
... ...
@@ -117,7 +117,7 @@ func TestBuild(t *testing.T) {
117 117
 			pushingPool: make(map[string]struct{}),
118 118
 		}
119 119
 
120
-		buildfile := NewBuildFile(srv, ioutil.Discard)
120
+		buildfile := NewBuildFile(srv, ioutil.Discard, false)
121 121
 		if _, err := buildfile.Build(mkTestContext(ctx.dockerfile, ctx.files, t)); err != nil {
122 122
 			t.Fatal(err)
123 123
 		}
... ...
@@ -157,6 +157,8 @@ func mkBuildContext(dockerfile string, files [][2]string) (Archive, error) {
157 157
 func (cli *DockerCli) CmdBuild(args ...string) error {
158 158
 	cmd := Subcmd("build", "[OPTIONS] PATH | URL | -", "Build a new container image from the source code at PATH")
159 159
 	tag := cmd.String("t", "", "Tag to be applied to the resulting image in case of success")
160
+	suppressOutput := cmd.Bool("q", false, "Suppress verbose build output")
161
+
160 162
 	if err := cmd.Parse(args); err != nil {
161 163
 		return nil
162 164
 	}
... ...
@@ -194,6 +196,10 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
194 194
 	// Upload the build context
195 195
 	v := &url.Values{}
196 196
 	v.Set("t", *tag)
197
+
198
+	if *suppressOutput {
199
+		v.Set("q", "1")
200
+	}
197 201
 	if isRemote {
198 202
 		v.Set("remote", cmd.Arg(0))
199 203
 	}
... ...
@@ -11,6 +11,7 @@
11 11
     Usage: docker build [OPTIONS] PATH | URL | -
12 12
     Build a new container image from the source code at PATH
13 13
       -t="": Tag to be applied to the resulting image in case of success.
14
+      -q=false: Suppress verbose build output.
14 15
     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
15 16
 
16 17