Skip to content

Commit e3dffbf

Browse files
ndeloofglours
authored andcommitted
exlusions apply to source, not merged result
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 20738c5 commit e3dffbf

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

loader/extends.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// as we use another service definition by `extends`, we must exclude attributes which creates dependency to another service
3131
// see https://github.com/compose-spec/compose-spec/blob/main/05-services.md#restrictions
32-
var exclusions = []string{"extends", "depends_on", "volumes_from"}
32+
var exclusions = []string{"depends_on", "volumes_from"}
3333

3434
func ApplyExtends(ctx context.Context, dict map[string]any, opts *Options, tracker *cycleTracker, post ...PostProcessor) error {
3535
a, ok := dict["services"]
@@ -123,13 +123,15 @@ func applyServiceExtends(ctx context.Context, name string, services map[string]a
123123
},
124124
})
125125
}
126+
for _, exclusion := range exclusions {
127+
delete(source, exclusion)
128+
}
126129
merged, err := override.ExtendService(source, service)
127130
if err != nil {
128131
return nil, err
129132
}
130-
for _, exclusion := range exclusions {
131-
delete(merged, exclusion)
132-
}
133+
134+
delete(merged, "extends")
133135
services[name] = merged
134136
return merged, nil
135137
}

loader/extends_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,29 @@ services:
386386
}
387387
}
388388

389+
func TestLoadExtendsDependsOn(t *testing.T) {
390+
yaml := `
391+
name: extends-depends_on
392+
services:
393+
service_a:
394+
image: a
395+
depends_on:
396+
- service_c
397+
398+
service_b:
399+
extends: service_a
400+
depends_on:
401+
- service_a
402+
403+
service_c:
404+
image: c`
405+
p, err := loadYAML(yaml)
406+
assert.NilError(t, err)
407+
assert.DeepEqual(t, p.Services["service_b"].DependsOn, types.DependsOnConfig{
408+
"service_a": types.ServiceDependency{Condition: types.ServiceConditionStarted, Required: true},
409+
})
410+
}
411+
389412
func TestLoadExtendsListener(t *testing.T) {
390413
yaml := `
391414
name: listener-extends

0 commit comments

Comments
 (0)