Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extending a service, dependencies must be excluded #718

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion loader/extends.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import (
"github.com/compose-spec/compose-go/v2/types"
)

// 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"}
ndeloof marked this conversation as resolved.
Show resolved Hide resolved

func ApplyExtends(ctx context.Context, dict map[string]any, opts *Options, tracker *cycleTracker, post ...PostProcessor) error {
a, ok := dict["services"]
if !ok {
Expand Down Expand Up @@ -123,7 +127,9 @@ func applyServiceExtends(ctx context.Context, name string, services map[string]a
if err != nil {
return nil, err
}
delete(merged, "extends")
for _, exclusion := range exclusions {
delete(merged, exclusion)
}
services[name] = merged
return merged, nil
}
Expand Down
7 changes: 4 additions & 3 deletions loader/extends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ services:
file: ./testdata/extends/depends_on.yaml
service: with_volumes_from
`,
wantErr: `service "bar" depends on undefined service "zot"`,
},
{
name: "depends_on",
Expand All @@ -334,7 +333,6 @@ services:
file: ./testdata/extends/depends_on.yaml
service: with_depends_on
`,
wantErr: `service "bar" depends on undefined service "zot"`,
},
{
name: "shared ipc",
Expand Down Expand Up @@ -369,8 +367,11 @@ services:
Content: []byte(tt.yaml),
}},
})
if tt.wantErr == "" {
assert.NilError(t, err)
return
}
assert.ErrorContains(t, err, tt.wantErr)

// Do the same but with a local `zot` service matching the imported reference
_, err = LoadWithContext(context.Background(), types.ConfigDetails{
ConfigFiles: []types.ConfigFile{{
Expand Down
Loading