Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit 12a47cb

Browse files
committed
Reject compose file that uses incompatible features
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 11c2b7a commit 12a47cb

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/bugsnag/panicwrap v1.2.0 // indirect
1515
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
1616
github.com/cloudflare/cfssl v1.4.1 // indirect
17-
github.com/compose-spec/compose-go v0.0.0-20200624120600-614475470cd8
17+
github.com/compose-spec/compose-go v0.0.0-20200707124823-710ff8e60ad9
1818
github.com/containerd/containerd v1.3.2 // indirect
1919
github.com/containerd/continuity v0.0.0-20200413184840-d3ef23f19fbb // indirect
2020
github.com/docker/cli v0.0.0-20200130152716-5d0cf8839492

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ github.com/cloudflare/go-metrics v0.0.0-20151117154305-6a9aea36fb41/go.mod h1:ea
5656
github.com/cloudflare/redoctober v0.0.0-20171127175943-746a508df14c/go.mod h1:6Se34jNoqrd8bTxrmJB2Bg2aoZ2CdSXonils9NsiNgo=
5757
github.com/compose-spec/compose-go v0.0.0-20200624120600-614475470cd8 h1:sVvKsoXizFOuJNc8dM91IeET2/zDNFj3hwHgk437iJ8=
5858
github.com/compose-spec/compose-go v0.0.0-20200624120600-614475470cd8/go.mod h1:ih9anT8po+49hrb+1j3ldIJ/YRAaBH52ErlQLTKE2Yo=
59+
github.com/compose-spec/compose-go v0.0.0-20200707124823-710ff8e60ad9 h1:WkFqc6UpRqxROso9KC+ceaTiXx/VWpeO1x+NV0d4d+o=
60+
github.com/compose-spec/compose-go v0.0.0-20200707124823-710ff8e60ad9/go.mod h1:ArodJ6gsEB7iWKrbV3fSHZ08LlBvSVB0Oqg04fX86t4=
5961
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko=
6062
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
6163
github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
@@ -167,6 +169,8 @@ github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2
167169
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
168170
github.com/jmhodges/clock v0.0.0-20160418191101-880ee4c33548/go.mod h1:hGT6jSUVzF6no3QaDSMLGLEHtHSBSefs+MgcDWnmhmo=
169171
github.com/jmoiron/sqlx v0.0.0-20180124204410-05cef0741ade/go.mod h1:IiEW3SEiiErVyFdH8NTuWjSifiEQKUoyK3LNqr2kCHU=
172+
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
173+
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
170174
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
171175
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
172176
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=

pkg/amazon/backend/cloudformation.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
cloudmap "github.com/awslabs/goformation/v4/cloudformation/servicediscovery"
1818
"github.com/awslabs/goformation/v4/cloudformation/tags"
1919
"github.com/compose-spec/compose-go/compatibility"
20+
"github.com/compose-spec/compose-go/errdefs"
2021
"github.com/compose-spec/compose-go/types"
2122
"github.com/docker/ecs-plugin/pkg/compose"
2223
"github.com/sirupsen/logrus"
@@ -39,8 +40,7 @@ func (c *FargateCompatibilityChecker) CheckPortsPublished(p *types.ServicePortCo
3940
p.Published = p.Target
4041
}
4142
if p.Published != p.Target {
42-
c.Error("published port can't be set to a distinct value than container port")
43-
p.Published = p.Target
43+
c.Incompatible("published port can't be set to a distinct value than container port")
4444
}
4545
}
4646

@@ -51,7 +51,7 @@ func (c *FargateCompatibilityChecker) CheckCapAdd(service *types.ServiceConfig)
5151
case "SYS_PTRACE":
5252
add = append(add, cap)
5353
default:
54-
c.Error("service.cap_add = %s", cap)
54+
c.Incompatible("ECS doesn't allow to add capability %s", cap)
5555
}
5656
}
5757
service.CapAdd = add
@@ -86,7 +86,14 @@ func (b Backend) Convert(project *types.Project) (*cloudformation.Template, erro
8686
}
8787
compatibility.Check(project, checker)
8888
for _, err := range checker.Errors() {
89-
logrus.Warn(err.Error())
89+
if errdefs.IsIncompatibleError(err) {
90+
logrus.Error(err.Error())
91+
} else {
92+
logrus.Warn(err.Error())
93+
}
94+
}
95+
if !compatibility.IsCompatible(checker) {
96+
return nil, fmt.Errorf("compose file is incompatible with Amazon ECS")
9097
}
9198

9299
template := cloudformation.NewTemplate()

0 commit comments

Comments
 (0)