mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
refactor create to not expose internal data structures
- use existing exposed type Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
This commit is contained in:
parent
02ae137b1d
commit
93bd57b0b2
3 changed files with 23 additions and 19 deletions
|
@ -366,10 +366,8 @@ func (s *Server) postContainersCreate(ctx context.Context, w http.ResponseWriter
|
|||
if err := checkForJSON(r); err != nil {
|
||||
return err
|
||||
}
|
||||
var (
|
||||
warnings []string
|
||||
name = r.Form.Get("name")
|
||||
)
|
||||
|
||||
name := r.Form.Get("name")
|
||||
|
||||
config, hostConfig, err := runconfig.DecodeContainerConfig(r.Body)
|
||||
if err != nil {
|
||||
|
@ -378,15 +376,12 @@ func (s *Server) postContainersCreate(ctx context.Context, w http.ResponseWriter
|
|||
version := ctx.Version()
|
||||
adjustCPUShares := version.LessThan("1.19")
|
||||
|
||||
container, warnings, err := s.daemon.ContainerCreate(ctx, name, config, hostConfig, adjustCPUShares)
|
||||
ccr, err := s.daemon.ContainerCreate(ctx, name, config, hostConfig, adjustCPUShares)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return writeJSON(w, http.StatusCreated, &types.ContainerCreateResponse{
|
||||
ID: container.ID,
|
||||
Warnings: warnings,
|
||||
})
|
||||
return writeJSON(w, http.StatusCreated, ccr)
|
||||
}
|
||||
|
||||
func (s *Server) deleteContainers(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
|
|
|
@ -233,10 +233,15 @@ func (b *builder) runContextCommand(ctx context.Context, args []string, allowRem
|
|||
return nil
|
||||
}
|
||||
|
||||
container, _, err := b.Daemon.ContainerCreate(ctx, "", b.Config, nil, true)
|
||||
ccr, err := b.Daemon.ContainerCreate(ctx, "", b.Config, nil, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
container, err := b.Daemon.Get(ctx, ccr.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.TmpContainers[container.ID] = struct{}{}
|
||||
|
||||
if err := container.Mount(ctx); err != nil {
|
||||
|
@ -621,13 +626,17 @@ func (b *builder) create(ctx context.Context) (*daemon.Container, error) {
|
|||
config := *b.Config
|
||||
|
||||
// Create the container
|
||||
c, warnings, err := b.Daemon.ContainerCreate(ctx, "", b.Config, hostConfig, true)
|
||||
ccr, err := b.Daemon.ContainerCreate(ctx, "", b.Config, hostConfig, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, warning := range warnings {
|
||||
for _, warning := range ccr.Warnings {
|
||||
fmt.Fprintf(b.OutStream, " ---> [Warning] %s\n", warning)
|
||||
}
|
||||
c, err := b.Daemon.Get(ctx, ccr.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b.TmpContainers[c.ID] = struct{}{}
|
||||
fmt.Fprintf(b.OutStream, " ---> Running in %s\n", stringid.TruncateID(c.ID))
|
||||
|
|
|
@ -16,14 +16,14 @@ import (
|
|||
)
|
||||
|
||||
// ContainerCreate takes configs and creates a container.
|
||||
func (daemon *Daemon) ContainerCreate(ctx context.Context, name string, config *runconfig.Config, hostConfig *runconfig.HostConfig, adjustCPUShares bool) (*Container, []string, error) {
|
||||
func (daemon *Daemon) ContainerCreate(ctx context.Context, name string, config *runconfig.Config, hostConfig *runconfig.HostConfig, adjustCPUShares bool) (types.ContainerCreateResponse, error) {
|
||||
if config == nil {
|
||||
return nil, nil, derr.ErrorCodeEmptyConfig
|
||||
return types.ContainerCreateResponse{}, derr.ErrorCodeEmptyConfig
|
||||
}
|
||||
|
||||
warnings, err := daemon.verifyContainerSettings(ctx, hostConfig, config)
|
||||
if err != nil {
|
||||
return nil, warnings, err
|
||||
return types.ContainerCreateResponse{"", warnings}, err
|
||||
}
|
||||
|
||||
daemon.adaptContainerSettings(hostConfig, adjustCPUShares)
|
||||
|
@ -32,20 +32,20 @@ func (daemon *Daemon) ContainerCreate(ctx context.Context, name string, config *
|
|||
if err != nil {
|
||||
if daemon.Graph(ctx).IsNotExist(err, config.Image) {
|
||||
if strings.Contains(config.Image, "@") {
|
||||
return nil, warnings, derr.ErrorCodeNoSuchImageHash.WithArgs(config.Image)
|
||||
return types.ContainerCreateResponse{"", warnings}, derr.ErrorCodeNoSuchImageHash.WithArgs(config.Image)
|
||||
}
|
||||
img, tag := parsers.ParseRepositoryTag(config.Image)
|
||||
if tag == "" {
|
||||
tag = tags.DefaultTag
|
||||
}
|
||||
return nil, warnings, derr.ErrorCodeNoSuchImageTag.WithArgs(img, tag)
|
||||
return types.ContainerCreateResponse{"", warnings}, derr.ErrorCodeNoSuchImageTag.WithArgs(img, tag)
|
||||
}
|
||||
return nil, warnings, err
|
||||
return types.ContainerCreateResponse{"", warnings}, err
|
||||
}
|
||||
|
||||
warnings = append(warnings, buildWarnings...)
|
||||
|
||||
return container, warnings, nil
|
||||
return types.ContainerCreateResponse{container.ID, warnings}, nil
|
||||
}
|
||||
|
||||
// Create creates a new container from the given configuration with a given name.
|
||||
|
|
Loading…
Reference in a new issue