mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-12 14:37:08 +08:00
bumpo compose-go to v2.1.0
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
47
vendor/github.com/compose-spec/compose-go/v2/loader/normalize.go
generated
vendored
47
vendor/github.com/compose-spec/compose-go/v2/loader/normalize.go
generated
vendored
@ -26,18 +26,12 @@ import (
|
||||
|
||||
// Normalize compose project by moving deprecated attributes to their canonical position and injecting implicit defaults
|
||||
func Normalize(dict map[string]any, env types.Mapping) (map[string]any, error) {
|
||||
dict["networks"] = normalizeNetworks(dict)
|
||||
normalizeNetworks(dict)
|
||||
|
||||
if d, ok := dict["services"]; ok {
|
||||
services := d.(map[string]any)
|
||||
for name, s := range services {
|
||||
service := s.(map[string]any)
|
||||
_, hasNetworks := service["networks"]
|
||||
_, hasNetworkMode := service["network_mode"]
|
||||
if !hasNetworks && !hasNetworkMode {
|
||||
// Service without explicit network attachment are implicitly exposed on default network
|
||||
service["networks"] = map[string]any{"default": nil}
|
||||
}
|
||||
|
||||
if service["pull_policy"] == types.PullPolicyIfNotPresent {
|
||||
service["pull_policy"] = types.PullPolicyMissing
|
||||
@ -137,18 +131,51 @@ func Normalize(dict map[string]any, env types.Mapping) (map[string]any, error) {
|
||||
return dict, nil
|
||||
}
|
||||
|
||||
func normalizeNetworks(dict map[string]any) map[string]any {
|
||||
func normalizeNetworks(dict map[string]any) {
|
||||
var networks map[string]any
|
||||
if n, ok := dict["networks"]; ok {
|
||||
networks = n.(map[string]any)
|
||||
} else {
|
||||
networks = map[string]any{}
|
||||
}
|
||||
if _, ok := networks["default"]; !ok {
|
||||
|
||||
// implicit `default` network must be introduced only if actually used by some service
|
||||
usesDefaultNetwork := false
|
||||
|
||||
if s, ok := dict["services"]; ok {
|
||||
services := s.(map[string]any)
|
||||
for name, se := range services {
|
||||
service := se.(map[string]any)
|
||||
if _, ok := service["network_mode"]; ok {
|
||||
continue
|
||||
}
|
||||
if n, ok := service["networks"]; !ok {
|
||||
// If none explicitly declared, service is connected to default network
|
||||
service["networks"] = map[string]any{"default": nil}
|
||||
usesDefaultNetwork = true
|
||||
} else {
|
||||
net := n.(map[string]any)
|
||||
if len(net) == 0 {
|
||||
// networks section declared but empty (corner case)
|
||||
service["networks"] = map[string]any{"default": nil}
|
||||
usesDefaultNetwork = true
|
||||
} else if _, ok := net["default"]; ok {
|
||||
usesDefaultNetwork = true
|
||||
}
|
||||
}
|
||||
services[name] = service
|
||||
}
|
||||
dict["services"] = services
|
||||
}
|
||||
|
||||
if _, ok := networks["default"]; !ok && usesDefaultNetwork {
|
||||
// If not declared explicitly, Compose model involves an implicit "default" network
|
||||
networks["default"] = nil
|
||||
}
|
||||
return networks
|
||||
|
||||
if len(networks) > 0 {
|
||||
dict["networks"] = networks
|
||||
}
|
||||
}
|
||||
|
||||
func resolve(a any, fn func(s string) (string, bool)) (any, bool) {
|
||||
|
Reference in New Issue
Block a user