Skip to content

Commit

Permalink
Move Config and HostConfig from runconfig to types/container.
Browse files Browse the repository at this point in the history
- Make the API client library completely standalone.
- Move windows partition isolation detection to the client, so the
  driver doesn't use external types.

Signed-off-by: David Calavera <[email protected]>
  • Loading branch information
calavera committed Dec 22, 2015
1 parent 747dccd commit 7ac4232
Show file tree
Hide file tree
Showing 65 changed files with 732 additions and 686 deletions.
4 changes: 2 additions & 2 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (

"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/runconfig"
)

// apiClient is an interface that clients that talk with a docker server must implement.
type apiClient interface {
ClientVersion() string
ContainerAttach(options types.ContainerAttachOptions) (types.HijackedResponse, error)
ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
ContainerCreate(config *runconfig.ContainerConfigWrapper, containerName string) (types.ContainerCreateResponse, error)
ContainerCreate(config *container.Config, hostConfig *container.HostConfig, containerName string) (types.ContainerCreateResponse, error)
ContainerDiff(containerID string) ([]types.ContainerChange, error)
ContainerExecAttach(execID string, config types.ExecConfig) (types.HijackedResponse, error)
ContainerExecCreate(config types.ExecConfig) (types.ContainerExecCreateResponse, error)
Expand Down
6 changes: 3 additions & 3 deletions api/client/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"fmt"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/opts"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/reference"
"github.com/docker/docker/runconfig"
)

// CmdCommit creates a new image from a container's changes.
Expand Down Expand Up @@ -54,9 +54,9 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
}
}

var config *runconfig.Config
var config *container.Config
if *flConfig != "" {
config = &runconfig.Config{}
config = &container.Config{}
if err := json.Unmarshal([]byte(*flConfig), config); err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions api/client/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/reference"
Expand Down Expand Up @@ -78,9 +79,7 @@ func newCIDFile(path string) (*cidFile, error) {
return &cidFile{path: path, file: f}, nil
}

func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runconfig.HostConfig, cidfile, name string) (*types.ContainerCreateResponse, error) {
mergedConfig := runconfig.MergeConfigs(config, hostConfig)

func (cli *DockerCli) createContainer(config *container.Config, hostConfig *container.HostConfig, cidfile, name string) (*types.ContainerCreateResponse, error) {
var containerIDFile *cidFile
if cidfile != "" {
var err error
Expand Down Expand Up @@ -108,7 +107,7 @@ func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runc
}

//create the container
response, err := cli.client.ContainerCreate(mergedConfig, name)
response, err := cli.client.ContainerCreate(config, hostConfig, name)
//if image not found try to pull it
if err != nil {
if lib.IsErrImageNotFound(err) {
Expand All @@ -125,7 +124,7 @@ func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runc
}
// Retry
var retryErr error
response, retryErr = cli.client.ContainerCreate(mergedConfig, name)
response, retryErr = cli.client.ContainerCreate(config, hostConfig, name)
if retryErr != nil {
return nil, retryErr
}
Expand Down
16 changes: 13 additions & 3 deletions api/client/lib/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@ import (
"strings"

"github.com/docker/docker/api/types"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/api/types/container"
)

type configWrapper struct {
*container.Config
HostConfig *container.HostConfig
}

// ContainerCreate creates a new container based in the given configuration.
// It can be associated with a name, but it's not mandatory.
func (cli *Client) ContainerCreate(config *runconfig.ContainerConfigWrapper, containerName string) (types.ContainerCreateResponse, error) {
func (cli *Client) ContainerCreate(config *container.Config, hostConfig *container.HostConfig, containerName string) (types.ContainerCreateResponse, error) {
var response types.ContainerCreateResponse
query := url.Values{}
if containerName != "" {
query.Set("name", containerName)
}

serverResp, err := cli.post("/containers/create", query, config, nil)
body := configWrapper{
Config: config,
HostConfig: hostConfig,
}

serverResp, err := cli.post("/containers/create", query, body, nil)
if err != nil {
if serverResp != nil && serverResp.statusCode == 404 && strings.Contains(err.Error(), config.Image) {
return response, imageNotFoundError{config.Image}
Expand Down
4 changes: 2 additions & 2 deletions api/client/lib/image_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

"github.com/docker/docker/api/types"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-units"
)

Expand Down Expand Up @@ -73,7 +73,7 @@ func imageBuildOptionsToQuery(options types.ImageBuildOptions) (url.Values, erro
query.Set("pull", "1")
}

if !runconfig.IsolationLevel.IsDefault(runconfig.IsolationLevel(options.Isolation)) {
if !container.IsolationLevel.IsDefault(container.IsolationLevel(options.Isolation)) {
query.Set("isolation", options.Isolation)
}

Expand Down
6 changes: 3 additions & 3 deletions api/server/router/build/build_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/builder"
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/daemon/daemonbuilder"
Expand All @@ -24,7 +25,6 @@ import (
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/docker/pkg/ulimit"
"github.com/docker/docker/reference"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/utils"
"golang.org/x/net/context"
)
Expand Down Expand Up @@ -144,8 +144,8 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *
buildConfig.ShmSize = &shmSize
}

if i := runconfig.IsolationLevel(r.FormValue("isolation")); i != "" {
if !runconfig.IsolationLevel.IsValid(i) {
if i := container.IsolationLevel(r.FormValue("isolation")); i != "" {
if !container.IsolationLevel.IsValid(i) {
return errf(fmt.Errorf("Unsupported isolation: %q", i))
}
buildConfig.Isolation = i
Expand Down
4 changes: 2 additions & 2 deletions api/server/router/container/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/daemon"
"github.com/docker/docker/daemon/exec"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/version"
"github.com/docker/docker/runconfig"
)

// execBackend includes functions to implement to provide exec functionality.
Expand Down Expand Up @@ -39,7 +39,7 @@ type stateBackend interface {
ContainerResize(name string, height, width int) error
ContainerRestart(name string, seconds int) error
ContainerRm(name string, config *types.ContainerRmConfig) error
ContainerStart(name string, hostConfig *runconfig.HostConfig) error
ContainerStart(name string, hostConfig *container.HostConfig) error
ContainerStop(name string, seconds int) error
ContainerUnpause(name string) error
ContainerWait(name string, timeout time.Duration) (int, error)
Expand Down
3 changes: 2 additions & 1 deletion api/server/router/container/container_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/docker/distribution/registry/api/errcode"
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
timetypes "github.com/docker/docker/api/types/time"
"github.com/docker/docker/daemon"
derr "github.com/docker/docker/errors"
Expand Down Expand Up @@ -162,7 +163,7 @@ func (s *containerRouter) postContainersStart(ctx context.Context, w http.Respon
// net/http otherwise seems to swallow any headers related to chunked encoding
// including r.TransferEncoding
// allow a nil body for backwards compatibility
var hostConfig *runconfig.HostConfig
var hostConfig *container.HostConfig
if r.Body != nil && (r.ContentLength > 0 || r.ContentLength == -1) {
if err := httputils.CheckForJSON(r); err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions api/server/router/local/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/docker/distribution/digest"
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/builder/dockerfile"
derr "github.com/docker/docker/errors"
"github.com/docker/docker/pkg/ioutils"
Expand Down Expand Up @@ -43,7 +44,7 @@ func (s *router) postCommit(ctx context.Context, w http.ResponseWriter, r *http.
return err
}
if c == nil {
c = &runconfig.Config{}
c = &container.Config{}
}

if !s.daemon.Exists(cname) {
Expand Down Expand Up @@ -162,8 +163,8 @@ func (s *router) postImagesCreate(ctx context.Context, w http.ResponseWriter, r
// 'err' MUST NOT be defined within this block, we need any error
// generated from the download to be available to the output
// stream processing below
var newConfig *runconfig.Config
newConfig, err = dockerfile.BuildFromConfig(&runconfig.Config{}, r.Form["changes"])
var newConfig *container.Config
newConfig, err = dockerfile.BuildFromConfig(&container.Config{}, r.Form["changes"])
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions api/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"io"
"net"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/pkg/ulimit"
"github.com/docker/docker/runconfig"
)

// ContainerAttachOptions holds parameters to attach to a container.
Expand All @@ -28,7 +28,7 @@ type ContainerCommitOptions struct {
Author string
Changes []string
Pause bool
Config *runconfig.Config
Config *container.Config
}

// ContainerExecInspect holds information returned by exec inspect.
Expand Down
12 changes: 5 additions & 7 deletions api/types/configs.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package types

import "github.com/docker/docker/api/types/container"

// configs holds structs used for internal communication between the
// frontend (such as an http server) and the backend (such as the
// docker daemon).

import (
"github.com/docker/docker/runconfig"
)

// ContainerCreateConfig is the parameter set to ContainerCreate()
type ContainerCreateConfig struct {
Name string
Config *runconfig.Config
HostConfig *runconfig.HostConfig
Config *container.Config
HostConfig *container.HostConfig
AdjustCPUShares bool
}

Expand All @@ -33,7 +31,7 @@ type ContainerCommitConfig struct {
Comment string
// merge container config into commit config before commit
MergeConfigs bool
Config *runconfig.Config
Config *container.Config
}

// ExecConfig is a small subset of the Config struct that hold the configuration
Expand Down
38 changes: 38 additions & 0 deletions api/types/container/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package container

import (
"github.com/docker/docker/api/types/strslice"
"github.com/docker/go-connections/nat"
)

// Config contains the configuration data about a container.
// It should hold only portable information about the container.
// Here, "portable" means "independent from the host we are running on".
// Non-portable information *should* appear in HostConfig.
// All fields added to this struct must be marked `omitempty` to keep getting
// predictable hashes from the old `v1Compatibility` configuration.
type Config struct {
Hostname string // Hostname
Domainname string // Domainname
User string // User that will run the command(s) inside the container
AttachStdin bool // Attach the standard input, makes possible user interaction
AttachStdout bool // Attach the standard output
AttachStderr bool // Attach the standard error
ExposedPorts map[nat.Port]struct{} `json:",omitempty"` // List of exposed ports
PublishService string `json:",omitempty"` // Name of the network service exposed by the container
Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
OpenStdin bool // Open stdin
StdinOnce bool // If true, close stdin after the 1 attached client disconnects.
Env []string // List of environment variable to set in the container
Cmd *strslice.StrSlice // Command to run when starting the container
ArgsEscaped bool `json:",omitempty"` // True if command is already escaped (Windows specific)
Image string // Name of the image as it was passed by the operator (eg. could be symbolic)
Volumes map[string]struct{} // List of volumes (mounts) used for the container
WorkingDir string // Current directory (PWD) in the command will be launched
Entrypoint *strslice.StrSlice // Entrypoint to run when starting the container
NetworkDisabled bool `json:",omitempty"` // Is network disabled
MacAddress string `json:",omitempty"` // Mac Address of the container
OnBuild []string // ONBUILD metadata that were defined on the image Dockerfile
Labels map[string]string // List of labels set to this container
StopSignal string `json:",omitempty"` // Signal to stop a container
}
Loading

0 comments on commit 7ac4232

Please sign in to comment.