Skip to content

Commit 20738c5

Browse files
committed
extending a service, dependencies must be excluded
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 4afb43c commit 20738c5

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

loader/extends.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import (
2727
"github.com/compose-spec/compose-go/v2/types"
2828
)
2929

30+
// as we use another service definition by `extends`, we must exclude attributes which creates dependency to another service
31+
// see https://github.com/compose-spec/compose-spec/blob/main/05-services.md#restrictions
32+
var exclusions = []string{"extends", "depends_on", "volumes_from"}
33+
3034
func ApplyExtends(ctx context.Context, dict map[string]any, opts *Options, tracker *cycleTracker, post ...PostProcessor) error {
3135
a, ok := dict["services"]
3236
if !ok {
@@ -123,7 +127,9 @@ func applyServiceExtends(ctx context.Context, name string, services map[string]a
123127
if err != nil {
124128
return nil, err
125129
}
126-
delete(merged, "extends")
130+
for _, exclusion := range exclusions {
131+
delete(merged, exclusion)
132+
}
127133
services[name] = merged
128134
return merged, nil
129135
}

loader/extends_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ services:
322322
file: ./testdata/extends/depends_on.yaml
323323
service: with_volumes_from
324324
`,
325-
wantErr: `service "bar" depends on undefined service "zot"`,
326325
},
327326
{
328327
name: "depends_on",
@@ -334,7 +333,6 @@ services:
334333
file: ./testdata/extends/depends_on.yaml
335334
service: with_depends_on
336335
`,
337-
wantErr: `service "bar" depends on undefined service "zot"`,
338336
},
339337
{
340338
name: "shared ipc",
@@ -369,8 +367,11 @@ services:
369367
Content: []byte(tt.yaml),
370368
}},
371369
})
370+
if tt.wantErr == "" {
371+
assert.NilError(t, err)
372+
return
373+
}
372374
assert.ErrorContains(t, err, tt.wantErr)
373-
374375
// Do the same but with a local `zot` service matching the imported reference
375376
_, err = LoadWithContext(context.Background(), types.ConfigDetails{
376377
ConfigFiles: []types.ConfigFile{{

0 commit comments

Comments
 (0)