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

Merge pull request #37189 from arm64b/create-intermediate-for-COPY-ADD

Refactor and cleanup the intermediate container creation
This commit is contained in:
Sebastiaan van Stijn 2018-06-07 21:20:17 -07:00 committed by GitHub
commit 52ea99eda2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 14 deletions

View file

@ -28,7 +28,6 @@ import (
"github.com/moby/buildkit/frontend/dockerfile/parser" "github.com/moby/buildkit/frontend/dockerfile/parser"
"github.com/moby/buildkit/frontend/dockerfile/shell" "github.com/moby/buildkit/frontend/dockerfile/shell"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus"
) )
// ENV foo bar // ENV foo bar
@ -305,10 +304,12 @@ func dispatchWorkdir(d dispatchRequest, c *instructions.WorkdirCommand) error {
comment := "WORKDIR " + runConfig.WorkingDir comment := "WORKDIR " + runConfig.WorkingDir
runConfigWithCommentCmd := copyRunConfig(runConfig, withCmdCommentString(comment, d.state.operatingSystem)) runConfigWithCommentCmd := copyRunConfig(runConfig, withCmdCommentString(comment, d.state.operatingSystem))
containerID, err := d.builder.probeAndCreate(d.state, runConfigWithCommentCmd) containerID, err := d.builder.probeAndCreate(d.state, runConfigWithCommentCmd)
if err != nil || containerID == "" { if err != nil || containerID == "" {
return err return err
} }
if err := d.builder.docker.ContainerCreateWorkdir(containerID); err != nil { if err := d.builder.docker.ContainerCreateWorkdir(containerID); err != nil {
return err return err
} }
@ -350,8 +351,7 @@ func dispatchRun(d dispatchRequest, c *instructions.RunCommand) error {
runConfigForCacheProbe := copyRunConfig(stateRunConfig, runConfigForCacheProbe := copyRunConfig(stateRunConfig,
withCmd(saveCmd), withCmd(saveCmd),
withEntrypointOverride(saveCmd, nil)) withEntrypointOverride(saveCmd, nil))
hit, err := d.builder.probeCache(d.state, runConfigForCacheProbe) if hit, err := d.builder.probeCache(d.state, runConfigForCacheProbe); err != nil || hit {
if err != nil || hit {
return err return err
} }
@ -363,11 +363,11 @@ func dispatchRun(d dispatchRequest, c *instructions.RunCommand) error {
// set config as already being escaped, this prevents double escaping on windows // set config as already being escaped, this prevents double escaping on windows
runConfig.ArgsEscaped = true runConfig.ArgsEscaped = true
logrus.Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd)
cID, err := d.builder.create(runConfig) cID, err := d.builder.create(runConfig)
if err != nil { if err != nil {
return err return err
} }
if err := d.builder.containerManager.Run(d.builder.clientCtx, cID, d.builder.Stdout, d.builder.Stderr); err != nil { if err := d.builder.containerManager.Run(d.builder.clientCtx, cID, d.builder.Stdout, d.builder.Stderr); err != nil {
if err, ok := err.(*statusCodeError); ok { if err, ok := err.(*statusCodeError); ok {
// TODO: change error type, because jsonmessage.JSONError assumes HTTP // TODO: change error type, because jsonmessage.JSONError assumes HTTP

View file

@ -27,6 +27,7 @@ import (
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus"
) )
// Archiver defines an interface for copying files from one destination to // Archiver defines an interface for copying files from one destination to
@ -84,12 +85,8 @@ func (b *Builder) commit(dispatchState *dispatchState, comment string) error {
} }
runConfigWithCommentCmd := copyRunConfig(dispatchState.runConfig, withCmdComment(comment, dispatchState.operatingSystem)) runConfigWithCommentCmd := copyRunConfig(dispatchState.runConfig, withCmdComment(comment, dispatchState.operatingSystem))
hit, err := b.probeCache(dispatchState, runConfigWithCommentCmd) id, err := b.probeAndCreate(dispatchState, runConfigWithCommentCmd)
if err != nil || hit { if err != nil || id == "" {
return err
}
id, err := b.create(runConfigWithCommentCmd)
if err != nil {
return err return err
} }
@ -413,13 +410,11 @@ func (b *Builder) probeAndCreate(dispatchState *dispatchState, runConfig *contai
if hit, err := b.probeCache(dispatchState, runConfig); err != nil || hit { if hit, err := b.probeCache(dispatchState, runConfig); err != nil || hit {
return "", err return "", err
} }
// Set a log config to override any default value set on the daemon return b.create(runConfig)
hostConfig := &container.HostConfig{LogConfig: defaultLogConfig}
container, err := b.containerManager.Create(runConfig, hostConfig)
return container.ID, err
} }
func (b *Builder) create(runConfig *container.Config) (string, error) { func (b *Builder) create(runConfig *container.Config) (string, error) {
logrus.Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd)
hostConfig := hostConfigFromOptions(b.options) hostConfig := hostConfigFromOptions(b.options)
container, err := b.containerManager.Create(runConfig, hostConfig) container, err := b.containerManager.Create(runConfig, hostConfig)
if err != nil { if err != nil {