Add -t to docker build in order to tag resulting image
This commit is contained in:
parent
97247c5c73
commit
56431d3130
2 changed files with 14 additions and 2 deletions
11
api.go
11
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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue