Skip to content
Open
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
19 changes: 17 additions & 2 deletions cli/compose/loader/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,21 @@ func toServicePortConfigsMap(s any) (map[any]any, error) {
}
m := map[any]any{}
for _, p := range ports {
m[p.Published] = p
// Key by published port + protocol so TCP and UDP on the same host
// port (e.g. 443/tcp and 443/udp) do not collapse when merging files.
m[servicePortMergeKey(p)] = p
}
return m, nil
}

func servicePortMergeKey(p types.ServicePortConfig) string {
proto := p.Protocol
if proto == "" {
proto = "tcp"
}
return fmt.Sprintf("%d/%s", p.Published, proto)
}

func toServiceVolumeConfigsMap(s any) (map[any]any, error) {
volumes, ok := s.([]types.ServiceVolumeConfig)
if !ok {
Expand Down Expand Up @@ -172,7 +182,12 @@ func toServicePortConfigsSlice(dst reflect.Value, m map[any]any) error {
for _, v := range m {
s = append(s, v.(types.ServicePortConfig))
}
sort.Slice(s, func(i, j int) bool { return s[i].Published < s[j].Published })
sort.Slice(s, func(i, j int) bool {
if s[i].Published != s[j].Published {
return s[i].Published < s[j].Published
}
return s[i].Protocol < s[j].Protocol
})
dst.Set(reflect.ValueOf(s))
return nil
}
Expand Down
24 changes: 24 additions & 0 deletions cli/compose/loader/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,30 @@ func TestLoadMultipleServicePorts(t *testing.T) {
},
},
},
{
name: "same_published_tcp_and_udp",
portBase: map[string]any{
"ports": []any{
"443:443",
"443:443/udp",
},
},
portOverride: map[string]any{},
expected: []types.ServicePortConfig{
{
Mode: "ingress",
Published: 443,
Target: 443,
Protocol: "tcp",
},
{
Mode: "ingress",
Published: 443,
Target: 443,
Protocol: "udp",
},
},
},
}

for _, tc := range portsCases {
Expand Down