Browse code

Use ContainerCommitResponse struct for Commit cmd

Signed-off-by: Jamie Hannaford <jamie.hannaford@rackspace.com>

Jamie Hannaford authored on 2015/03/29 01:39:24
Showing 3 changed files
... ...
@@ -5,7 +5,7 @@ import (
5 5
 	"fmt"
6 6
 	"net/url"
7 7
 
8
-	"github.com/docker/docker/engine"
8
+	"github.com/docker/docker/api/types"
9 9
 	"github.com/docker/docker/opts"
10 10
 	flag "github.com/docker/docker/pkg/mflag"
11 11
 	"github.com/docker/docker/pkg/parsers"
... ...
@@ -57,9 +57,10 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
57 57
 	}
58 58
 
59 59
 	var (
60
-		config *runconfig.Config
61
-		env    engine.Env
60
+		config   *runconfig.Config
61
+		response types.ContainerCommitResponse
62 62
 	)
63
+
63 64
 	if *flConfig != "" {
64 65
 		config = &runconfig.Config{}
65 66
 		if err := json.Unmarshal([]byte(*flConfig), config); err != nil {
... ...
@@ -70,10 +71,11 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
70 70
 	if err != nil {
71 71
 		return err
72 72
 	}
73
-	if err := env.Decode(stream); err != nil {
73
+
74
+	if err := json.NewDecoder(stream).Decode(&response); err != nil {
74 75
 		return err
75 76
 	}
76 77
 
77
-	fmt.Fprintf(cli.out, "%s\n", env.Get("Id"))
78
+	fmt.Fprintln(cli.out, response.ID)
78 79
 	return nil
79 80
 }
... ...
@@ -507,7 +507,6 @@ func postCommit(eng *engine.Engine, version version.Version, w http.ResponseWrit
507 507
 	}
508 508
 	var (
509 509
 		config       engine.Env
510
-		env          engine.Env
511 510
 		job          = eng.Job("commit", r.Form.Get("container"))
512 511
 		stdoutBuffer = bytes.NewBuffer(nil)
513 512
 	)
... ...
@@ -537,8 +536,9 @@ func postCommit(eng *engine.Engine, version version.Version, w http.ResponseWrit
537 537
 	if err := job.Run(); err != nil {
538 538
 		return err
539 539
 	}
540
-	env.Set("Id", engine.Tail(stdoutBuffer, 1))
541
-	return writeJSONEnv(w, http.StatusCreated, env)
540
+	return writeJSON(w, http.StatusCreated, &types.ContainerCommitResponse{
541
+		ID: engine.Tail(stdoutBuffer, 1),
542
+	})
542 543
 }
543 544
 
544 545
 // Creates an image from Pull or from Import
... ...
@@ -30,3 +30,8 @@ type ContainerWaitResponse struct {
30 30
 	// StatusCode is the status code of the wait job
31 31
 	StatusCode int `json:"StatusCode"`
32 32
 }
33
+
34
+// POST "/commit?container="+containerID
35
+type ContainerCommitResponse struct {
36
+	ID string `json:"Id"`
37
+}