@@ -29,21 +29,25 @@ import (
2929func Normalize (dict map [string ]any , env types.Mapping ) (map [string ]any , error ) {
3030 normalizeNetworks (dict )
3131
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 )
32+ for _ , key := range []string {"services" , "jobs" } {
33+ d , ok := dict [key ]
34+ if ! ok {
35+ continue
36+ }
37+ containers := d .(map [string ]any )
38+ for name , s := range containers {
39+ container := s .(map [string ]any )
3640
37- if service ["pull_policy" ] == types .PullPolicyIfNotPresent {
38- service ["pull_policy" ] = types .PullPolicyMissing
41+ if container ["pull_policy" ] == types .PullPolicyIfNotPresent {
42+ container ["pull_policy" ] = types .PullPolicyMissing
3943 }
4044
4145 fn := func (s string ) (string , bool ) {
4246 v , ok := env [s ]
4347 return v , ok
4448 }
4549
46- if b , ok := service ["build" ]; ok {
50+ if b , ok := container ["build" ]; ok {
4751 build := b .(map [string ]any )
4852 if build ["context" ] == nil {
4953 build ["context" ] = "."
@@ -56,20 +60,20 @@ func Normalize(dict map[string]any, env types.Mapping) (map[string]any, error) {
5660 build ["args" ], _ = resolve (a , fn , false )
5761 }
5862
59- service ["build" ] = build
63+ container ["build" ] = build
6064 }
6165
62- if e , ok := service ["environment" ]; ok {
63- service ["environment" ], _ = resolve (e , fn , true )
66+ if e , ok := container ["environment" ]; ok {
67+ container ["environment" ], _ = resolve (e , fn , true )
6468 }
6569
6670 var dependsOn map [string ]any
67- if d , ok := service ["depends_on" ]; ok {
71+ if d , ok := container ["depends_on" ]; ok {
6872 dependsOn = d .(map [string ]any )
6973 } else {
7074 dependsOn = map [string ]any {}
7175 }
72- if l , ok := service ["links" ]; ok {
76+ if l , ok := container ["links" ]; ok {
7377 links := l .([]any )
7478 for _ , e := range links {
7579 link := e .(string )
@@ -88,7 +92,7 @@ func Normalize(dict map[string]any, env types.Mapping) (map[string]any, error) {
8892 }
8993
9094 for _ , namespace := range []string {"network_mode" , "ipc" , "pid" , "uts" , "cgroup" } {
91- if n , ok := service [namespace ]; ok {
95+ if n , ok := container [namespace ]; ok {
9296 ref := n .(string )
9397 if strings .HasPrefix (ref , types .ServicePrefix ) {
9498 shared := ref [len (types .ServicePrefix ):]
@@ -103,18 +107,18 @@ func Normalize(dict map[string]any, env types.Mapping) (map[string]any, error) {
103107 }
104108 }
105109
106- if v , ok := service ["volumes" ]; ok {
110+ if v , ok := container ["volumes" ]; ok {
107111 volumes := v .([]any )
108112 for i , volume := range volumes {
109113 vol := volume .(map [string ]any )
110114 target := vol ["target" ].(string )
111115 vol ["target" ] = path .Clean (target )
112116 volumes [i ] = vol
113117 }
114- service ["volumes" ] = volumes
118+ container ["volumes" ] = volumes
115119 }
116120
117- if n , ok := service ["volumes_from" ]; ok {
121+ if n , ok := container ["volumes_from" ]; ok {
118122 volumesFrom := n .([]any )
119123 for _ , v := range volumesFrom {
120124 vol := v .(string )
@@ -131,12 +135,12 @@ func Normalize(dict map[string]any, env types.Mapping) (map[string]any, error) {
131135 }
132136 }
133137 if len (dependsOn ) > 0 {
134- service ["depends_on" ] = dependsOn
138+ container ["depends_on" ] = dependsOn
135139 }
136- services [name ] = service
140+ containers [name ] = container
137141 }
138142
139- dict ["services" ] = services
143+ dict [key ] = containers
140144 }
141145 setNameFromKey (dict )
142146
@@ -154,33 +158,37 @@ func normalizeNetworks(dict map[string]any) {
154158 // implicit `default` network must be introduced only if actually used by some service
155159 usesDefaultNetwork := false
156160
157- if s , ok := dict ["services" ]; ok {
158- services := s .(map [string ]any )
159- for name , se := range services {
160- service := se .(map [string ]any )
161- if _ , ok := service ["provider" ]; ok {
161+ for _ , key := range []string {"services" , "jobs" } {
162+ s , ok := dict [key ]
163+ if ! ok {
164+ continue
165+ }
166+ containers := s .(map [string ]any )
167+ for name , se := range containers {
168+ container := se .(map [string ]any )
169+ if _ , ok := container ["provider" ]; ok {
162170 continue
163171 }
164- if _ , ok := service ["network_mode" ]; ok {
172+ if _ , ok := container ["network_mode" ]; ok {
165173 continue
166174 }
167- if n , ok := service ["networks" ]; ! ok {
168- // If none explicitly declared, service is connected to default network
169- service ["networks" ] = map [string ]any {"default" : nil }
175+ if n , ok := container ["networks" ]; ! ok {
176+ // If none explicitly declared, container is connected to default network
177+ container ["networks" ] = map [string ]any {"default" : nil }
170178 usesDefaultNetwork = true
171179 } else {
172180 net := n .(map [string ]any )
173181 if len (net ) == 0 {
174182 // networks section declared but empty (corner case)
175- service ["networks" ] = map [string ]any {"default" : nil }
183+ container ["networks" ] = map [string ]any {"default" : nil }
176184 usesDefaultNetwork = true
177185 } else if _ , ok := net ["default" ]; ok {
178186 usesDefaultNetwork = true
179187 }
180188 }
181- services [name ] = service
189+ containers [name ] = container
182190 }
183- dict ["services" ] = services
191+ dict [key ] = containers
184192 }
185193
186194 if _ , ok := networks ["default" ]; ! ok && usesDefaultNetwork {
0 commit comments