Jelajahi Sumber

build resolves enabled service after project has been loaded

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 5 bulan lalu
induk
melakukan
7cf7c6414f

+ 1 - 0
cmd/compose/build.go

@@ -145,6 +145,7 @@ func buildCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
 }
 
 func runBuild(ctx context.Context, dockerCli command.Cli, backend api.Service, opts buildOptions, services []string) error {
+	opts.All = true // do not drop resources as build may involve some dependencies by additional_contexts
 	project, _, err := opts.ToProject(ctx, dockerCli, nil, cli.WithResolvedPaths(true), cli.WithoutEnvironmentResolution)
 	if err != nil {
 		return err

+ 12 - 0
pkg/e2e/build_test.go

@@ -596,3 +596,15 @@ func TestBuildLongOutputLine(t *testing.T) {
 	out = res.Combined()
 	assert.Check(t, strings.Contains(out, "long-line  Built"))
 }
+
+func TestBuildDependentImageWithProfile(t *testing.T) {
+	c := NewParallelCLI(t)
+
+	t.Cleanup(func() {
+		c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/profiles/compose.yaml", "down", "--rmi=local")
+	})
+
+	res := c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/profiles/compose.yaml", "build", "secret-build-test")
+	out := res.Combined()
+	assert.Check(t, strings.Contains(out, "secret-build-test  Built"))
+}

+ 19 - 0
pkg/e2e/fixtures/build-test/profiles/Dockerfile

@@ -0,0 +1,19 @@
+#   Copyright 2020 Docker Compose CLI authors
+
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+
+#       http://www.apache.org/licenses/LICENSE-2.0
+
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+
+FROM alpine
+RUN --mount=type=secret,id=test-secret ls -la /run/secrets/; cp /run/secrets/test-secret /tmp
+
+CMD ["cat", "/tmp/test-secret"]

+ 12 - 0
pkg/e2e/fixtures/build-test/profiles/compose.yaml

@@ -0,0 +1,12 @@
+secrets:
+  test-secret:
+    file: test-secret.txt
+
+services:
+  secret-build-test:
+    profiles: ["test"]
+    build:
+      context: .
+      dockerfile: Dockerfile
+      secrets:
+        - test-secret

+ 1 - 0
pkg/e2e/fixtures/build-test/profiles/test-secret.txt

@@ -0,0 +1 @@
+SECRET