bump compose-go to v2.1.4

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours
2024-07-17 16:57:39 +02:00
parent 3005743f7c
commit ca452c47d8
18 changed files with 625 additions and 220 deletions

View File

@ -52,14 +52,14 @@ func Normalize(dict map[string]any, env types.Mapping) (map[string]any, error) {
}
if a, ok := build["args"]; ok {
build["args"], _ = resolve(a, fn)
build["args"], _ = resolve(a, fn, false)
}
service["build"] = build
}
if e, ok := service["environment"]; ok {
service["environment"], _ = resolve(e, fn)
service["environment"], _ = resolve(e, fn, true)
}
var dependsOn map[string]any
@ -178,12 +178,12 @@ func normalizeNetworks(dict map[string]any) {
}
}
func resolve(a any, fn func(s string) (string, bool)) (any, bool) {
func resolve(a any, fn func(s string) (string, bool), keepEmpty bool) (any, bool) {
switch v := a.(type) {
case []any:
var resolved []any
for _, val := range v {
if r, ok := resolve(val, fn); ok {
if r, ok := resolve(val, fn, keepEmpty); ok {
resolved = append(resolved, r)
}
}
@ -197,6 +197,8 @@ func resolve(a any, fn func(s string) (string, bool)) (any, bool) {
}
if s, ok := fn(key); ok {
resolved[key] = s
} else if keepEmpty {
resolved[key] = nil
}
}
return resolved, true
@ -205,6 +207,9 @@ func resolve(a any, fn func(s string) (string, bool)) (any, bool) {
if val, ok := fn(v); ok {
return fmt.Sprintf("%s=%s", v, val), true
}
if keepEmpty {
return v, true
}
return "", false
}
return v, true