Skip to content

Commit a6c8406

Browse files
authored
chore(manifest): make port to be optional for backend svc (#2884)
<!-- Provide summary of changes --> <!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" --> By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
1 parent 6e6eaa3 commit a6c8406

File tree

6 files changed

+86
-55
lines changed

6 files changed

+86
-55
lines changed

internal/pkg/manifest/backend_svc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type BackendService struct {
2525

2626
// BackendServiceConfig holds the configuration that can be overridden per environments.
2727
type BackendServiceConfig struct {
28-
ImageConfig ImageWithPortAndHealthcheck `yaml:"image,flow"`
28+
ImageConfig ImageWithHealthcheckAndOptionalPort `yaml:"image,flow"`
2929
ImageOverride `yaml:",inline"`
3030
TaskConfig `yaml:",inline"`
3131
Logging `yaml:"logging,flow"`
@@ -128,7 +128,7 @@ func newDefaultBackendService() *BackendService {
128128
Type: aws.String(BackendServiceType),
129129
},
130130
BackendServiceConfig: BackendServiceConfig{
131-
ImageConfig: ImageWithPortAndHealthcheck{},
131+
ImageConfig: ImageWithHealthcheckAndOptionalPort{},
132132
TaskConfig: TaskConfig{
133133
CPU: aws.Int(256),
134134
Memory: aws.Int(512),

internal/pkg/manifest/backend_svc_test.go

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func TestNewBackendSvc(t *testing.T) {
3333
Type: aws.String(BackendServiceType),
3434
},
3535
BackendServiceConfig: BackendServiceConfig{
36-
ImageConfig: ImageWithPortAndHealthcheck{
37-
ImageWithPort: ImageWithPort{
36+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
37+
ImageWithOptionalPort: ImageWithOptionalPort{
3838
Image: Image{
3939
Build: BuildArgsOrString{
4040
BuildArgs: DockerBuildArgs{
@@ -79,8 +79,8 @@ func TestNewBackendSvc(t *testing.T) {
7979
Type: aws.String(BackendServiceType),
8080
},
8181
BackendServiceConfig: BackendServiceConfig{
82-
ImageConfig: ImageWithPortAndHealthcheck{
83-
ImageWithPort: ImageWithPort{
82+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
83+
ImageWithOptionalPort: ImageWithOptionalPort{
8484
Image: Image{
8585
Location: aws.String("mockImage"),
8686
},
@@ -190,8 +190,8 @@ func TestBackendService_Port(t *testing.T) {
190190
"returns the port value and sets ok to true if a port is exposed": {
191191
mft: &BackendService{
192192
BackendServiceConfig: BackendServiceConfig{
193-
ImageConfig: ImageWithPortAndHealthcheck{
194-
ImageWithPort: ImageWithPort{
193+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
194+
ImageWithOptionalPort: ImageWithOptionalPort{
195195
Port: uint16P(80),
196196
},
197197
},
@@ -262,8 +262,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
262262
Type: aws.String(BackendServiceType),
263263
},
264264
BackendServiceConfig: BackendServiceConfig{
265-
ImageConfig: ImageWithPortAndHealthcheck{
266-
ImageWithPort: ImageWithPort{
265+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
266+
ImageWithOptionalPort: ImageWithOptionalPort{
267267
Image: Image{
268268
Build: BuildArgsOrString{
269269
BuildArgs: DockerBuildArgs{
@@ -292,8 +292,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
292292
}
293293
mockBackendServiceWithNilEnvironment := BackendService{
294294
BackendServiceConfig: BackendServiceConfig{
295-
ImageConfig: ImageWithPortAndHealthcheck{
296-
ImageWithPort: ImageWithPort{
295+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
296+
ImageWithOptionalPort: ImageWithOptionalPort{
297297
Port: aws.Uint16(80),
298298
},
299299
},
@@ -304,16 +304,16 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
304304
}
305305
mockBackendServiceWithMinimalOverride := BackendService{
306306
BackendServiceConfig: BackendServiceConfig{
307-
ImageConfig: ImageWithPortAndHealthcheck{
308-
ImageWithPort: ImageWithPort{
307+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
308+
ImageWithOptionalPort: ImageWithOptionalPort{
309309
Port: aws.Uint16(80),
310310
},
311311
},
312312
},
313313
Environments: map[string]*BackendServiceConfig{
314314
"test": {
315-
ImageConfig: ImageWithPortAndHealthcheck{
316-
ImageWithPort: ImageWithPort{
315+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
316+
ImageWithOptionalPort: ImageWithOptionalPort{
317317
Port: aws.Uint16(5000),
318318
},
319319
},
@@ -322,8 +322,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
322322
}
323323
mockBackendServiceWithAllOverride := BackendService{
324324
BackendServiceConfig: BackendServiceConfig{
325-
ImageConfig: ImageWithPortAndHealthcheck{
326-
ImageWithPort: ImageWithPort{
325+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
326+
ImageWithOptionalPort: ImageWithOptionalPort{
327327
Port: aws.Uint16(80),
328328
Image: Image{
329329
DockerLabels: map[string]string{
@@ -355,8 +355,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
355355
},
356356
Environments: map[string]*BackendServiceConfig{
357357
"test": {
358-
ImageConfig: ImageWithPortAndHealthcheck{
359-
ImageWithPort: ImageWithPort{
358+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
359+
ImageWithOptionalPort: ImageWithOptionalPort{
360360
Image: Image{
361361
DockerLabels: map[string]string{
362362
"com.amazonaws.ecs.copilot.description": "Overridden!",
@@ -395,8 +395,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
395395
Type: aws.String(BackendServiceType),
396396
},
397397
BackendServiceConfig: BackendServiceConfig{
398-
ImageConfig: ImageWithPortAndHealthcheck{
399-
ImageWithPort: ImageWithPort{
398+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
399+
ImageWithOptionalPort: ImageWithOptionalPort{
400400
Image: Image{
401401
Build: BuildArgsOrString{
402402
BuildArgs: DockerBuildArgs{
@@ -409,8 +409,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
409409
},
410410
Environments: map[string]*BackendServiceConfig{
411411
"prod-iad": {
412-
ImageConfig: ImageWithPortAndHealthcheck{
413-
ImageWithPort: ImageWithPort{
412+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
413+
ImageWithOptionalPort: ImageWithOptionalPort{
414414
Image: Image{
415415
Location: aws.String("env-override location"),
416416
},
@@ -425,8 +425,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
425425
Type: aws.String(BackendServiceType),
426426
},
427427
BackendServiceConfig: BackendServiceConfig{
428-
ImageConfig: ImageWithPortAndHealthcheck{
429-
ImageWithPort: ImageWithPort{
428+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
429+
ImageWithOptionalPort: ImageWithOptionalPort{
430430
Image: Image{
431431
Location: aws.String("original location"),
432432
},
@@ -435,8 +435,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
435435
},
436436
Environments: map[string]*BackendServiceConfig{
437437
"prod-iad": {
438-
ImageConfig: ImageWithPortAndHealthcheck{
439-
ImageWithPort: ImageWithPort{
438+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
439+
ImageWithOptionalPort: ImageWithOptionalPort{
440440
Image: Image{
441441
Location: aws.String("env-override location"),
442442
},
@@ -451,8 +451,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
451451
Type: aws.String(BackendServiceType),
452452
},
453453
BackendServiceConfig: BackendServiceConfig{
454-
ImageConfig: ImageWithPortAndHealthcheck{
455-
ImageWithPort: ImageWithPort{
454+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
455+
ImageWithOptionalPort: ImageWithOptionalPort{
456456
Image: Image{
457457
Build: BuildArgsOrString{
458458
BuildArgs: DockerBuildArgs{
@@ -466,8 +466,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
466466
},
467467
Environments: map[string]*BackendServiceConfig{
468468
"prod-iad": {
469-
ImageConfig: ImageWithPortAndHealthcheck{
470-
ImageWithPort: ImageWithPort{
469+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
470+
ImageWithOptionalPort: ImageWithOptionalPort{
471471
Image: Image{
472472
Build: BuildArgsOrString{
473473
BuildString: aws.String("env overridden dockerfile"),
@@ -484,8 +484,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
484484
Type: aws.String(BackendServiceType),
485485
},
486486
BackendServiceConfig: BackendServiceConfig{
487-
ImageConfig: ImageWithPortAndHealthcheck{
488-
ImageWithPort: ImageWithPort{
487+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
488+
ImageWithOptionalPort: ImageWithOptionalPort{
489489
Image: Image{
490490
Location: aws.String("original location"),
491491
},
@@ -494,8 +494,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
494494
},
495495
Environments: map[string]*BackendServiceConfig{
496496
"prod-iad": {
497-
ImageConfig: ImageWithPortAndHealthcheck{
498-
ImageWithPort: ImageWithPort{
497+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
498+
ImageWithOptionalPort: ImageWithOptionalPort{
499499
Image: Image{
500500
Build: BuildArgsOrString{
501501
BuildString: aws.String("env overridden dockerfile"),
@@ -533,8 +533,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
533533

534534
wanted: &BackendService{
535535
BackendServiceConfig: BackendServiceConfig{
536-
ImageConfig: ImageWithPortAndHealthcheck{
537-
ImageWithPort: ImageWithPort{
536+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
537+
ImageWithOptionalPort: ImageWithOptionalPort{
538538
Port: aws.Uint16(5000),
539539
},
540540
},
@@ -548,8 +548,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
548548

549549
wanted: &BackendService{
550550
BackendServiceConfig: BackendServiceConfig{
551-
ImageConfig: ImageWithPortAndHealthcheck{
552-
ImageWithPort: ImageWithPort{
551+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
552+
ImageWithOptionalPort: ImageWithOptionalPort{
553553
Port: aws.Uint16(80),
554554
Image: Image{
555555
DockerLabels: map[string]string{
@@ -598,8 +598,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
598598
Type: aws.String(BackendServiceType),
599599
},
600600
BackendServiceConfig: BackendServiceConfig{
601-
ImageConfig: ImageWithPortAndHealthcheck{
602-
ImageWithPort: ImageWithPort{
601+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
602+
ImageWithOptionalPort: ImageWithOptionalPort{
603603
Image: Image{
604604
Location: aws.String("env-override location"),
605605
},
@@ -619,8 +619,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
619619
Type: aws.String(BackendServiceType),
620620
},
621621
BackendServiceConfig: BackendServiceConfig{
622-
ImageConfig: ImageWithPortAndHealthcheck{
623-
ImageWithPort: ImageWithPort{
622+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
623+
ImageWithOptionalPort: ImageWithOptionalPort{
624624
Image: Image{
625625
Location: aws.String("env-override location"),
626626
},
@@ -639,8 +639,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
639639
Type: aws.String(BackendServiceType),
640640
},
641641
BackendServiceConfig: BackendServiceConfig{
642-
ImageConfig: ImageWithPortAndHealthcheck{
643-
ImageWithPort: ImageWithPort{
642+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
643+
ImageWithOptionalPort: ImageWithOptionalPort{
644644
Image: Image{
645645
Build: BuildArgsOrString{
646646
BuildString: aws.String("env overridden dockerfile"),
@@ -661,8 +661,8 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
661661
Type: aws.String(BackendServiceType),
662662
},
663663
BackendServiceConfig: BackendServiceConfig{
664-
ImageConfig: ImageWithPortAndHealthcheck{
665-
ImageWithPort: ImageWithPort{
664+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
665+
ImageWithOptionalPort: ImageWithOptionalPort{
666666
Image: Image{
667667
Build: BuildArgsOrString{
668668
BuildString: aws.String("env overridden dockerfile"),

internal/pkg/manifest/svc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ secrets:
237237
Type: aws.String(BackendServiceType),
238238
},
239239
BackendServiceConfig: BackendServiceConfig{
240-
ImageConfig: ImageWithPortAndHealthcheck{
241-
ImageWithPort: ImageWithPort{
240+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
241+
ImageWithOptionalPort: ImageWithOptionalPort{
242242
Image: Image{
243243
Build: BuildArgsOrString{
244244
BuildString: aws.String("./subscribers/Dockerfile"),

internal/pkg/manifest/validate.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ func (i *ImageWithPortAndHealthcheck) Validate() error {
272272
return nil
273273
}
274274

275+
// Validate returns nil if ImageWithHealthcheckAndOptionalPort is configured correctly.
276+
func (i *ImageWithHealthcheckAndOptionalPort) Validate() error {
277+
var err error
278+
if err = i.ImageWithOptionalPort.Validate(); err != nil {
279+
return err
280+
}
281+
if err = i.HealthCheck.Validate(); err != nil {
282+
return fmt.Errorf(`validate "healthcheck": %w`, err)
283+
}
284+
return nil
285+
}
286+
275287
// Validate returns nil if ImageWithHealthcheck is configured correctly.
276288
func (i *ImageWithHealthcheck) Validate() error {
277289
if err := i.Image.Validate(); err != nil {
@@ -280,6 +292,14 @@ func (i *ImageWithHealthcheck) Validate() error {
280292
return nil
281293
}
282294

295+
// Validate returns nil if ImageWithOptionalPort is configured correctly.
296+
func (i *ImageWithOptionalPort) Validate() error {
297+
if err := i.Image.Validate(); err != nil {
298+
return err
299+
}
300+
return nil
301+
}
302+
283303
// Validate returns nil if ImageWithPort is configured correctly.
284304
func (i *ImageWithPort) Validate() error {
285305
if err := i.Image.Validate(); err != nil {

internal/pkg/manifest/validate_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,11 @@ func TestLoadBalancedWebServiceConfig_Validate(t *testing.T) {
156156
}
157157

158158
func TestBackendServiceConfig_Validate(t *testing.T) {
159-
testImageConfig := ImageWithPortAndHealthcheck{
160-
ImageWithPort: ImageWithPort{
159+
testImageConfig := ImageWithHealthcheckAndOptionalPort{
160+
ImageWithOptionalPort: ImageWithOptionalPort{
161161
Image: Image{
162162
Build: BuildArgsOrString{BuildString: aws.String("mockBuild")},
163163
},
164-
Port: uint16P(80),
165164
},
166165
}
167166
testCases := map[string]struct {
@@ -173,8 +172,8 @@ func TestBackendServiceConfig_Validate(t *testing.T) {
173172
"error if fail to validate image": {
174173
config: BackendService{
175174
BackendServiceConfig: BackendServiceConfig{
176-
ImageConfig: ImageWithPortAndHealthcheck{
177-
ImageWithPort: ImageWithPort{
175+
ImageConfig: ImageWithHealthcheckAndOptionalPort{
176+
ImageWithOptionalPort: ImageWithOptionalPort{
178177
Image: Image{
179178
Build: BuildArgsOrString{BuildString: aws.String("mockBuild")},
180179
Location: aws.String("mockLocation"),

internal/pkg/manifest/workload.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ type ImageWithPort struct {
125125
Port *uint16 `yaml:"port"`
126126
}
127127

128+
// ImageWithHealthcheckAndOptionalPort represents a container image with an optional exposed port and health check.
129+
type ImageWithHealthcheckAndOptionalPort struct {
130+
ImageWithOptionalPort `yaml:",inline"`
131+
HealthCheck ContainerHealthCheck `yaml:"healthcheck"`
132+
}
133+
134+
// ImageWithOptionalPort represents a container image with an optional exposed port.
135+
type ImageWithOptionalPort struct {
136+
Image Image `yaml:",inline"`
137+
Port *uint16 `yaml:"port"`
138+
}
139+
128140
// GetLocation returns the location of the image.
129141
func (i Image) GetLocation() string {
130142
return aws.StringValue(i.Location)

0 commit comments

Comments
 (0)