@@ -26,10 +26,13 @@ func (flags *arrayFlag) Set(value string) error {
26
26
return nil
27
27
}
28
28
29
+ func (flags * arrayFlag ) Specified () bool {
30
+ return len (* flags ) > 0
31
+ }
32
+
29
33
var (
30
34
clusterName = flag .String ("c" , "" , "Cluster name to deploy to" )
31
35
repoName = flag .String ("i" , "" , "Container repo to pull from e.g. quay.io/username/reponame" )
32
- appName = flag .String ("a" , "" , "Application name" )
33
36
environment = flag .String ("e" , "" , "Application environment, e.g. production" )
34
37
sha = flag .String ("s" , "" , "Tag, usually short git SHA to deploy" )
35
38
region = flag .String ("r" , "" , "AWS region" )
39
42
)
40
43
41
44
var channels arrayFlag
45
+ var apps arrayFlag
42
46
43
47
func fail (s string ) {
44
48
fmt .Printf (s )
@@ -74,22 +78,25 @@ func sendWebhooks(message string) {
74
78
75
79
func init () {
76
80
flag .Var (& channels , "C" , "Slack channels to post to (can be specified multiple times)" )
81
+ flag .Var (& apps , "a" , "Application names (can be specified multiple times)" )
82
+
77
83
}
78
84
79
85
func main () {
80
86
flag .Parse ()
81
87
82
- if * clusterName == "" || * appName == "" || * environment == "" || * region == "" {
88
+ if * clusterName == "" || ! apps . Specified () || * environment == "" || * region == "" {
83
89
flag .Usage ()
84
- fail (fmt .Sprintf ("Failed deployment of app %s : missing parameters\n " , * appName ))
90
+ fail (fmt .Sprintf ("Failed deployment of apps %s : missing parameters\n " , apps ))
85
91
}
86
92
87
93
if (* repoName == "" || * sha == "" ) && * targetImage == "" {
88
94
flag .Usage ()
89
- fail (fmt .Sprintf ("Failed deployment %s : no repo name, sha or target image specified\n " , * appName ))
95
+ fail (fmt .Sprintf ("Failed deployment %s : no repo name, sha or target image specified\n " , apps ))
90
96
}
91
97
92
- serviceName := * appName + "-" + * environment
98
+ // Take the first app specified and use it for creating the task definitions for all services.
99
+ exemplarServiceName := apps [0 ] + "-" + * environment
93
100
cfg := & aws.Config {
94
101
Region : aws .String (* region ),
95
102
}
@@ -104,26 +111,26 @@ func main() {
104
111
} else {
105
112
fmt .Printf ("Request to deploy target image: %s to %s at %s \n " , * targetImage , * environment , * region )
106
113
}
107
- fmt .Printf ("Describing services for cluster %s and service %s \n " , * clusterName , serviceName )
114
+ fmt .Printf ("Describing services for cluster %s and service %s \n " , * clusterName , exemplarServiceName )
108
115
109
116
serviceDesc , err :=
110
117
svc .DescribeServices (
111
118
& ecs.DescribeServicesInput {
112
119
Cluster : clusterName ,
113
- Services : []* string {& serviceName },
120
+ Services : []* string {& exemplarServiceName },
114
121
})
115
122
if err != nil {
116
- fail (fmt .Sprintf ("Failed: deployment %s \n `%s`" , * appName , err .Error ()))
123
+ fail (fmt .Sprintf ("Failed to describe %s \n `%s`" , exemplarServiceName , err .Error ()))
117
124
}
118
125
119
126
if len (serviceDesc .Services ) < 1 {
120
- msg := fmt .Sprintf ("No service %s found on cluster %s" , serviceName , * clusterName )
127
+ msg := fmt .Sprintf ("No service %s found on cluster %s" , exemplarServiceName , * clusterName )
121
128
fail ("Failed: " + msg )
122
129
}
123
130
124
131
service := serviceDesc .Services [0 ]
125
- if serviceName != * service .ServiceName {
126
- msg := fmt .Sprintf ("Found the wrong service when looking for %s found %s \n " , serviceName , * service .ServiceName )
132
+ if exemplarServiceName != * service .ServiceName {
133
+ msg := fmt .Sprintf ("Found the wrong service when looking for %s found %s \n " , exemplarServiceName , * service .ServiceName )
127
134
fail ("Failed: " + msg )
128
135
}
129
136
@@ -134,7 +141,7 @@ func main() {
134
141
& ecs.DescribeTaskDefinitionInput {
135
142
TaskDefinition : service .TaskDefinition })
136
143
if err != nil {
137
- fail (fmt .Sprintf ("Failed: deployment %s \n `%s`" , * appName , err .Error ()))
144
+ fail (fmt .Sprintf ("Failed: deployment %s \n `%s`" , exemplarServiceName , err .Error ()))
138
145
}
139
146
140
147
if * debug {
@@ -166,41 +173,45 @@ func main() {
166
173
registerRes , err :=
167
174
svc .RegisterTaskDefinition (futureDef )
168
175
if err != nil {
169
- fail (fmt .Sprintf ("Failed: deployment %s for %s to %s \n `%s`" , * containerDef .Image , * appName , * clusterName , err .Error ()))
176
+ fail (fmt .Sprintf ("Failed: deployment %s for %s to %s \n `%s`" , * containerDef .Image , exemplarServiceName , * clusterName , err .Error ()))
170
177
}
171
178
172
179
newArn := registerRes .TaskDefinition .TaskDefinitionArn
173
180
174
181
fmt .Printf ("Registered new task for %s:%s \n " , * sha , * newArn )
175
182
176
- // update service to use new definition
177
- _ , err = svc .UpdateService (
178
- & ecs.UpdateServiceInput {
179
- Cluster : clusterName ,
180
- Service : & serviceName ,
181
- DesiredCount : service .DesiredCount ,
182
- TaskDefinition : newArn ,
183
- })
184
- if err != nil {
185
- fail (fmt .Sprintf ("Failed: deployment %s for %s to %s as %s \n `%s`" , * containerDef .Image , * appName , * clusterName , * newArn , err .Error ()))
186
- }
183
+ // update services to use new definition
184
+ for _ , appName := range apps {
185
+ serviceName := appName + "-" + * environment
187
186
188
- slackMsg := fmt .Sprintf ("Deployed %s for *%s* to *%s* as `%s`" , * containerDef .Image , * appName , * clusterName , * newArn )
187
+ _ , err = svc .UpdateService (
188
+ & ecs.UpdateServiceInput {
189
+ Cluster : clusterName ,
190
+ Service : & serviceName ,
191
+ DesiredCount : service .DesiredCount ,
192
+ TaskDefinition : newArn ,
193
+ })
194
+ if err != nil {
195
+ fail (fmt .Sprintf ("Failed: deployment %s for %s to %s as %s \n `%s`" , * containerDef .Image , appName , * clusterName , * newArn , err .Error ()))
196
+ }
189
197
190
- // extract old image sha, and use it to generate a git compare URL
191
- if * oldImage != "" && * sha != "" {
192
- parts := strings .Split (* oldImage , ":" )
193
- if len (parts ) == 2 {
194
- // possibly a tagged image "def15c31-php5.5"
195
- parts = strings .Split (parts [1 ], "-" )
196
- if gitURL , err := gitURL (parts [0 ], * sha ); err == nil {
197
- slackMsg += " (<" + gitURL + "|diff>)"
198
+ slackMsg := fmt .Sprintf ("Deployed %s for *%s* to *%s* as `%s`" , * containerDef .Image , appName , * clusterName , * newArn )
199
+
200
+ // extract old image sha, and use it to generate a git compare URL
201
+ if * oldImage != "" && * sha != "" {
202
+ parts := strings .Split (* oldImage , ":" )
203
+ if len (parts ) == 2 {
204
+ // possibly a tagged image "def15c31-php5.5"
205
+ parts = strings .Split (parts [1 ], "-" )
206
+ if gitURL , err := gitURL (parts [0 ], * sha ); err == nil {
207
+ slackMsg += " (<" + gitURL + "|diff>)"
208
+ }
198
209
}
199
210
}
200
- }
201
- sendWebhooks (slackMsg )
211
+ sendWebhooks (slackMsg )
202
212
203
- fmt .Printf ("Updated %s service to use new ARN: %s \n " , serviceName , * newArn )
213
+ fmt .Printf ("Updated %s service to use new ARN: %s \n " , serviceName , * newArn )
214
+ }
204
215
205
216
}
206
217
0 commit comments