Normalize compose project by moving deprecated attributes to their canonical position and injecting implicit defaults
(dict map[string]any, env types.Mapping)
| 27 | |
| 28 | // Normalize compose project by moving deprecated attributes to their canonical position and injecting implicit defaults |
| 29 | func Normalize(dict map[string]any, env types.Mapping) (map[string]any, error) { |
| 30 | normalizeNetworks(dict) |
| 31 | |
| 32 | if d, ok := dict["services"]; ok { |
| 33 | services := d.(map[string]any) |
| 34 | for name, s := range services { |
| 35 | service := s.(map[string]any) |
| 36 | |
| 37 | if service["pull_policy"] == types.PullPolicyIfNotPresent { |
| 38 | service["pull_policy"] = types.PullPolicyMissing |
| 39 | } |
| 40 | |
| 41 | fn := func(s string) (string, bool) { |
| 42 | v, ok := env[s] |
| 43 | return v, ok |
| 44 | } |
| 45 | |
| 46 | if b, ok := service["build"]; ok { |
| 47 | build := b.(map[string]any) |
| 48 | if build["context"] == nil { |
| 49 | build["context"] = "." |
| 50 | } |
| 51 | if build["dockerfile"] == nil && build["dockerfile_inline"] == nil { |
| 52 | build["dockerfile"] = "Dockerfile" |
| 53 | } |
| 54 | |
| 55 | if a, ok := build["args"]; ok { |
| 56 | build["args"], _ = resolve(a, fn, false) |
| 57 | } |
| 58 | |
| 59 | service["build"] = build |
| 60 | } |
| 61 | |
| 62 | if e, ok := service["environment"]; ok { |
| 63 | service["environment"], _ = resolve(e, fn, true) |
| 64 | } |
| 65 | |
| 66 | var dependsOn map[string]any |
| 67 | if d, ok := service["depends_on"]; ok { |
| 68 | dependsOn = d.(map[string]any) |
| 69 | } else { |
| 70 | dependsOn = map[string]any{} |
| 71 | } |
| 72 | if l, ok := service["links"]; ok { |
| 73 | links := l.([]any) |
| 74 | for _, e := range links { |
| 75 | link := e.(string) |
| 76 | parts := strings.Split(link, ":") |
| 77 | if len(parts) == 2 { |
| 78 | link = parts[0] |
| 79 | } |
| 80 | if _, ok := dependsOn[link]; !ok { |
| 81 | dependsOn[link] = map[string]any{ |
| 82 | "condition": types.ServiceConditionStarted, |
| 83 | "restart": true, |
| 84 | "required": true, |
| 85 | } |
| 86 | } |
searching dependent graphs…