Refactor and cleanup the intermediate container creation
| ... | ... |
@@ -28,7 +28,6 @@ import ( |
| 28 | 28 |
"github.com/moby/buildkit/frontend/dockerfile/parser" |
| 29 | 29 |
"github.com/moby/buildkit/frontend/dockerfile/shell" |
| 30 | 30 |
"github.com/pkg/errors" |
| 31 |
- "github.com/sirupsen/logrus" |
|
| 32 | 31 |
) |
| 33 | 32 |
|
| 34 | 33 |
// ENV foo bar |
| ... | ... |
@@ -305,10 +304,12 @@ func dispatchWorkdir(d dispatchRequest, c *instructions.WorkdirCommand) error {
|
| 305 | 305 |
|
| 306 | 306 |
comment := "WORKDIR " + runConfig.WorkingDir |
| 307 | 307 |
runConfigWithCommentCmd := copyRunConfig(runConfig, withCmdCommentString(comment, d.state.operatingSystem)) |
| 308 |
+ |
|
| 308 | 309 |
containerID, err := d.builder.probeAndCreate(d.state, runConfigWithCommentCmd) |
| 309 | 310 |
if err != nil || containerID == "" {
|
| 310 | 311 |
return err |
| 311 | 312 |
} |
| 313 |
+ |
|
| 312 | 314 |
if err := d.builder.docker.ContainerCreateWorkdir(containerID); err != nil {
|
| 313 | 315 |
return err |
| 314 | 316 |
} |
| ... | ... |
@@ -350,8 +351,7 @@ func dispatchRun(d dispatchRequest, c *instructions.RunCommand) error {
|
| 350 | 350 |
runConfigForCacheProbe := copyRunConfig(stateRunConfig, |
| 351 | 351 |
withCmd(saveCmd), |
| 352 | 352 |
withEntrypointOverride(saveCmd, nil)) |
| 353 |
- hit, err := d.builder.probeCache(d.state, runConfigForCacheProbe) |
|
| 354 |
- if err != nil || hit {
|
|
| 353 |
+ if hit, err := d.builder.probeCache(d.state, runConfigForCacheProbe); err != nil || hit {
|
|
| 355 | 354 |
return err |
| 356 | 355 |
} |
| 357 | 356 |
|
| ... | ... |
@@ -363,11 +363,11 @@ func dispatchRun(d dispatchRequest, c *instructions.RunCommand) error {
|
| 363 | 363 |
// set config as already being escaped, this prevents double escaping on windows |
| 364 | 364 |
runConfig.ArgsEscaped = true |
| 365 | 365 |
|
| 366 |
- logrus.Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd)
|
|
| 367 | 366 |
cID, err := d.builder.create(runConfig) |
| 368 | 367 |
if err != nil {
|
| 369 | 368 |
return err |
| 370 | 369 |
} |
| 370 |
+ |
|
| 371 | 371 |
if err := d.builder.containerManager.Run(d.builder.clientCtx, cID, d.builder.Stdout, d.builder.Stderr); err != nil {
|
| 372 | 372 |
if err, ok := err.(*statusCodeError); ok {
|
| 373 | 373 |
// TODO: change error type, because jsonmessage.JSONError assumes HTTP |
| ... | ... |
@@ -27,6 +27,7 @@ import ( |
| 27 | 27 |
"github.com/docker/docker/pkg/system" |
| 28 | 28 |
"github.com/docker/go-connections/nat" |
| 29 | 29 |
"github.com/pkg/errors" |
| 30 |
+ "github.com/sirupsen/logrus" |
|
| 30 | 31 |
) |
| 31 | 32 |
|
| 32 | 33 |
// Archiver defines an interface for copying files from one destination to |
| ... | ... |
@@ -84,12 +85,8 @@ func (b *Builder) commit(dispatchState *dispatchState, comment string) error {
|
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 | 86 |
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 {
|
|
| 87 |
+ id, err := b.probeAndCreate(dispatchState, runConfigWithCommentCmd) |
|
| 88 |
+ if err != nil || id == "" {
|
|
| 93 | 89 |
return err |
| 94 | 90 |
} |
| 95 | 91 |
|
| ... | ... |
@@ -413,13 +410,11 @@ func (b *Builder) probeAndCreate(dispatchState *dispatchState, runConfig *contai |
| 413 | 413 |
if hit, err := b.probeCache(dispatchState, runConfig); err != nil || hit {
|
| 414 | 414 |
return "", err |
| 415 | 415 |
} |
| 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 |
|
| 416 |
+ return b.create(runConfig) |
|
| 420 | 417 |
} |
| 421 | 418 |
|
| 422 | 419 |
func (b *Builder) create(runConfig *container.Config) (string, error) {
|
| 420 |
+ logrus.Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd)
|
|
| 423 | 421 |
hostConfig := hostConfigFromOptions(b.options) |
| 424 | 422 |
container, err := b.containerManager.Create(runConfig, hostConfig) |
| 425 | 423 |
if err != nil {
|