Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,11 @@ func parsePlatforms(service types.ServiceConfig) ([]specs.Platform, error) {
func addBuildDependencies(services []string, project *types.Project) []string {
servicesWithDependencies := utils.NewSet(services...)
for _, service := range services {
b := project.Services[service].Build
s, ok := project.Services[service]
if !ok {
s = project.DisabledServices[service]
}
b := s.Build
if b != nil {
for _, target := range b.AdditionalContexts {
if s, found := strings.CutPrefix(target, types.ServicePrefix); found {
Expand Down
16 changes: 16 additions & 0 deletions pkg/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,19 @@ func TestBuildDependentImage(t *testing.T) {
out = res.Combined()
assert.Check(t, strings.Contains(out, "secondbuild Built"))
}

func TestBuildSubDependencies(t *testing.T) {
c := NewParallelCLI(t)

t.Cleanup(func() {
c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/sub-dependencies/compose.yaml", "down", "--rmi=local")
})

res := c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/sub-dependencies/compose.yaml", "build", "main")
out := res.Combined()
assert.Check(t, strings.Contains(out, "main Built"))

res = c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/sub-dependencies/compose.yaml", "up", "--build", "main")
out = res.Combined()
assert.Check(t, strings.Contains(out, "main Built"))
}
36 changes: 36 additions & 0 deletions pkg/e2e/fixtures/build-test/sub-dependencies/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
services:
main:
build:
dockerfile_inline: |
FROM alpine
additional_contexts:
dep1: service:dep1
dep2: service:dep2
entrypoint: ["echo", "Hello from main"]

dep1:
build:
dockerfile_inline: |
FROM alpine
additional_contexts:
subdep1: service:subdep1
subdep2: service:subdep2
entrypoint: ["echo", "Hello from dep1"]

dep2:
build:
dockerfile_inline: |
FROM alpine
entrypoint: ["echo", "Hello from dep2"]

subdep1:
build:
dockerfile_inline: |
FROM alpine
entrypoint: ["echo", "Hello from subdep1"]

subdep2:
build:
dockerfile_inline: |
FROM alpine
entrypoint: ["echo", "Hello from subdep2"]