Skip to content

Commit 52ea99e

Browse files
authored
Merge pull request moby#37189 from arm64b/create-intermediate-for-COPY-ADD
Refactor and cleanup the intermediate container creation
2 parents e3e552a + 7f280f6 commit 52ea99e

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

builder/dockerfile/dispatchers.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/moby/buildkit/frontend/dockerfile/parser"
2929
"github.com/moby/buildkit/frontend/dockerfile/shell"
3030
"github.com/pkg/errors"
31-
"github.com/sirupsen/logrus"
3231
)
3332

3433
// ENV foo bar
@@ -305,10 +304,12 @@ func dispatchWorkdir(d dispatchRequest, c *instructions.WorkdirCommand) error {
305304

306305
comment := "WORKDIR " + runConfig.WorkingDir
307306
runConfigWithCommentCmd := copyRunConfig(runConfig, withCmdCommentString(comment, d.state.operatingSystem))
307+
308308
containerID, err := d.builder.probeAndCreate(d.state, runConfigWithCommentCmd)
309309
if err != nil || containerID == "" {
310310
return err
311311
}
312+
312313
if err := d.builder.docker.ContainerCreateWorkdir(containerID); err != nil {
313314
return err
314315
}
@@ -350,8 +351,7 @@ func dispatchRun(d dispatchRequest, c *instructions.RunCommand) error {
350351
runConfigForCacheProbe := copyRunConfig(stateRunConfig,
351352
withCmd(saveCmd),
352353
withEntrypointOverride(saveCmd, nil))
353-
hit, err := d.builder.probeCache(d.state, runConfigForCacheProbe)
354-
if err != nil || hit {
354+
if hit, err := d.builder.probeCache(d.state, runConfigForCacheProbe); err != nil || hit {
355355
return err
356356
}
357357

@@ -363,11 +363,11 @@ func dispatchRun(d dispatchRequest, c *instructions.RunCommand) error {
363363
// set config as already being escaped, this prevents double escaping on windows
364364
runConfig.ArgsEscaped = true
365365

366-
logrus.Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd)
367366
cID, err := d.builder.create(runConfig)
368367
if err != nil {
369368
return err
370369
}
370+
371371
if err := d.builder.containerManager.Run(d.builder.clientCtx, cID, d.builder.Stdout, d.builder.Stderr); err != nil {
372372
if err, ok := err.(*statusCodeError); ok {
373373
// TODO: change error type, because jsonmessage.JSONError assumes HTTP

builder/dockerfile/internals.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/docker/docker/pkg/system"
2828
"github.com/docker/go-connections/nat"
2929
"github.com/pkg/errors"
30+
"github.com/sirupsen/logrus"
3031
)
3132

3233
// Archiver defines an interface for copying files from one destination to
@@ -84,12 +85,8 @@ func (b *Builder) commit(dispatchState *dispatchState, comment string) error {
8485
}
8586

8687
runConfigWithCommentCmd := copyRunConfig(dispatchState.runConfig, withCmdComment(comment, dispatchState.operatingSystem))
87-
hit, err := b.probeCache(dispatchState, runConfigWithCommentCmd)
88-
if err != nil || hit {
89-
return err
90-
}
91-
id, err := b.create(runConfigWithCommentCmd)
92-
if err != nil {
88+
id, err := b.probeAndCreate(dispatchState, runConfigWithCommentCmd)
89+
if err != nil || id == "" {
9390
return err
9491
}
9592

@@ -413,13 +410,11 @@ func (b *Builder) probeAndCreate(dispatchState *dispatchState, runConfig *contai
413410
if hit, err := b.probeCache(dispatchState, runConfig); err != nil || hit {
414411
return "", err
415412
}
416-
// Set a log config to override any default value set on the daemon
417-
hostConfig := &container.HostConfig{LogConfig: defaultLogConfig}
418-
container, err := b.containerManager.Create(runConfig, hostConfig)
419-
return container.ID, err
413+
return b.create(runConfig)
420414
}
421415

422416
func (b *Builder) create(runConfig *container.Config) (string, error) {
417+
logrus.Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd)
423418
hostConfig := hostConfigFromOptions(b.options)
424419
container, err := b.containerManager.Create(runConfig, hostConfig)
425420
if err != nil {

0 commit comments

Comments
 (0)