Skip to content

Commit 1d34661

Browse files
ndeloofglours
authored andcommitted
fix support for additional_contexts with service sub-dependencies
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 0f9e6ab commit 1d34661

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

pkg/compose/build.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,11 @@ func parsePlatforms(service types.ServiceConfig) ([]specs.Platform, error) {
628628
func addBuildDependencies(services []string, project *types.Project) []string {
629629
servicesWithDependencies := utils.NewSet(services...)
630630
for _, service := range services {
631-
b := project.Services[service].Build
631+
s, ok := project.Services[service]
632+
if !ok {
633+
s = project.DisabledServices[service]
634+
}
635+
b := s.Build
632636
if b != nil {
633637
for _, target := range b.AdditionalContexts {
634638
if s, found := strings.CutPrefix(target, types.ServicePrefix); found {

pkg/e2e/build_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,3 +564,19 @@ func TestBuildDependentImage(t *testing.T) {
564564
out = res.Combined()
565565
assert.Check(t, strings.Contains(out, "secondbuild Built"))
566566
}
567+
568+
func TestBuildSubDependencies(t *testing.T) {
569+
c := NewParallelCLI(t)
570+
571+
t.Cleanup(func() {
572+
c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/sub-dependencies/compose.yaml", "down", "--rmi=local")
573+
})
574+
575+
res := c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/sub-dependencies/compose.yaml", "build", "main")
576+
out := res.Combined()
577+
assert.Check(t, strings.Contains(out, "main Built"))
578+
579+
res = c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/sub-dependencies/compose.yaml", "up", "--build", "main")
580+
out = res.Combined()
581+
assert.Check(t, strings.Contains(out, "main Built"))
582+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
services:
2+
main:
3+
build:
4+
dockerfile_inline: |
5+
FROM alpine
6+
additional_contexts:
7+
dep1: service:dep1
8+
dep2: service:dep2
9+
entrypoint: ["echo", "Hello from main"]
10+
11+
dep1:
12+
build:
13+
dockerfile_inline: |
14+
FROM alpine
15+
additional_contexts:
16+
subdep1: service:subdep1
17+
subdep2: service:subdep2
18+
entrypoint: ["echo", "Hello from dep1"]
19+
20+
dep2:
21+
build:
22+
dockerfile_inline: |
23+
FROM alpine
24+
entrypoint: ["echo", "Hello from dep2"]
25+
26+
subdep1:
27+
build:
28+
dockerfile_inline: |
29+
FROM alpine
30+
entrypoint: ["echo", "Hello from subdep1"]
31+
32+
subdep2:
33+
build:
34+
dockerfile_inline: |
35+
FROM alpine
36+
entrypoint: ["echo", "Hello from subdep2"]

0 commit comments

Comments
 (0)