1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add verbose output to docker build

Verbose output is enabled by default and
the flag -q can be used to suppress the verbose output.
This commit is contained in:
Michael Crosby 2013-07-11 15:12:25 -09:00
parent 637eceb6a7
commit 474191dd7b
5 changed files with 26 additions and 3 deletions

9
api.go
View file

@ -756,6 +756,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
} }
remoteURL := r.FormValue("remote") remoteURL := r.FormValue("remote")
repoName := r.FormValue("t") repoName := r.FormValue("t")
rawSuppressOutput := r.FormValue("q")
tag := "" tag := ""
if strings.Contains(repoName, ":") { if strings.Contains(repoName, ":") {
remoteParts := strings.Split(repoName, ":") remoteParts := strings.Split(repoName, ":")
@ -802,7 +803,13 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
} }
context = c 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) id, err := b.Build(context)
if err != nil { if err != nil {
fmt.Fprintf(w, "Error build: %s\n", err) fmt.Fprintf(w, "Error build: %s\n", err)

View file

@ -28,6 +28,7 @@ type buildFile struct {
maintainer string maintainer string
config *Config config *Config
context string context string
verbose bool
lastContainer *Container lastContainer *Container
tmpContainers map[string]struct{} tmpContainers map[string]struct{}
@ -303,6 +304,13 @@ func (b *buildFile) run() (string, error) {
return "", err return "", err
} }
if b.verbose {
err = <-c.Attach(nil, nil, b.out, b.out)
if err != nil {
return "", err
}
}
// Wait for it to finish // Wait for it to finish
if ret := c.Wait(); ret != 0 { if ret := c.Wait(); ret != 0 {
return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, ret) 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") 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{ return &buildFile{
builder: NewBuilder(srv.runtime), builder: NewBuilder(srv.runtime),
runtime: srv.runtime, runtime: srv.runtime,
@ -459,5 +467,6 @@ func NewBuildFile(srv *Server, out io.Writer) BuildFile {
out: out, out: out,
tmpContainers: make(map[string]struct{}), tmpContainers: make(map[string]struct{}),
tmpImages: make(map[string]struct{}), tmpImages: make(map[string]struct{}),
verbose: verbose,
} }
} }

View file

@ -117,7 +117,7 @@ func TestBuild(t *testing.T) {
pushingPool: make(map[string]struct{}), 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 { if _, err := buildfile.Build(mkTestContext(ctx.dockerfile, ctx.files, t)); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -157,6 +157,8 @@ func mkBuildContext(dockerfile string, files [][2]string) (Archive, error) {
func (cli *DockerCli) CmdBuild(args ...string) 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") 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") 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 { if err := cmd.Parse(args); err != nil {
return nil return nil
} }
@ -194,6 +196,10 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
// Upload the build context // Upload the build context
v := &url.Values{} v := &url.Values{}
v.Set("t", *tag) v.Set("t", *tag)
if *suppressOutput {
v.Set("q", "1")
}
if isRemote { if isRemote {
v.Set("remote", cmd.Arg(0)) v.Set("remote", cmd.Arg(0))
} }

View file

@ -11,6 +11,7 @@
Usage: docker build [OPTIONS] PATH | URL | - Usage: docker build [OPTIONS] PATH | URL | -
Build a new container image from the source code at PATH Build a new container image from the source code at PATH
-t="": Tag to be applied to the resulting image in case of success. -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 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