diff --git a/loader/extends.go b/loader/extends.go index 2a127d2c..61051733 100644 --- a/loader/extends.go +++ b/loader/extends.go @@ -29,7 +29,7 @@ import ( // as we use another service definition by `extends`, we must exclude attributes which creates dependency to another service // see https://github.com/compose-spec/compose-spec/blob/main/05-services.md#restrictions -var exclusions = []string{"extends", "depends_on", "volumes_from"} +var exclusions = []string{"depends_on", "volumes_from"} func ApplyExtends(ctx context.Context, dict map[string]any, opts *Options, tracker *cycleTracker, post ...PostProcessor) error { a, ok := dict["services"] @@ -123,13 +123,15 @@ func applyServiceExtends(ctx context.Context, name string, services map[string]a }, }) } + for _, exclusion := range exclusions { + delete(source, exclusion) + } merged, err := override.ExtendService(source, service) if err != nil { return nil, err } - for _, exclusion := range exclusions { - delete(merged, exclusion) - } + + delete(merged, "extends") services[name] = merged return merged, nil } diff --git a/loader/extends_test.go b/loader/extends_test.go index 3a14c545..22d90749 100644 --- a/loader/extends_test.go +++ b/loader/extends_test.go @@ -386,6 +386,29 @@ services: } } +func TestLoadExtendsDependsOn(t *testing.T) { + yaml := ` +name: extends-depends_on +services: + service_a: + image: a + depends_on: + - service_c + + service_b: + extends: service_a + depends_on: + - service_a + + service_c: + image: c` + p, err := loadYAML(yaml) + assert.NilError(t, err) + assert.DeepEqual(t, p.Services["service_b"].DependsOn, types.DependsOnConfig{ + "service_a": types.ServiceDependency{Condition: types.ServiceConditionStarted, Required: true}, + }) +} + func TestLoadExtendsListener(t *testing.T) { yaml := ` name: listener-extends