1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

builder: remove daemon dependency in ContainerCreate()

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass 2015-12-16 17:56:49 +01:00
parent 9be1ec60d4
commit 03a170c48d
6 changed files with 20 additions and 21 deletions

View file

@ -32,7 +32,7 @@ type copyBackend interface {
// stateBackend includes functions to implement to provide container state lifecycle functionality. // stateBackend includes functions to implement to provide container state lifecycle functionality.
type stateBackend interface { type stateBackend interface {
ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error) ContainerCreate(types.ContainerCreateConfig) (types.ContainerCreateResponse, error)
ContainerKill(name string, sig uint64) error ContainerKill(name string, sig uint64) error
ContainerPause(name string) error ContainerPause(name string) error
ContainerRename(oldName, newName string) error ContainerRename(oldName, newName string) error

View file

@ -339,7 +339,7 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo
version := httputils.VersionFromContext(ctx) version := httputils.VersionFromContext(ctx)
adjustCPUShares := version.LessThan("1.19") adjustCPUShares := version.LessThan("1.19")
ccr, err := s.backend.ContainerCreate(&daemon.ContainerCreateConfig{ ccr, err := s.backend.ContainerCreate(types.ContainerCreateConfig{
Name: name, Name: name,
Config: config, Config: config,
HostConfig: hostConfig, HostConfig: hostConfig,

View file

@ -8,6 +8,14 @@ import (
"github.com/docker/docker/runconfig" "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 // ContainerRmConfig holds arguments for the container remove
// operation. This struct is used to tell the backend what operations // operation. This struct is used to tell the backend what operations
// to perform. // to perform.

View file

@ -10,7 +10,6 @@ import (
"time" "time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/daemon"
"github.com/docker/docker/runconfig" "github.com/docker/docker/runconfig"
) )
@ -117,7 +116,7 @@ type Backend interface {
// ContainerWsAttachWithLogs attaches to container. // ContainerWsAttachWithLogs attaches to container.
ContainerWsAttachWithLogs(name string, cfg *daemon.ContainerWsAttachWithLogsConfig) error ContainerWsAttachWithLogs(name string, cfg *daemon.ContainerWsAttachWithLogsConfig) error
// ContainerCreate creates a new Docker container and returns potential warnings // 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 removes a container specified by `id`.
ContainerRm(name string, config *types.ContainerRmConfig) error ContainerRm(name string, config *types.ContainerRmConfig) error
// Commit creates a new Docker image from an existing Docker container. // Commit creates a new Docker image from an existing Docker container.

View file

@ -23,7 +23,6 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/builder" "github.com/docker/docker/builder"
"github.com/docker/docker/builder/dockerfile/parser" "github.com/docker/docker/builder/dockerfile/parser"
"github.com/docker/docker/daemon"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/httputils" "github.com/docker/docker/pkg/httputils"
"github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/ioutils"
@ -188,7 +187,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
return nil 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 { if err != nil {
return err return err
} }
@ -507,7 +506,7 @@ func (b *Builder) create() (string, error) {
config := *b.runConfig config := *b.runConfig
// Create the container // Create the container
c, err := b.docker.ContainerCreate(&daemon.ContainerCreateConfig{ c, err := b.docker.ContainerCreate(types.ContainerCreateConfig{
Config: b.runConfig, Config: b.runConfig,
HostConfig: hostConfig, HostConfig: hostConfig,
}) })

View file

@ -13,23 +13,15 @@ import (
"github.com/opencontainers/runc/libcontainer/label" "github.com/opencontainers/runc/libcontainer/label"
) )
// ContainerCreateConfig is the parameter set to ContainerCreate() // ContainerCreate creates a container.
type ContainerCreateConfig struct { func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig) (types.ContainerCreateResponse, error) {
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) {
if params.Config == nil { if params.Config == nil {
return types.ContainerCreateResponse{}, derr.ErrorCodeEmptyConfig return types.ContainerCreateResponse{}, derr.ErrorCodeEmptyConfig
} }
warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config) warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config)
if err != nil { if err != nil {
return types.ContainerCreateResponse{ID: "", Warnings: warnings}, err return types.ContainerCreateResponse{Warnings: warnings}, err
} }
if params.HostConfig == nil { if params.HostConfig == nil {
@ -37,24 +29,25 @@ func (daemon *Daemon) ContainerCreate(params *ContainerCreateConfig) (types.Cont
} }
err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares) err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares)
if err != nil { if err != nil {
return types.ContainerCreateResponse{ID: "", Warnings: warnings}, err return types.ContainerCreateResponse{Warnings: warnings}, err
} }
container, err := daemon.create(params) container, err := daemon.create(params)
if err != nil { 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 return types.ContainerCreateResponse{ID: container.ID, Warnings: warnings}, nil
} }
// Create creates a new container from the given configuration with a given name. // 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 ( var (
container *container.Container container *container.Container
img *image.Image img *image.Image
imgID image.ID imgID image.ID
err error err error
retErr error
) )
if params.Config.Image != "" { if params.Config.Image != "" {