mirror of
https://github.com/docker/compose.git
synced 2025-07-08 22:34:26 +02:00
Merge pull request #10423 from ndeloof/build_classic_panic
prevent panic using classic builder
This commit is contained in:
commit
449a46a252
@ -75,7 +75,11 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !buildkitEnabled {
|
if !buildkitEnabled {
|
||||||
|
if service.Build.Args == nil {
|
||||||
|
service.Build.Args = args
|
||||||
|
} else {
|
||||||
service.Build.Args = service.Build.Args.OverrideBy(args)
|
service.Build.Args = service.Build.Args.OverrideBy(args)
|
||||||
|
}
|
||||||
id, err := s.doBuildClassic(ctx, service)
|
id, err := s.doBuildClassic(ctx, service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -29,9 +29,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestLocalComposeBuild(t *testing.T) {
|
func TestLocalComposeBuild(t *testing.T) {
|
||||||
c := NewParallelCLI(t)
|
|
||||||
|
|
||||||
t.Run("build named and unnamed images", func(t *testing.T) {
|
for _, env := range []string{"DOCKER_BUILDKIT=0", "DOCKER_BUILDKIT=1"} {
|
||||||
|
c := NewCLI(t, WithEnv(env))
|
||||||
|
|
||||||
|
t.Run(env+" build named and unnamed images", func(t *testing.T) {
|
||||||
// ensure local test run does not reuse previously build image
|
// ensure local test run does not reuse previously build image
|
||||||
c.RunDockerOrExitError(t, "rmi", "build-test-nginx")
|
c.RunDockerOrExitError(t, "rmi", "build-test-nginx")
|
||||||
c.RunDockerOrExitError(t, "rmi", "custom-nginx")
|
c.RunDockerOrExitError(t, "rmi", "custom-nginx")
|
||||||
@ -43,7 +45,7 @@ func TestLocalComposeBuild(t *testing.T) {
|
|||||||
c.RunDockerCmd(t, "image", "inspect", "custom-nginx")
|
c.RunDockerCmd(t, "image", "inspect", "custom-nginx")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("build with build-arg", func(t *testing.T) {
|
t.Run(env+" build with build-arg", func(t *testing.T) {
|
||||||
// ensure local test run does not reuse previously build image
|
// ensure local test run does not reuse previously build image
|
||||||
c.RunDockerOrExitError(t, "rmi", "build-test-nginx")
|
c.RunDockerOrExitError(t, "rmi", "build-test-nginx")
|
||||||
c.RunDockerOrExitError(t, "rmi", "custom-nginx")
|
c.RunDockerOrExitError(t, "rmi", "custom-nginx")
|
||||||
@ -54,7 +56,7 @@ func TestLocalComposeBuild(t *testing.T) {
|
|||||||
res.Assert(t, icmd.Expected{Out: `"FOO": "BAR"`})
|
res.Assert(t, icmd.Expected{Out: `"FOO": "BAR"`})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("build with build-arg set by env", func(t *testing.T) {
|
t.Run(env+" build with build-arg set by env", func(t *testing.T) {
|
||||||
// ensure local test run does not reuse previously build image
|
// ensure local test run does not reuse previously build image
|
||||||
c.RunDockerOrExitError(t, "rmi", "build-test-nginx")
|
c.RunDockerOrExitError(t, "rmi", "build-test-nginx")
|
||||||
c.RunDockerOrExitError(t, "rmi", "custom-nginx")
|
c.RunDockerOrExitError(t, "rmi", "custom-nginx")
|
||||||
@ -73,7 +75,7 @@ func TestLocalComposeBuild(t *testing.T) {
|
|||||||
res.Assert(t, icmd.Expected{Out: `"FOO": "BAR"`})
|
res.Assert(t, icmd.Expected{Out: `"FOO": "BAR"`})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("build with multiple build-args ", func(t *testing.T) {
|
t.Run(env+" build with multiple build-args ", func(t *testing.T) {
|
||||||
// ensure local test run does not reuse previously build image
|
// ensure local test run does not reuse previously build image
|
||||||
c.RunDockerOrExitError(t, "rmi", "-f", "multi-args-multiargs")
|
c.RunDockerOrExitError(t, "rmi", "-f", "multi-args-multiargs")
|
||||||
cmd := c.NewDockerComposeCmd(t, "--project-directory", "fixtures/build-test/multi-args", "build")
|
cmd := c.NewDockerComposeCmd(t, "--project-directory", "fixtures/build-test/multi-args", "build")
|
||||||
@ -86,7 +88,7 @@ func TestLocalComposeBuild(t *testing.T) {
|
|||||||
res.Assert(t, icmd.Expected{Out: `"RESULT": "SUCCESS"`})
|
res.Assert(t, icmd.Expected{Out: `"RESULT": "SUCCESS"`})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("build as part of up", func(t *testing.T) {
|
t.Run(env+" build as part of up", func(t *testing.T) {
|
||||||
c.RunDockerOrExitError(t, "rmi", "build-test-nginx")
|
c.RunDockerOrExitError(t, "rmi", "build-test-nginx")
|
||||||
c.RunDockerOrExitError(t, "rmi", "custom-nginx")
|
c.RunDockerOrExitError(t, "rmi", "custom-nginx")
|
||||||
|
|
||||||
@ -105,24 +107,26 @@ func TestLocalComposeBuild(t *testing.T) {
|
|||||||
c.RunDockerCmd(t, "image", "inspect", "custom-nginx")
|
c.RunDockerCmd(t, "image", "inspect", "custom-nginx")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("no rebuild when up again", func(t *testing.T) {
|
t.Run(env+" no rebuild when up again", func(t *testing.T) {
|
||||||
res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "up", "-d")
|
res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "up", "-d")
|
||||||
|
|
||||||
assert.Assert(t, !strings.Contains(res.Stdout(), "COPY static"), res.Stdout())
|
assert.Assert(t, !strings.Contains(res.Stdout(), "COPY static"), res.Stdout())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("rebuild when up --build", func(t *testing.T) {
|
t.Run(env+" rebuild when up --build", func(t *testing.T) {
|
||||||
res := c.RunDockerComposeCmd(t, "--workdir", "fixtures/build-test", "up", "-d", "--build")
|
res := c.RunDockerComposeCmd(t, "--workdir", "fixtures/build-test", "up", "-d", "--build")
|
||||||
|
|
||||||
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
|
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
|
||||||
res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"})
|
res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("cleanup build project", func(t *testing.T) {
|
t.Run(env+" cleanup build project", func(t *testing.T) {
|
||||||
c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "down")
|
c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "down")
|
||||||
c.RunDockerCmd(t, "rmi", "build-test-nginx")
|
c.RunDockerCmd(t, "rmi", "build-test-nginx")
|
||||||
c.RunDockerCmd(t, "rmi", "custom-nginx")
|
c.RunDockerCmd(t, "rmi", "custom-nginx")
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildSSH(t *testing.T) {
|
func TestBuildSSH(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user