Skip to content

Commit 7cf7c64

Browse files
ndeloofglours
authored andcommitted
build resolves enabled service after project has been loaded
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 0e0ed91 commit 7cf7c64

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

cmd/compose/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func buildCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
145145
}
146146

147147
func runBuild(ctx context.Context, dockerCli command.Cli, backend api.Service, opts buildOptions, services []string) error {
148+
opts.All = true // do not drop resources as build may involve some dependencies by additional_contexts
148149
project, _, err := opts.ToProject(ctx, dockerCli, nil, cli.WithResolvedPaths(true), cli.WithoutEnvironmentResolution)
149150
if err != nil {
150151
return err

pkg/e2e/build_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,3 +596,15 @@ func TestBuildLongOutputLine(t *testing.T) {
596596
out = res.Combined()
597597
assert.Check(t, strings.Contains(out, "long-line Built"))
598598
}
599+
600+
func TestBuildDependentImageWithProfile(t *testing.T) {
601+
c := NewParallelCLI(t)
602+
603+
t.Cleanup(func() {
604+
c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/profiles/compose.yaml", "down", "--rmi=local")
605+
})
606+
607+
res := c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/profiles/compose.yaml", "build", "secret-build-test")
608+
out := res.Combined()
609+
assert.Check(t, strings.Contains(out, "secret-build-test Built"))
610+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2020 Docker Compose CLI authors
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
FROM alpine
17+
RUN --mount=type=secret,id=test-secret ls -la /run/secrets/; cp /run/secrets/test-secret /tmp
18+
19+
CMD ["cat", "/tmp/test-secret"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
secrets:
2+
test-secret:
3+
file: test-secret.txt
4+
5+
services:
6+
secret-build-test:
7+
profiles: ["test"]
8+
build:
9+
context: .
10+
dockerfile: Dockerfile
11+
secrets:
12+
- test-secret
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SECRET

0 commit comments

Comments
 (0)