Browse Source

Make the commit configuration to be a typed struct rather than accepting a string.

Signed-off-by: David Calavera <david.calavera@gmail.com>
David Calavera 9 years ago
parent
commit
2ec468e284
3 changed files with 15 additions and 16 deletions
  1. 11 1
      api/client/commit.go
  2. 2 14
      api/client/lib/container_commit.go
  3. 2 1
      api/types/client.go

+ 11 - 1
api/client/commit.go

@@ -1,6 +1,7 @@
 package client
 package client
 
 
 import (
 import (
+	"encoding/json"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
 
 
@@ -10,6 +11,7 @@ import (
 	"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/registry"
 	"github.com/docker/docker/registry"
+	"github.com/docker/docker/runconfig"
 )
 )
 
 
 // CmdCommit creates a new image from a container's changes.
 // CmdCommit creates a new image from a container's changes.
@@ -56,6 +58,14 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
 		}
 		}
 	}
 	}
 
 
+	var config *runconfig.Config
+	if *flConfig != "" {
+		config = &runconfig.Config{}
+		if err := json.Unmarshal([]byte(*flConfig), config); err != nil {
+			return err
+		}
+	}
+
 	options := types.ContainerCommitOptions{
 	options := types.ContainerCommitOptions{
 		ContainerID:    name,
 		ContainerID:    name,
 		RepositoryName: repositoryName,
 		RepositoryName: repositoryName,
@@ -64,7 +74,7 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
 		Author:         *flAuthor,
 		Author:         *flAuthor,
 		Changes:        flChanges.GetAll(),
 		Changes:        flChanges.GetAll(),
 		Pause:          *flPause,
 		Pause:          *flPause,
-		JSONConfig:     *flConfig,
+		Config:         config,
 	}
 	}
 
 
 	response, err := cli.client.ContainerCommit(options)
 	response, err := cli.client.ContainerCommit(options)

+ 2 - 14
api/client/lib/container_commit.go

@@ -5,7 +5,6 @@ import (
 	"net/url"
 	"net/url"
 
 
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
-	"github.com/docker/docker/runconfig"
 )
 )
 
 
 // ContainerCommit applies changes into a container and creates a new tagged image.
 // ContainerCommit applies changes into a container and creates a new tagged image.
@@ -23,19 +22,8 @@ func (cli *Client) ContainerCommit(options types.ContainerCommitOptions) (types.
 		query.Set("pause", "0")
 		query.Set("pause", "0")
 	}
 	}
 
 
-	var (
-		config   *runconfig.Config
-		response types.ContainerCommitResponse
-	)
-
-	if options.JSONConfig != "" {
-		config = &runconfig.Config{}
-		if err := json.Unmarshal([]byte(options.JSONConfig), config); err != nil {
-			return response, err
-		}
-	}
-
-	resp, err := cli.post("/commit", query, config, nil)
+	var response types.ContainerCommitResponse
+	resp, err := cli.post("/commit", query, options.Config, nil)
 	if err != nil {
 	if err != nil {
 		return response, err
 		return response, err
 	}
 	}

+ 2 - 1
api/types/client.go

@@ -8,6 +8,7 @@ import (
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/pkg/parsers/filters"
 	"github.com/docker/docker/pkg/parsers/filters"
 	"github.com/docker/docker/pkg/ulimit"
 	"github.com/docker/docker/pkg/ulimit"
+	"github.com/docker/docker/runconfig"
 )
 )
 
 
 // ContainerAttachOptions holds parameters to attach to a container.
 // ContainerAttachOptions holds parameters to attach to a container.
@@ -28,7 +29,7 @@ type ContainerCommitOptions struct {
 	Author         string
 	Author         string
 	Changes        []string
 	Changes        []string
 	Pause          bool
 	Pause          bool
-	JSONConfig     string
+	Config         *runconfig.Config
 }
 }
 
 
 // ContainerExecInspect holds information returned by exec inspect.
 // ContainerExecInspect holds information returned by exec inspect.