Skip to content

Commit 93ec08a

Browse files
committed
extract ContainerSpec from ServiceConfig
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 433649b commit 93ec08a

15 files changed

Lines changed: 541 additions & 373 deletions

graph/graph_test.go

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import (
3131

3232
func TestTraversalWithMultipleParents(t *testing.T) {
3333
dependent := types.ServiceConfig{
34-
Name: "dependent",
35-
DependsOn: make(types.DependsOnConfig),
34+
Name: "dependent",
35+
ContainerSpec: types.ContainerSpec{
36+
DependsOn: make(types.DependsOnConfig),
37+
},
3638
}
3739

3840
project := types.Project{
@@ -119,8 +121,10 @@ func TestBuildGraph(t *testing.T) {
119121
desc: "builds graph with single service",
120122
services: types.Services{
121123
"test": {
122-
Name: "test",
123-
DependsOn: types.DependsOnConfig{},
124+
Name: "test",
125+
ContainerSpec: types.ContainerSpec{
126+
DependsOn: types.DependsOnConfig{},
127+
},
124128
},
125129
},
126130
expectedVertices: map[string]*vertex[types.ServiceConfig]{
@@ -136,12 +140,16 @@ func TestBuildGraph(t *testing.T) {
136140
desc: "builds graph with two separate services",
137141
services: types.Services{
138142
"test": {
139-
Name: "test",
140-
DependsOn: types.DependsOnConfig{},
143+
Name: "test",
144+
ContainerSpec: types.ContainerSpec{
145+
DependsOn: types.DependsOnConfig{},
146+
},
141147
},
142148
"another": {
143-
Name: "another",
144-
DependsOn: types.DependsOnConfig{},
149+
Name: "another",
150+
ContainerSpec: types.ContainerSpec{
151+
DependsOn: types.DependsOnConfig{},
152+
},
145153
},
146154
},
147155
expectedVertices: map[string]*vertex[types.ServiceConfig]{
@@ -164,13 +172,17 @@ func TestBuildGraph(t *testing.T) {
164172
services: types.Services{
165173
"test": {
166174
Name: "test",
167-
DependsOn: types.DependsOnConfig{
168-
"another": types.ServiceDependency{},
175+
ContainerSpec: types.ContainerSpec{
176+
DependsOn: types.DependsOnConfig{
177+
"another": types.ServiceDependency{},
178+
},
169179
},
170180
},
171181
"another": {
172-
Name: "another",
173-
DependsOn: types.DependsOnConfig{},
182+
Name: "another",
183+
ContainerSpec: types.ContainerSpec{
184+
DependsOn: types.DependsOnConfig{},
185+
},
174186
},
175187
},
176188
expectedVertices: map[string]*vertex[types.ServiceConfig]{
@@ -197,9 +209,11 @@ func TestBuildGraph(t *testing.T) {
197209
services: types.Services{
198210
"test": {
199211
Name: "test",
200-
DependsOn: types.DependsOnConfig{
201-
"another": types.ServiceDependency{
202-
Required: false,
212+
ContainerSpec: types.ContainerSpec{
213+
DependsOn: types.DependsOnConfig{
214+
"another": types.ServiceDependency{
215+
Required: false,
216+
},
203217
},
204218
},
205219
},
@@ -218,9 +232,11 @@ func TestBuildGraph(t *testing.T) {
218232
services: types.Services{
219233
"test": {
220234
Name: "test",
221-
DependsOn: types.DependsOnConfig{
222-
"another": types.ServiceDependency{
223-
Required: true,
235+
ContainerSpec: types.ContainerSpec{
236+
DependsOn: types.DependsOnConfig{
237+
"another": types.ServiceDependency{
238+
Required: true,
239+
},
224240
},
225241
},
226242
},
@@ -232,18 +248,22 @@ func TestBuildGraph(t *testing.T) {
232248
services: types.Services{
233249
"test": {
234250
Name: "test",
235-
DependsOn: types.DependsOnConfig{
236-
"another": types.ServiceDependency{
237-
Required: true,
251+
ContainerSpec: types.ContainerSpec{
252+
DependsOn: types.DependsOnConfig{
253+
"another": types.ServiceDependency{
254+
Required: true,
255+
},
238256
},
239257
},
240258
},
241259
},
242260
disabled: types.Services{
243261
"another": {
244-
Name: "another",
245-
Profiles: []string{"test"},
246-
DependsOn: types.DependsOnConfig{},
262+
Name: "another",
263+
Profiles: []string{"test"},
264+
ContainerSpec: types.ContainerSpec{
265+
DependsOn: types.DependsOnConfig{},
266+
},
247267
},
248268
},
249269
expectedError: `service "another" is required by "test" but is disabled. Can be enabled by profiles [test]`,
@@ -253,19 +273,25 @@ func TestBuildGraph(t *testing.T) {
253273
services: types.Services{
254274
"test": {
255275
Name: "test",
256-
DependsOn: types.DependsOnConfig{
257-
"another": types.ServiceDependency{},
276+
ContainerSpec: types.ContainerSpec{
277+
DependsOn: types.DependsOnConfig{
278+
"another": types.ServiceDependency{},
279+
},
258280
},
259281
},
260282
"another": {
261283
Name: "another",
262-
DependsOn: types.DependsOnConfig{
263-
"another_dep": types.ServiceDependency{},
284+
ContainerSpec: types.ContainerSpec{
285+
DependsOn: types.DependsOnConfig{
286+
"another_dep": types.ServiceDependency{},
287+
},
264288
},
265289
},
266290
"another_dep": {
267-
Name: "another_dep",
268-
DependsOn: types.DependsOnConfig{},
291+
Name: "another_dep",
292+
ContainerSpec: types.ContainerSpec{
293+
DependsOn: types.DependsOnConfig{},
294+
},
269295
},
270296
},
271297
expectedVertices: map[string]*vertex[types.ServiceConfig]{
@@ -435,14 +461,18 @@ func exampleProject() *types.Project {
435461
Services: types.Services{
436462
"test1": {
437463
Name: "test1",
438-
DependsOn: map[string]types.ServiceDependency{
439-
"test2": {},
464+
ContainerSpec: types.ContainerSpec{
465+
DependsOn: map[string]types.ServiceDependency{
466+
"test2": {},
467+
},
440468
},
441469
},
442470
"test2": {
443471
Name: "test2",
444-
DependsOn: map[string]types.ServiceDependency{
445-
"test3": {},
472+
ContainerSpec: types.ContainerSpec{
473+
DependsOn: map[string]types.ServiceDependency{
474+
"test3": {},
475+
},
446476
},
447477
},
448478
"test3": {

loader/include_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ services:
9090
})
9191
assert.NilError(t, err)
9292
assert.DeepEqual(t, p.Services["bar"], types.ServiceConfig{
93-
Name: "bar",
94-
Image: "busybox",
95-
Environment: types.MappingWithEquals{
96-
"ZOT": strPtr("QIX"),
93+
Name: "bar",
94+
ContainerSpec: types.ContainerSpec{
95+
Image: "busybox",
96+
Environment: types.MappingWithEquals{
97+
"ZOT": strPtr("QIX"),
98+
},
9799
},
98100
})
99101
}

loader/loader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ func Transform(source interface{}, target interface{}) error {
777777
),
778778
Result: target,
779779
TagName: "yaml",
780+
Squash: true,
780781
Metadata: &data,
781782
}
782783
decoder, err := mapstructure.NewDecoder(config)

0 commit comments

Comments
 (0)