-
Notifications
You must be signed in to change notification settings - Fork 131
Fix models support with compose include #824
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ type merger func(any, any, tree.Path) (any, error) | |
var mergeSpecials = map[tree.Path]merger{} | ||
|
||
func init() { | ||
mergeSpecials["models.*.runtime_flags"] = override | ||
mergeSpecials["networks.*.ipam.config"] = mergeIPAMConfig | ||
mergeSpecials["networks.*.labels"] = mergeToSequence | ||
mergeSpecials["volumes.*.labels"] = mergeToSequence | ||
|
@@ -160,11 +161,53 @@ func mergeDependsOn(c any, o any, path tree.Path) (any, error) { | |
} | ||
|
||
func mergeModels(c any, o any, path tree.Path) (any, error) { | ||
// Check if both sides are string arrays for short syntax only | ||
if rightArr, ok := c.([]any); ok { | ||
if leftArr, ok := o.([]any); ok { | ||
if isStringArray(rightArr) && isStringArray(leftArr) { | ||
return mergeStringArrays(rightArr, leftArr), nil | ||
} | ||
} | ||
} | ||
|
||
// Otherwise, use map merge for long syntax or mixed syntax | ||
Comment on lines
+164
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should not be necessary, as next lines merge equivalent mapping syntax There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean to remove the comment only? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, I mean this all block. Mutating into mapping format then merge is the right way, and should not require any extra processing - we do the same for the many other comparable structs |
||
right := convertIntoMapping(c, nil) | ||
left := convertIntoMapping(o, nil) | ||
return mergeMappings(right, left, path) | ||
} | ||
|
||
func isStringArray(arr []any) bool { | ||
for _, item := range arr { | ||
if _, ok := item.(string); !ok { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func mergeStringArrays(right, left []any) []any { | ||
seen := make(map[string]bool) | ||
var result []any | ||
|
||
for _, item := range right { | ||
str := item.(string) | ||
if !seen[str] { | ||
result = append(result, str) | ||
seen[str] = true | ||
} | ||
} | ||
|
||
for _, item := range left { | ||
str := item.(string) | ||
if !seen[str] { | ||
result = append(result, str) | ||
seen[str] = true | ||
} | ||
} | ||
|
||
return result | ||
} | ||
|
||
func mergeNetworks(c any, o any, path tree.Path) (any, error) { | ||
right := convertIntoMapping(c, nil) | ||
left := convertIntoMapping(o, nil) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires an update on the compose-spec documentation to make it clear runtime_flags won't be appended
see https://github.com/compose-spec/compose-spec/blob/main/13-merge.md#exceptions