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

enforce unicity after canonical transformation #565

Merged
merged 1 commit into from
Feb 6, 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
32 changes: 32 additions & 0 deletions loader/extends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,35 @@ services:
})
assert.NilError(t, err)
}

func TestExtendsPortOverride(t *testing.T) {
yaml := `
name: test-extends-port
services:
test:
extends:
file: testdata/extends/ports.yaml
service: test
`
abs, err := filepath.Abs(".")
assert.NilError(t, err)

p, err := LoadWithContext(context.Background(), types.ConfigDetails{
ConfigFiles: []types.ConfigFile{
{
Filename: "testdata/extends/ports.yaml",
},
{
Content: []byte(yaml),
Filename: "(override)",
},
},
WorkingDir: abs,
}, func(options *Options) {
options.ResolvePaths = false
options.SkipValidation = true
})
assert.NilError(t, err)
assert.Equal(t, len(p.Services["test"].Ports), 1)

}
6 changes: 6 additions & 0 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ func loadYamlModel(ctx context.Context, config types.ConfigDetails, opts *Option
return nil, err
}

// Canonical transformation can reveal duplicates, typically as ports can be a range and conflict with an override
dict, err = override.EnforceUnicity(dict)
if err != nil {
return nil, err
}

if !opts.SkipInclude {
included = append(included, config.ConfigFiles[0].Filename)
err = ApplyInclude(ctx, config, dict, opts, included)
Expand Down
5 changes: 5 additions & 0 deletions loader/testdata/extends/ports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
test:
image: test
ports:
- 8080:8080
Loading