Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 03a170c

Browse files
author
Tibor Vass
committed
builder: remove daemon dependency in ContainerCreate()
Signed-off-by: Tibor Vass <tibor@docker.com>
1 parent 9be1ec6 commit 03a170c

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

api/server/router/container/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type copyBackend interface {
3232

3333
// stateBackend includes functions to implement to provide container state lifecycle functionality.
3434
type stateBackend interface {
35-
ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error)
35+
ContainerCreate(types.ContainerCreateConfig) (types.ContainerCreateResponse, error)
3636
ContainerKill(name string, sig uint64) error
3737
ContainerPause(name string) error
3838
ContainerRename(oldName, newName string) error

api/server/router/container/container_routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo
339339
version := httputils.VersionFromContext(ctx)
340340
adjustCPUShares := version.LessThan("1.19")
341341

342-
ccr, err := s.backend.ContainerCreate(&daemon.ContainerCreateConfig{
342+
ccr, err := s.backend.ContainerCreate(types.ContainerCreateConfig{
343343
Name: name,
344344
Config: config,
345345
HostConfig: hostConfig,

api/types/configs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import (
88
"github.com/docker/docker/runconfig"
99
)
1010

11+
// ContainerCreateConfig is the parameter set to ContainerCreate()
12+
type ContainerCreateConfig struct {
13+
Name string
14+
Config *runconfig.Config
15+
HostConfig *runconfig.HostConfig
16+
AdjustCPUShares bool
17+
}
18+
1119
// ContainerRmConfig holds arguments for the container remove
1220
// operation. This struct is used to tell the backend what operations
1321
// to perform.

builder/builder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/docker/docker/api/types"
13-
"github.com/docker/docker/daemon"
1413
"github.com/docker/docker/runconfig"
1514
)
1615

@@ -117,7 +116,7 @@ type Backend interface {
117116
// ContainerWsAttachWithLogs attaches to container.
118117
ContainerWsAttachWithLogs(name string, cfg *daemon.ContainerWsAttachWithLogsConfig) error
119118
// ContainerCreate creates a new Docker container and returns potential warnings
120-
ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error)
119+
ContainerCreate(types.ContainerCreateConfig) (types.ContainerCreateResponse, error)
121120
// ContainerRm removes a container specified by `id`.
122121
ContainerRm(name string, config *types.ContainerRmConfig) error
123122
// Commit creates a new Docker image from an existing Docker container.

builder/dockerfile/internals.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/docker/docker/api/types"
2424
"github.com/docker/docker/builder"
2525
"github.com/docker/docker/builder/dockerfile/parser"
26-
"github.com/docker/docker/daemon"
2726
"github.com/docker/docker/pkg/archive"
2827
"github.com/docker/docker/pkg/httputils"
2928
"github.com/docker/docker/pkg/ioutils"
@@ -188,7 +187,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
188187
return nil
189188
}
190189

191-
container, err := b.docker.ContainerCreate(&daemon.ContainerCreateConfig{Config: b.runConfig})
190+
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig})
192191
if err != nil {
193192
return err
194193
}
@@ -507,7 +506,7 @@ func (b *Builder) create() (string, error) {
507506
config := *b.runConfig
508507

509508
// Create the container
510-
c, err := b.docker.ContainerCreate(&daemon.ContainerCreateConfig{
509+
c, err := b.docker.ContainerCreate(types.ContainerCreateConfig{
511510
Config: b.runConfig,
512511
HostConfig: hostConfig,
513512
})

daemon/create.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,41 @@ import (
1313
"github.com/opencontainers/runc/libcontainer/label"
1414
)
1515

16-
// ContainerCreateConfig is the parameter set to ContainerCreate()
17-
type ContainerCreateConfig struct {
18-
Name string
19-
Config *runconfig.Config
20-
HostConfig *runconfig.HostConfig
21-
AdjustCPUShares bool
22-
}
23-
24-
// ContainerCreate takes configs and creates a container.
25-
func (daemon *Daemon) ContainerCreate(params *ContainerCreateConfig) (types.ContainerCreateResponse, error) {
16+
// ContainerCreate creates a container.
17+
func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig) (types.ContainerCreateResponse, error) {
2618
if params.Config == nil {
2719
return types.ContainerCreateResponse{}, derr.ErrorCodeEmptyConfig
2820
}
2921

3022
warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config)
3123
if err != nil {
32-
return types.ContainerCreateResponse{ID: "", Warnings: warnings}, err
24+
return types.ContainerCreateResponse{Warnings: warnings}, err
3325
}
3426

3527
if params.HostConfig == nil {
3628
params.HostConfig = &runconfig.HostConfig{}
3729
}
3830
err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares)
3931
if err != nil {
40-
return types.ContainerCreateResponse{ID: "", Warnings: warnings}, err
32+
return types.ContainerCreateResponse{Warnings: warnings}, err
4133
}
4234

4335
container, err := daemon.create(params)
4436
if err != nil {
45-
return types.ContainerCreateResponse{ID: "", Warnings: warnings}, daemon.imageNotExistToErrcode(err)
37+
return types.ContainerCreateResponse{Warnings: warnings}, daemon.imageNotExistToErrcode(err)
4638
}
4739

4840
return types.ContainerCreateResponse{ID: container.ID, Warnings: warnings}, nil
4941
}
5042

5143
// Create creates a new container from the given configuration with a given name.
52-
func (daemon *Daemon) create(params *ContainerCreateConfig) (retC *container.Container, retErr error) {
44+
func (daemon *Daemon) create(params types.ContainerCreateConfig) (*container.Container, error) {
5345
var (
5446
container *container.Container
5547
img *image.Image
5648
imgID image.ID
5749
err error
50+
retErr error
5851
)
5952

6053
if params.Config.Image != "" {

0 commit comments

Comments
 (0)