Skip to content

Commit

Permalink
exlusions apply to source, not merged result
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof authored and glours committed Dec 19, 2024
1 parent 20738c5 commit e3dffbf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
10 changes: 6 additions & 4 deletions loader/extends.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
}
Expand Down
23 changes: 23 additions & 0 deletions loader/extends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e3dffbf

Please sign in to comment.