From 56431d3130f8a48cfb708509cbe39682f7fe841c Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 30 May 2013 12:08:21 -0700 Subject: [PATCH] Add -t to docker build in order to tag resulting image --- api.go | 11 ++++++++++- commands.go | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index 3c440d7331..621d9c82e1 100644 --- a/api.go +++ b/api.go @@ -650,6 +650,13 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ if err := r.ParseMultipartForm(4096); err != nil { return err } + remote := r.FormValue("t") + tag := "" + if strings.Contains(remote, ":") { + remoteParts := strings.Split(remote, ":") + tag = remoteParts[1] + remote = remoteParts[0] + } dockerfile, _, err := r.FormFile("Dockerfile") if err != nil { @@ -664,8 +671,10 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ } b := NewBuildFile(srv, utils.NewWriteFlusher(w)) - if _, err := b.Build(dockerfile, context); err != nil { + if id, err := b.Build(dockerfile, context); err != nil { fmt.Fprintf(w, "Error build: %s\n", err) + } else if remote != "" { + srv.runtime.repositories.Set(remote, tag, id, false) } return nil } diff --git a/commands.go b/commands.go index 67b8e917f5..c24a48f5a0 100644 --- a/commands.go +++ b/commands.go @@ -132,6 +132,7 @@ func (cli *DockerCli) CmdInsert(args ...string) error { func (cli *DockerCli) CmdBuild(args ...string) error { cmd := Subcmd("build", "PATH | -", "Build a new container image from the source code at PATH") + tag := cmd.String("t", "", "Tag to be applied to the resulting image") if err := cmd.Parse(args); err != nil { return nil } @@ -191,8 +192,10 @@ func (cli *DockerCli) CmdBuild(args ...string) error { } multipartBody = io.MultiReader(multipartBody, boundary) + v := &url.Values{} + v.Set("t", *tag) // Send the multipart request with correct content-type - req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s", cli.host, cli.port, "/build"), multipartBody) + req, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%d%s?%s", cli.host, cli.port, "/build", v.Encode()), multipartBody) if err != nil { return err }