From 03a170c48d660be72c387f1821ca48a713dd1cea Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Wed, 16 Dec 2015 17:56:49 +0100 Subject: [PATCH] builder: remove daemon dependency in ContainerCreate() Signed-off-by: Tibor Vass --- api/server/router/container/backend.go | 2 +- .../router/container/container_routes.go | 2 +- api/types/configs.go | 8 +++++++ builder/builder.go | 3 +-- builder/dockerfile/internals.go | 5 ++--- daemon/create.go | 21 +++++++------------ 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/api/server/router/container/backend.go b/api/server/router/container/backend.go index 33bf3c5b7a..0f2f06bfcc 100644 --- a/api/server/router/container/backend.go +++ b/api/server/router/container/backend.go @@ -32,7 +32,7 @@ type copyBackend interface { // stateBackend includes functions to implement to provide container state lifecycle functionality. type stateBackend interface { - ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error) + ContainerCreate(types.ContainerCreateConfig) (types.ContainerCreateResponse, error) ContainerKill(name string, sig uint64) error ContainerPause(name string) error ContainerRename(oldName, newName string) error diff --git a/api/server/router/container/container_routes.go b/api/server/router/container/container_routes.go index dd300a498f..b300a56b89 100644 --- a/api/server/router/container/container_routes.go +++ b/api/server/router/container/container_routes.go @@ -339,7 +339,7 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo version := httputils.VersionFromContext(ctx) adjustCPUShares := version.LessThan("1.19") - ccr, err := s.backend.ContainerCreate(&daemon.ContainerCreateConfig{ + ccr, err := s.backend.ContainerCreate(types.ContainerCreateConfig{ Name: name, Config: config, HostConfig: hostConfig, diff --git a/api/types/configs.go b/api/types/configs.go index 2551a0b3b4..c166ac7e51 100644 --- a/api/types/configs.go +++ b/api/types/configs.go @@ -8,6 +8,14 @@ import ( "github.com/docker/docker/runconfig" ) +// ContainerCreateConfig is the parameter set to ContainerCreate() +type ContainerCreateConfig struct { + Name string + Config *runconfig.Config + HostConfig *runconfig.HostConfig + AdjustCPUShares bool +} + // ContainerRmConfig holds arguments for the container remove // operation. This struct is used to tell the backend what operations // to perform. diff --git a/builder/builder.go b/builder/builder.go index 06b151911a..03090dabc3 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -10,7 +10,6 @@ import ( "time" "github.com/docker/docker/api/types" - "github.com/docker/docker/daemon" "github.com/docker/docker/runconfig" ) @@ -117,7 +116,7 @@ type Backend interface { // ContainerWsAttachWithLogs attaches to container. ContainerWsAttachWithLogs(name string, cfg *daemon.ContainerWsAttachWithLogsConfig) error // ContainerCreate creates a new Docker container and returns potential warnings - ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error) + ContainerCreate(types.ContainerCreateConfig) (types.ContainerCreateResponse, error) // ContainerRm removes a container specified by `id`. ContainerRm(name string, config *types.ContainerRmConfig) error // Commit creates a new Docker image from an existing Docker container. diff --git a/builder/dockerfile/internals.go b/builder/dockerfile/internals.go index 1f82879244..daa1f2903f 100644 --- a/builder/dockerfile/internals.go +++ b/builder/dockerfile/internals.go @@ -23,7 +23,6 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/builder" "github.com/docker/docker/builder/dockerfile/parser" - "github.com/docker/docker/daemon" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/httputils" "github.com/docker/docker/pkg/ioutils" @@ -188,7 +187,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD return nil } - container, err := b.docker.ContainerCreate(&daemon.ContainerCreateConfig{Config: b.runConfig}) + container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig}) if err != nil { return err } @@ -507,7 +506,7 @@ func (b *Builder) create() (string, error) { config := *b.runConfig // Create the container - c, err := b.docker.ContainerCreate(&daemon.ContainerCreateConfig{ + c, err := b.docker.ContainerCreate(types.ContainerCreateConfig{ Config: b.runConfig, HostConfig: hostConfig, }) diff --git a/daemon/create.go b/daemon/create.go index ff6bca7f3d..1d8219dc8d 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -13,23 +13,15 @@ import ( "github.com/opencontainers/runc/libcontainer/label" ) -// ContainerCreateConfig is the parameter set to ContainerCreate() -type ContainerCreateConfig struct { - Name string - Config *runconfig.Config - HostConfig *runconfig.HostConfig - AdjustCPUShares bool -} - -// ContainerCreate takes configs and creates a container. -func (daemon *Daemon) ContainerCreate(params *ContainerCreateConfig) (types.ContainerCreateResponse, error) { +// ContainerCreate creates a container. +func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig) (types.ContainerCreateResponse, error) { if params.Config == nil { return types.ContainerCreateResponse{}, derr.ErrorCodeEmptyConfig } warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config) if err != nil { - return types.ContainerCreateResponse{ID: "", Warnings: warnings}, err + return types.ContainerCreateResponse{Warnings: warnings}, err } if params.HostConfig == nil { @@ -37,24 +29,25 @@ func (daemon *Daemon) ContainerCreate(params *ContainerCreateConfig) (types.Cont } err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares) if err != nil { - return types.ContainerCreateResponse{ID: "", Warnings: warnings}, err + return types.ContainerCreateResponse{Warnings: warnings}, err } container, err := daemon.create(params) if err != nil { - return types.ContainerCreateResponse{ID: "", Warnings: warnings}, daemon.imageNotExistToErrcode(err) + return types.ContainerCreateResponse{Warnings: warnings}, daemon.imageNotExistToErrcode(err) } return types.ContainerCreateResponse{ID: container.ID, Warnings: warnings}, nil } // Create creates a new container from the given configuration with a given name. -func (daemon *Daemon) create(params *ContainerCreateConfig) (retC *container.Container, retErr error) { +func (daemon *Daemon) create(params types.ContainerCreateConfig) (*container.Container, error) { var ( container *container.Container img *image.Image imgID image.ID err error + retErr error ) if params.Config.Image != "" {