forked from josmo/drone-ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
303 lines (298 loc) · 10.4 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli"
)
var (
version = "0.0.0"
build = "0"
)
func main() {
app := cli.NewApp()
app.Name = "AWS ECS Deploy"
app.Usage = "AWS ECS Deploy"
app.Action = run
app.Version = fmt.Sprintf("%s+%s", version, build)
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "access-key",
Usage: "AWS access key",
EnvVar: "PLUGIN_ACCESS_KEY,ECS_ACCESS_KEY,AWS_ACCESS_KEY",
},
cli.StringFlag{
Name: "secret-key",
Usage: "AWS secret key",
EnvVar: "PLUGIN_SECRET_KEY,ECS_SECRET_KEY,AWS_SECRET_KEY",
},
cli.StringFlag{
Name: "user-role-arn",
Usage: "AWS user role",
EnvVar: "PLUGIN_USER_ROLE_ARN,ECS_USER_ROLE_ARN,AWS_USER_ROLE_ARN",
},
cli.StringFlag{
Name: "region",
Usage: "aws region",
EnvVar: "PLUGIN_REGION",
},
cli.StringFlag{
Name: "family",
Usage: "ECS family",
EnvVar: "PLUGIN_FAMILY",
},
cli.StringFlag{
Name: "task-role-arn",
Usage: "ECS task IAM role",
EnvVar: "PLUGIN_TASK_ROLE_ARN",
},
cli.StringFlag{
Name: "service",
Usage: "Service to act on",
EnvVar: "PLUGIN_SERVICE",
},
cli.StringFlag{
Name: "container-name",
Usage: "Container name",
EnvVar: "PLUGIN_CONTAINER_NAME",
},
cli.StringFlag{
Name: "docker-image",
Usage: "image to use",
EnvVar: "PLUGIN_DOCKER_IMAGE",
},
cli.StringFlag{
Name: "tag",
Usage: "AWS tag",
EnvVar: "PLUGIN_TAG",
},
cli.StringFlag{
Name: "cluster",
Usage: "AWS ECS cluster",
EnvVar: "PLUGIN_CLUSTER",
},
cli.StringFlag{
Name: "log-driver",
Usage: "The log driver to use for the container",
EnvVar: "PLUGIN_LOG_DRIVER",
},
cli.StringSliceFlag{
Name: "log-options",
Usage: "The configuration options to send to the log driver",
EnvVar: "PLUGIN_LOG_OPTIONS",
},
cli.StringSliceFlag{
Name: "port-mappings",
Usage: "ECS port maps",
EnvVar: "PLUGIN_PORT_MAPPINGS",
},
cli.StringSliceFlag{
Name: "labels",
Usage: "A key/value map of labels to add to the container",
EnvVar: "PLUGIN_LABELS",
},
cli.StringSliceFlag{
Name: "entry-point",
Usage: "A list of values to build the container entry point argument",
EnvVar: "PLUGIN_ENTRY_POINT",
},
cli.StringSliceFlag{
Name: "environment-variables",
Usage: "ECS environment-variables",
EnvVar: "PLUGIN_ENVIRONMENT_VARIABLES",
},
cli.StringSliceFlag{
Name: "secret-environment-variables",
Usage: "Secret ECS environment-variables",
EnvVar: "PLUGIN_SECRET_ENVIRONMENT_VARIABLES",
},
cli.StringSliceFlag{
Name: "secrets-manager-variables",
Usage: "Environment-variables from AWS Secrets manager",
EnvVar: "PLUGIN_SECRETS_MANAGER_VARIABLES",
},
cli.Int64Flag{
Name: "cpu",
Usage: "The number of cpu units to reserve for the container",
EnvVar: "PLUGIN_CPU",
},
cli.Int64Flag{
Name: "memory",
Usage: "The hard limit (in MiB) of memory to present to the container",
EnvVar: "PLUGIN_MEMORY",
},
cli.Int64Flag{
Name: "memory-reservation",
Usage: "The soft limit (in MiB) of memory to reserve for the container. Defaults to 128",
Value: 128,
EnvVar: "PLUGIN_MEMORY_RESERVATION",
},
cli.StringFlag{
Name: "network-mode",
Usage: "The Docker networking mode to use for the containers in the task. Defaults to bridge if unspecified",
EnvVar: "PLUGIN_TASK_NETWORK_MODE",
},
cli.StringFlag{
Name: "deployment-configuration",
Usage: "Deployment parameters that control how many tasks run during the deployment and the ordering of stopping and starting tasks",
EnvVar: "PLUGIN_DEPLOYMENT_CONFIGURATION",
},
cli.Int64Flag{
Name: "desired-count",
Usage: "The number of instantiations of the specified task definition to place and keep running on your cluster",
EnvVar: "PLUGIN_DESIRED_COUNT",
},
cli.BoolTFlag{
Name: "yaml-verified",
Usage: "Ensure the yaml was signed",
EnvVar: "DRONE_YAML_VERIFIED",
},
cli.StringFlag{
Name: "task-cpu",
Usage: "The number of CPU units used by the task. It can be expressed as an integer using CPU units, for example 1024, or as a string using vCPUs, for example 1 vCPU or 1 vcpu",
EnvVar: "PLUGIN_TASK_CPU",
},
cli.StringFlag{
Name: "task-memory",
Usage: "The amount of memory (in MiB) used by the task.It can be expressed as an integer using MiB, for example 1024, or as a string using GB. Required if using Fargate launch type",
EnvVar: "PLUGIN_TASK_MEMORY",
},
cli.StringFlag{
Name: "task-execution-role-arn",
Usage: "The Amazon Resource Name (ARN) of the task execution role that the Amazon ECS container agent and the Docker daemon can assume.",
EnvVar: "PLUGIN_TASK_EXECUTION_ROLE_ARN",
},
cli.StringFlag{
Name: "compatibilities",
Usage: "List of launch types supported by the task",
EnvVar: "PLUGIN_COMPATIBILITIES",
},
cli.StringSliceFlag{
Name: "healthcheck-command",
Usage: "List representing the command that the container runs to determine if it is healthy. Must start with CMD to execute the command arguments directly, or CMD-SHELL to run the command with the container's default shell",
EnvVar: "PLUGIN_HEALTHCHECK_COMMAND",
},
cli.Int64Flag{
Name: "healthcheck-interval",
Usage: "The time period in seconds between each health check execution. You may specify between 5 and 300 seconds. Defaults to 30 seconds",
Value: 30,
EnvVar: "PLUGIN_HEALTHCHECK_INTERVAL",
},
cli.Int64Flag{
Name: "healthcheck-retries",
Usage: "The number of times to retry a failed health check before the container is considered unhealthy. You may specify between 1 and 10 retries. Defaults to 3",
Value: 3,
EnvVar: "PLUGIN_HEALTHCHECK_RETRIES",
},
cli.Int64Flag{
Name: "healthcheck-start-period",
Usage: "The grace period within which to provide containers time to bootstrap before failed health checks count towards the maximum number of retries. You may specify between 0 and 300 seconds. The startPeriod is disabled by default",
Value: 0,
EnvVar: "PLUGIN_HEALTHCHECK_START_PERIOD",
},
cli.Int64Flag{
Name: "healthcheck-timeout",
Usage: "The time period in seconds to wait for a health check to succeed before it is considered a failure. You may specify between 2 and 60 seconds. Defaults to 5 seconds",
Value: 5,
EnvVar: "PLUGIN_HEALTHCHECK_TIMEOUT",
},
cli.StringFlag{
Name: "service-network-assign-public-ip",
Usage: "Assign public IP (ENABLED|DISABLED), defaults to DISABLED",
Value: "DISABLED",
EnvVar: "PLUGIN_SERVICE_NETWORK_ASSIGN_PUBLIC_IP",
},
cli.StringSliceFlag{
Name: "service-network-security-groups",
Usage: "The security groups to associate with the service",
EnvVar: "PLUGIN_SERVICE_NETWORK_SECURITY_GROUPS",
},
cli.StringSliceFlag{
Name: "service-network-subnets",
Usage: "The subnets to associate with the service",
EnvVar: "PLUGIN_SERVICE_NETWORK_SUBNETS",
},
cli.StringSliceFlag{
Name: "ulimits",
Usage: "ECS ulimits",
EnvVar: "PLUGIN_ULIMITS",
},
cli.StringSliceFlag{
Name: "mount-points",
Usage: "ECS mount points",
EnvVar: "PLUGIN_MOUNT_POINTS",
},
cli.StringSliceFlag{
Name: "volumes",
Usage: "ECS volume definitions",
EnvVar: "PLUGIN_VOLUMES",
},
cli.StringSliceFlag{
Name: "efs-volumes",
Usage: "EFS volume definitions",
EnvVar: "PLUGIN_EFS_VOLUMES",
},
cli.StringFlag{
Name: "placement-constraints",
Usage: "json array of placement constraints",
EnvVar: "PLUGIN_PLACEMENT_CONSTRAINTS",
},
cli.BoolFlag{
Name: "privileged",
Usage: "Container will run in privileged mode (applicable only for EC2 launch type)",
EnvVar: "PLUGIN_PRIVILEGED",
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func run(c *cli.Context) error {
plugin := Plugin{
Key: c.String("access-key"),
Secret: c.String("secret-key"),
UserRoleArn: c.String("user-role-arn"),
Region: c.String("region"),
Family: c.String("family"),
TaskRoleArn: c.String("task-role-arn"),
Service: c.String("service"),
ContainerName: c.String("container-name"),
DockerImage: c.String("docker-image"),
Tag: c.String("tag"),
Cluster: c.String("cluster"),
LogDriver: c.String("log-driver"),
LogOptions: c.StringSlice("log-options"),
PortMappings: c.StringSlice("port-mappings"),
Environment: c.StringSlice("environment-variables"),
SecretEnvironment: c.StringSlice("secret-environment-variables"),
SecretsManagerEnvironment: c.StringSlice("secrets-manager-variables"),
EntryPoint: c.StringSlice("entry-point"),
Labels: c.StringSlice("labels"),
CPU: c.Int64("cpu"),
Memory: c.Int64("memory"),
MemoryReservation: c.Int64("memory-reservation"),
NetworkMode: c.String("network-mode"),
DeploymentConfiguration: c.String("deployment-configuration"),
DesiredCount: c.Int64("desired-count"),
YamlVerified: c.BoolT("yaml-verified"),
TaskCPU: c.String("task-cpu"),
TaskMemory: c.String("task-memory"),
TaskExecutionRoleArn: c.String("task-execution-role-arn"),
Compatibilities: c.String("compatibilities"),
HealthCheckCommand: c.StringSlice("healthcheck-command"),
HealthCheckInterval: c.Int64("healthcheck-interval"),
HealthCheckRetries: c.Int64("healthcheck-retries"),
HealthCheckStartPeriod: c.Int64("healthcheck-start-period"),
HealthCheckTimeout: c.Int64("healthcheck-timeout"),
ServiceNetworkAssignPublicIp: c.String("service-network-assign-public-ip"),
ServiceNetworkSecurityGroups: c.StringSlice("service-network-security-groups"),
ServiceNetworkSubnets: c.StringSlice("service-network-subnets"),
Ulimits: c.StringSlice("ulimits"),
MountPoints: c.StringSlice("mount-points"),
Volumes: c.StringSlice("volumes"),
EfsVolumes: c.StringSlice("efs-volumes"),
PlacementConstraints: c.String("placement-constraints"),
Privileged: c.Bool("privileged"),
}
return plugin.Exec()
}