ecs_deploy 0.3.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a565132ff142d819e1bdc64368264ebc89de1030
4
- data.tar.gz: d0b5d389d5a9311853d8524e45c56bd54943450a
2
+ SHA256:
3
+ metadata.gz: 3988729fd28cd6cfb8fb6f36869855b1bbc468899d453a38e7415552a81c13aa
4
+ data.tar.gz: 73543aa973eadf609e049355064cd98e6ce18c448b69be6c1920e6cfee9fffa7
5
5
  SHA512:
6
- metadata.gz: 50c6f3c9aecdacc26de0d61cb487f4196bf31031b8c43b798b4bebae1e2246e35ebf1bb1c6079a62b7d5f54c3f504fefb69ca08f08689d9717c601746db63bdb
7
- data.tar.gz: f4fa32bf5a67e71a6265842eaffbff31647d17337fdb23e01007a6082f13b894a45ec127ca098a7c9125935937f9ac04c5d88025223915938da591a3259119e2
6
+ metadata.gz: 95495a3d6fdfaaaf4c7e5197f2f2107905310a0df36dc26197a43e8defe4e1721b9de45eed68a89e8aa50d3187df54590814544806b0e1b719e387bc774005af
7
+ data.tar.gz: 5e09d4a796fa051db972f5fd70c52ceb96058690123a3cc583aaf4642ebabf9e80cd225afcf64e67af9078944cb4ba013142f9923d9b6d8549d654401fa5edb6
data/.gitignore CHANGED
@@ -8,4 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
 
11
+ .rspec_status
11
12
  .envrc
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - ruby-2.4.9
4
+ - ruby-2.5.7
5
+ - ruby-2.6.5
data/CHANGELOG.md ADDED
@@ -0,0 +1,139 @@
1
+ # v1.0
2
+
3
+ ## Release v1.0.2 - 2021/05/26
4
+
5
+ ### Enhancement
6
+
7
+ * add option enable_execute_command to support ECS Exec
8
+ https://github.com/reproio/ecs_deploy/pull/69
9
+
10
+ ## Release v1.0.1 - 2021/05/19
11
+
12
+ ### Enhancement
13
+
14
+ * retry register_task_definition by AWS SDK feature
15
+ https://github.com/reproio/ecs_deploy/pull/67
16
+ * Support Ruby 3.0
17
+ https://github.com/reproio/ecs_deploy/pull/66
18
+ * Wait until stop old tasks
19
+ https://github.com/reproio/ecs_deploy/pull/65
20
+ * Add prioritized_over_upscale_triggers option to triggers
21
+ https://github.com/reproio/ecs_deploy/pull/62
22
+ * Display only unstable services in EcsDeploy::Service#wait_all_running
23
+ https://github.com/reproio/ecs_deploy/pull/61
24
+
25
+ ## Release v1.0.0 - 2019/12/24
26
+
27
+ ### New feature
28
+
29
+ * Add tasks to deploy the application faster
30
+ https://github.com/reproio/ecs_deploy/pull/57
31
+
32
+ ### Enhancement
33
+
34
+ * Add parameters `ecs_wait_until_services_stable_max_attempts` and `ecs_wait_until_services_stable_delay`
35
+ https://github.com/reproio/ecs_deploy/pull/30
36
+ * Detect region automatically according to AWS SDK
37
+ https://github.com/reproio/ecs_deploy/pull/31
38
+ * Support new features of ECS to support Fargate
39
+ https://github.com/reproio/ecs_deploy/pull/32
40
+ * Ignore running tasks which don't belong to the ECS services on deregistering container instances
41
+ https://github.com/reproio/ecs_deploy/pull/33
42
+ * Drop AWS SDK 2 support
43
+ https://github.com/reproio/ecs_deploy/pull/34
44
+ * Support scheduling_strategy option
45
+ https://github.com/reproio/ecs_deploy/pull/35
46
+ * Support execution_role_arn on task_definition
47
+ https://github.com/reproio/ecs_deploy/pull/36
48
+ * Support spot fleet requests and container instance draining
49
+ https://github.com/reproio/ecs_deploy/pull/40
50
+ * Add network_configuration paramters to ScheduledTask
51
+ https://github.com/reproio/ecs_deploy/pull/46
52
+ * Support tagging ECS resources
53
+ https://github.com/reproio/ecs_deploy/pull/48
54
+ https://github.com/reproio/ecs_deploy/pull/49
55
+ * Wait for stopping tasks until tasks stop
56
+ https://github.com/reproio/ecs_deploy/pull/50
57
+ * Improve performance when start tasks
58
+ https://github.com/reproio/ecs_deploy/pull/53
59
+ * Improve stability of auto scaling groups managed by ecs_auto_scaler
60
+ https://github.com/reproio/ecs_deploy/pull/55
61
+
62
+ ### Bug fixes
63
+
64
+ * Fix infinite loop that occurs when there are more than 100 container instances
65
+ https://github.com/reproio/ecs_deploy/pull/38
66
+ * Fix errors that occur on decreasing more than 20 container instances
67
+ https://github.com/reproio/ecs_deploy/pull/39
68
+
69
+ # Ancient releases
70
+
71
+ ## Release v0.3.2 - 2017/23/10
72
+
73
+ ### Enhancement
74
+
75
+ * Remove execution feature
76
+ https://github.com/reproio/ecs_deploy/pull/24
77
+ * Support container overrides in scheduled tasks
78
+ https://github.com/reproio/ecs_deploy/pull/26
79
+
80
+ ### Bug fixes
81
+
82
+ * Fix deployment errors that occur when `ecs_scheduled_tasks` is not set
83
+ https://github.com/reproio/ecs_deploy/pull/27
84
+
85
+ ## Release v0.3.1 - 2017/04/08
86
+
87
+ ### Bug fixes
88
+
89
+ * Fix block parameter name
90
+
91
+ ## Release v0.3.0 - 2017/03/08
92
+
93
+ ### New feature
94
+
95
+ * Support ScheduledTask deployment
96
+ https://github.com/reproio/ecs_deploy/pull/22
97
+
98
+ ### Enhancement
99
+
100
+ * Support network_mode and placement_constraints
101
+ * Introduce `ecs_registered_tasks` capistrano variable
102
+ https://github.com/reproio/ecs_deploy/pull/23
103
+
104
+ ### Bug fixes
105
+
106
+ * Filter inactive services
107
+ https://github.com/reproio/ecs_deploy/pull/19
108
+ * Wait 10 services at once
109
+ https://github.com/reproio/ecs_deploy/pull/20
110
+ https://github.com/reproio/ecs_deploy/pull/21
111
+
112
+ ## Release v0.2.0 - 2016/31/10
113
+
114
+ ### Enhancement
115
+
116
+ * Support task role arn
117
+ https://github.com/reproio/ecs_deploy/pull/13
118
+ * Make the scale-in process safe
119
+ https://github.com/reproio/ecs_deploy/pull/14
120
+ * Support ALB
121
+ https://github.com/reproio/ecs_deploy/pull/15
122
+
123
+ ## Release v0.1.2 - 2016/28/07
124
+
125
+ ### Bug fixes
126
+
127
+ * Fix rollback bug
128
+ https://github.com/reproio/ecs_deploy/pull/11
129
+
130
+ ## Release v0.1.1 - 2016/03/07
131
+
132
+ ### Bug fixes
133
+
134
+ * Add missing desired_count for backend services
135
+ https://github.com/reproio/ecs_deploy/pull/9
136
+
137
+ ## Release v0.1.0 - 2016/27/06
138
+
139
+ Initial release.
data/README.md CHANGED
@@ -28,11 +28,11 @@ require 'ecs_deploy/capistrano'
28
28
 
29
29
  # deploy.rb
30
30
  set :ecs_default_cluster, "ecs-cluster-name"
31
- set :ecs_access_key_id, "dummy" # optional, if nil, use environment variable
32
- set :ecs_secret_access_key, "dummy" # optional, if nil, use environment variable
33
31
  set :ecs_region, %w(ap-northeast-1) # optional, if nil, use environment variable
34
32
  set :ecs_service_role, "customEcsServiceRole" # default: ecsServiceRole
35
33
  set :ecs_deploy_wait_timeout, 600 # default: 300
34
+ set :ecs_wait_until_services_stable_max_attempts, 40 # optional
35
+ set :ecs_wait_until_services_stable_delay, 15 # optional
36
36
 
37
37
  set :ecs_tasks, [
38
38
  {
@@ -87,12 +87,27 @@ set :ecs_tasks, [
87
87
  }
88
88
  ],
89
89
  volumes: [{name: "sockets_path", host: {}}],
90
- executions: [ # execution task on deploy timing
91
- {container_overrides: [{name: "myapp", command: ["db_migrate"]}]},
92
- ]
93
90
  },
94
91
  ]
95
92
 
93
+ set :ecs_scheduled_tasks, [
94
+ {
95
+ cluster: "default", # Unless this key, use fetch(:ecs_default_cluster)
96
+ rule_name: "schedule_name",
97
+ schedule_expression: "cron(0 12 * * ? *)",
98
+ description: "schedule_description", # Optional
99
+ target_id: "task_name", # Unless this key, use task_definition_name
100
+ task_definition_name: "myapp-#{fetch(:rails_env)}",
101
+ task_count: 2, # Default 1
102
+ revision: 12, # Optional
103
+ role_arn: "TaskRoleArn", # Optional
104
+ container_overrides: [ # Optional
105
+ name: "myapp-main",
106
+ command: ["ls"],
107
+ ]
108
+ }
109
+ ]
110
+
96
111
  set :ecs_services, [
97
112
  {
98
113
  name: "myapp-#{fetch(:rails_env)}",
@@ -116,6 +131,7 @@ set :ecs_services, [
116
131
 
117
132
  ```sh
118
133
  cap <stage> ecs:register_task_definition # register ecs_tasks as TaskDefinition
134
+ cap <stage> ecs:deploy_scheduled_task # register ecs_scheduled_tasks to CloudWatchEvent
119
135
  cap <stage> ecs:deploy # create or update Service by ecs_services info
120
136
 
121
137
  cap <stage> ecs:rollback # deregister current task definition and update Service by previous revision of current task definition
@@ -173,7 +189,16 @@ And rollback
173
189
 
174
190
  ## Autoscaler
175
191
 
176
- Write config file (YAML format).
192
+ The autoscaler of `ecs_deploy` supports auto scaling of ECS services and clusters.
193
+
194
+ ### Prerequisits
195
+
196
+ * You use a ECS cluster whose instances belong to either an auto scaling group or a spot fleet request
197
+ * You have CloudWatch alarms and you want to scale services when their state changes
198
+
199
+ ### How to use autoscaler
200
+
201
+ First, write a configuration file (YAML format) like below:
177
202
 
178
203
  ```yaml
179
204
  # ポーリング時にupscale_triggersに指定した状態のalarmがあればstep分serviceとinstanceを増やす (max_task_countまで)
@@ -186,37 +211,275 @@ polling_interval: 60
186
211
  auto_scaling_groups:
187
212
  - name: ecs-cluster-nodes
188
213
  region: ap-northeast-1
189
- buffer: 1 # タスク数に対する余剰のインスタンス数
190
-
191
- services:
192
- - name: repro-api-production
193
214
  cluster: ecs-cluster
215
+ # autoscaler will set the capacity to (buffer + desired_tasks * required_capacity).
216
+ # Adjust this value if it takes much time to prepare ECS instances and launch new tasks.
217
+ buffer: 1
218
+ services:
219
+ - name: repro-api-production
220
+ step: 1
221
+ idle_time: 240
222
+ max_task_count: [10, 25]
223
+ scheduled_min_task_count:
224
+ - {from: "1:45", to: "4:30", count: 8}
225
+ cooldown_time_for_reach_max: 600
226
+ min_task_count: 0
227
+ # Required capacity per task (default: 1)
228
+ # You should specify "binpack" as task placement strategy if the value is less than 1 and you use an auto scaling group.
229
+ required_capacity: 0.5
230
+ upscale_triggers:
231
+ - alarm_name: "ECS [repro-api-production] CPUUtilization"
232
+ state: ALARM
233
+ - alarm_name: "ELB repro-api-a HTTPCode_Backend_5XX"
234
+ state: ALARM
235
+ step: 2
236
+ downscale_triggers:
237
+ - alarm_name: "ECS [repro-api-production] CPUUtilization (low)"
238
+ state: OK
239
+
240
+ spot_fleet_requests:
241
+ - id: sfr-354de735-2c17-4565-88c9-10ada5b957e5
194
242
  region: ap-northeast-1
195
- auto_scaling_group_name: ecs-cluster-nodes
196
- step: 1
197
- idle_time: 240
198
- max_task_count: [10, 25]
199
- scheduled_min_task_count:
200
- - {from: "1:45", to: "4:30", count: 8}
201
- cooldown_time_for_reach_max: 600
202
- min_task_count: 0
203
- upscale_triggers:
204
- - alarm_name: "ECS [repro-api-production] CPUUtilization"
205
- state: ALARM
206
- - alarm_name: "ELB repro-api-a HTTPCode_Backend_5XX"
207
- state: ALARM
208
- step: 2
209
- downscale_triggers:
210
- - alarm_name: "ECS [repro-api-production] CPUUtilization (low)"
211
- state: OK
243
+ cluster: ecs-cluster-for-worker
244
+ buffer: 1
245
+ services:
246
+ - name: repro-worker-production
247
+ step: 1
248
+ idle_time: 240
249
+ cooldown_time_for_reach_max: 600
250
+ min_task_count: 0
251
+ # Required capacity per task (default: 1)
252
+ # The capacity assumes that WeightedCapacity is equal to the number of vCPUs.
253
+ required_capacity: 2
254
+ upscale_triggers:
255
+ - alarm_name: "ECS [repro-worker-production] CPUUtilization"
256
+ state: ALARM
257
+ downscale_triggers:
258
+ - alarm_name: "ECS [repro-worker-production] CPUUtilization (low)"
259
+ state: OK
260
+ - alarm_name: "Aurora DMLLatency is high"
261
+ state: ALARM
262
+ prioritized_over_upscale_triggers: true
263
+
264
+ # If you specify `spot_instance_intrp_warns_queue_urls` as SQS queue for spot instance interruption warnings,
265
+ # autoscaler will polls them and set the state of instances to be intrrupted to "DRAINING".
266
+ # autoscaler will also waits for the capacity of active instances in the cluster being decreased
267
+ # when the capacity of spot fleet request is decreased,
268
+ # so you should specify URLs or set the state of the instances to "DRAINING" manually.
269
+ spot_instance_intrp_warns_queue_urls:
270
+ - https://sqs.ap-northeast-1.amazonaws.com/<account-id>/spot-instance-intrp-warns
212
271
  ```
213
272
 
273
+ Then, execute the following command:
274
+
214
275
  ```sh
215
276
  ecs_auto_scaler <config yaml>
216
277
  ```
217
278
 
218
279
  I recommends deploy `ecs_auto_scaler` on ECS too.
219
280
 
281
+ ### Signals
282
+
283
+ Signal | Description
284
+ -----------|------------------------------------------------------------
285
+ TERM, INT | Shutdown gracefully
286
+ CONT | Resume auto scaling
287
+ TSTP | Pause auto scaling (Run only container instance draining)
288
+
289
+ ### IAM policy for autoscaler
290
+
291
+ The following permissions are required for the preceding configuration of "repro-api-production" service:
292
+
293
+ ```
294
+ {
295
+ "Version": "2012-10-17",
296
+ "Statement": [
297
+ {
298
+ "Effect": "Allow",
299
+ "Action": [
300
+ "autoscaling:DescribeAutoScalingGroups",
301
+ "cloudwatch:DescribeAlarms",
302
+ "ec2:DescribeInstances",
303
+ "ec2:TerminateInstances",
304
+ "ecs:ListTasks"
305
+ ],
306
+ "Resource": "*"
307
+ },
308
+ {
309
+ "Effect": "Allow",
310
+ "Action": [
311
+ "ecs:DescribeServices",
312
+ "ecs:UpdateService"
313
+ ],
314
+ "Resource": [
315
+ "arn:aws:ecs:ap-northeast-1:<account-id>:service/ecs-cluster/repro-api-production"
316
+ ]
317
+ },
318
+ {
319
+ "Effect": "Allow",
320
+ "Action": [
321
+ "ecs:DescribeTasks"
322
+ ],
323
+ "Resource": [
324
+ "arn:aws:ecs:ap-northeast-1:<account-id>:task/ecs-cluster/*"
325
+ ]
326
+ },
327
+ {
328
+ "Effect": "Allow",
329
+ "Action": [
330
+ "autoscaling:DetachInstances",
331
+ "autoscaling:UpdateAutoScalingGroup"
332
+ ],
333
+ "Resource": [
334
+ "arn:aws:autoscaling:ap-northeast-1:<account-id>:autoScalingGroup:<group-id>:autoScalingGroupName/ecs-cluster-nodes"
335
+ ]
336
+ },
337
+ {
338
+ "Effect": "Allow",
339
+ "Action": [
340
+ "ecs:DescribeContainerInstances"
341
+ ],
342
+ "Resource": [
343
+ "arn:aws:ecs:ap-northeast-1:<account-id>:container-instance/ecs-cluster/*"
344
+ ]
345
+ },
346
+ {
347
+ "Effect": "Allow",
348
+ "Action": [
349
+ "ecs:DeregisterContainerInstance",
350
+ "ecs:ListContainerInstances"
351
+ ],
352
+ "Resource": [
353
+ "arn:aws:ecs:ap-northeast-1:<account-id>:cluster/ecs-cluster"
354
+ ]
355
+ }
356
+ ]
357
+ }
358
+ ```
359
+
360
+ If you use spot instances, additional permissions are required like below:
361
+
362
+ ```
363
+ {
364
+ "Version": "2012-10-17",
365
+ "Statement": [
366
+ {
367
+ "Effect": "Allow",
368
+ "Action": "ecs:UpdateContainerInstancesState",
369
+ "Resource": "arn:aws:ecs:ap-northeast-1:<account-id>:container-instance/ecs-cluster/*"
370
+ },
371
+ {
372
+ "Effect": "Allow",
373
+ "Action": [
374
+ "sqs:DeleteMessage",
375
+ "sqs:DeleteMessageBatch",
376
+ "sqs:ReceiveMessage"
377
+ ],
378
+ "Resource": "arn:aws:sqs:ap-northeast-1:<account-id>:spot-instance-intrp-warns"
379
+ }
380
+ ]
381
+ }
382
+ ```
383
+
384
+ The following permissions are required for the preceding configuration of "repro-worker-production" service:
385
+
386
+ ```
387
+ {
388
+ "Version": "2012-10-17",
389
+ "Statement": [
390
+ {
391
+ "Effect": "Allow",
392
+ "Action": [
393
+ "sqs:DeleteMessage",
394
+ "sqs:DeleteMessageBatch",
395
+ "sqs:ReceiveMessage"
396
+ ],
397
+ "Resource": "arn:aws:sqs:ap-northeast-1:<account-id>:spot-instance-intrp-warns"
398
+ },
399
+ {
400
+ "Effect": "Allow",
401
+ "Action": [
402
+ "cloudwatch:DescribeAlarms",
403
+ "ec2:DescribeInstances",
404
+ "ec2:DescribeSpotFleetInstances",
405
+ "ec2:DescribeSpotFleetRequests",
406
+ "ec2:ModifySpotFleetRequest",
407
+ "ec2:TerminateInstances",
408
+ "ecs:ListTasks"
409
+ ],
410
+ "Resource": "*"
411
+ },
412
+ {
413
+ "Effect": "Allow",
414
+ "Action": [
415
+ "ecs:DescribeServices",
416
+ "ecs:UpdateService"
417
+ ],
418
+ "Resource": [
419
+ "arn:aws:ecs:ap-northeast-1:<account-id>:service/ecs-cluster-for-worker/repro-worker-production"
420
+ ]
421
+ },
422
+ {
423
+ "Effect": "Allow",
424
+ "Action": [
425
+ "ecs:DescribeTasks"
426
+ ],
427
+ "Resource": [
428
+ "arn:aws:ecs:ap-northeast-1:<account-id>:task/ecs-cluster-for-worker/*"
429
+ ]
430
+ },
431
+ {
432
+ "Effect": "Allow",
433
+ "Action": [
434
+ "ecs:DescribeContainerInstances",
435
+ "ecs:UpdateContainerInstancesState"
436
+ ],
437
+ "Resource": [
438
+ "arn:aws:ecs:ap-northeast-1:<account-id>:container-instance/ecs-cluster-for-worker/*"
439
+ ]
440
+ },
441
+ {
442
+ "Effect": "Allow",
443
+ "Action": [
444
+ "ecs:ListContainerInstances"
445
+ ],
446
+ "Resource": [
447
+ "arn:aws:ecs:ap-northeast-1:<account-id>:cluster/ecs-cluster-for-worker"
448
+ ]
449
+ }
450
+ ]
451
+ }
452
+ ```
453
+
454
+ ### How to deploy faster with Auto Scaling Group
455
+
456
+ Add following configuration to your deploy.rb and hooks if you need.
457
+
458
+ ```ruby
459
+ # deploy.rb
460
+ set :ecs_instance_fluctuation_manager_configs, [
461
+ {
462
+ region: "ap-northeast-1",
463
+ cluster: "CLUSTER_NAME",
464
+ auto_scaling_group_name: "AUTO_SCALING_GROUP_NAME",
465
+ desired_capacity: 20, # original capacity of auto scaling group
466
+ }
467
+ ]
468
+ ```
469
+
470
+ This configuration enables tasks `ecs:increase_instances_to_max_size` and `ecs:terminate_redundant_instances`.
471
+ If this configuration is not set, the above tasks do nothing.
472
+ The task `ecs:increase_instances_to_max_size` will increase ECS instances.
473
+ The task `ecs:terminate_redundant_instances` will decrease ECS instances considering AZ balance.
474
+
475
+ Hook configuration example:
476
+
477
+ ```ruby
478
+ after "deploy:updating", "ecs:increase_instances_to_max_size"
479
+ after "deploy:finished", "ecs:terminate_redundant_instances"
480
+ after "deploy:failed", "ecs:terminate_redundant_instances"
481
+ ```
482
+
220
483
  ## Development
221
484
 
222
485
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.