fix support for additional_contexts with service sub-dependencies
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
0f9e6ab832
commit
1d34661e91
@ -628,7 +628,11 @@ func parsePlatforms(service types.ServiceConfig) ([]specs.Platform, error) {
|
|||||||
func addBuildDependencies(services []string, project *types.Project) []string {
|
func addBuildDependencies(services []string, project *types.Project) []string {
|
||||||
servicesWithDependencies := utils.NewSet(services...)
|
servicesWithDependencies := utils.NewSet(services...)
|
||||||
for _, service := range 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 {
|
if b != nil {
|
||||||
for _, target := range b.AdditionalContexts {
|
for _, target := range b.AdditionalContexts {
|
||||||
if s, found := strings.CutPrefix(target, types.ServicePrefix); found {
|
if s, found := strings.CutPrefix(target, types.ServicePrefix); found {
|
||||||
|
@ -564,3 +564,19 @@ func TestBuildDependentImage(t *testing.T) {
|
|||||||
out = res.Combined()
|
out = res.Combined()
|
||||||
assert.Check(t, strings.Contains(out, "secondbuild Built"))
|
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
pkg/e2e/fixtures/build-test/sub-dependencies/compose.yaml
Normal file
36
pkg/e2e/fixtures/build-test/sub-dependencies/compose.yaml
Normal file
@ -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"]
|
Loading…
x
Reference in New Issue
Block a user