Use ContainerCommitResponse struct for Commit cmd

Signed-off-by: Jamie Hannaford <jamie.hannaford@rackspace.com>
This commit is contained in:
Jamie Hannaford 2015-03-28 17:39:24 +01:00
parent 61069d8b69
commit 8b795a05a8
3 changed files with 15 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"github.com/docker/docker/engine" "github.com/docker/docker/api/types"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers"
@ -57,9 +57,10 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
} }
var ( var (
config *runconfig.Config config *runconfig.Config
env engine.Env response types.ContainerCommitResponse
) )
if *flConfig != "" { if *flConfig != "" {
config = &runconfig.Config{} config = &runconfig.Config{}
if err := json.Unmarshal([]byte(*flConfig), config); err != nil { if err := json.Unmarshal([]byte(*flConfig), config); err != nil {
@ -70,10 +71,11 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
if err != nil { if err != nil {
return err return err
} }
if err := env.Decode(stream); err != nil {
if err := json.NewDecoder(stream).Decode(&response); err != nil {
return err return err
} }
fmt.Fprintf(cli.out, "%s\n", env.Get("Id")) fmt.Fprintln(cli.out, response.ID)
return nil return nil
} }

View File

@ -507,7 +507,6 @@ func postCommit(eng *engine.Engine, version version.Version, w http.ResponseWrit
} }
var ( var (
config engine.Env config engine.Env
env engine.Env
job = eng.Job("commit", r.Form.Get("container")) job = eng.Job("commit", r.Form.Get("container"))
stdoutBuffer = bytes.NewBuffer(nil) stdoutBuffer = bytes.NewBuffer(nil)
) )
@ -537,8 +536,9 @@ func postCommit(eng *engine.Engine, version version.Version, w http.ResponseWrit
if err := job.Run(); err != nil { if err := job.Run(); err != nil {
return err return err
} }
env.Set("Id", engine.Tail(stdoutBuffer, 1)) return writeJSON(w, http.StatusCreated, &types.ContainerCommitResponse{
return writeJSONEnv(w, http.StatusCreated, env) ID: engine.Tail(stdoutBuffer, 1),
})
} }
// Creates an image from Pull or from Import // Creates an image from Pull or from Import

View File

@ -30,3 +30,8 @@ type ContainerWaitResponse struct {
// StatusCode is the status code of the wait job // StatusCode is the status code of the wait job
StatusCode int `json:"StatusCode"` StatusCode int `json:"StatusCode"`
} }
// POST "/commit?container="+containerID
type ContainerCommitResponse struct {
ID string `json:"Id"`
}