ecs_deploy 0.2.0 → 1.0.1

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: a5027056d7641256dc566be9a2fd16dff8046f42
4
- data.tar.gz: 009c12a42f0fdcd18f3c8a53b35f0e48055112a8
2
+ SHA256:
3
+ metadata.gz: 6b008d513950d8b8e5abab3400d9c123dfe22fa7ab0bce2db9fc13d398359ccf
4
+ data.tar.gz: 8b3096d4cbe25b0febf667b560a0202e915ab9eee2a511b50dc50d61938805b3
5
5
  SHA512:
6
- metadata.gz: c53395003a3e8953aef1d63cdf7a59d89b1f45e90b0acef1a00ff4420a4e96139e854427e204650aecfbf02f6a064348a6dea9f5919ef6b161a4e962e9d2b6bf
7
- data.tar.gz: 82ce007f7e3e5ac6f4c30a705a6c16ca16889302d4c316a08990fae786bb403f9679582788584a23032d6894f04bcb6b321c82155c759844283c2400279162e2
6
+ metadata.gz: 1822d8b4ef6bf0392565918ee6bfe1df2d04e0ad376cb895497fbdd4029523f1db00452dd11f00c3c5acdedafa17039bfd49aebd8b16b4261cffb03a605a5fe9
7
+ data.tar.gz: 7a395b568354d77868bcd7b9c3d469550f8905fde2640bdace1e014d0639d5ab0a7f6f7b0f94fa6c2928c770a05837783c5994ce702c7fc31c744bc58ee46648
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,132 @@
1
+ # v1.0
2
+
3
+ ## Release v1.0.1 - 2021/05/19
4
+
5
+ ### Enhancement
6
+
7
+ * retry register_task_definition by AWS SDK feature
8
+ https://github.com/reproio/ecs_deploy/pull/67
9
+ * Support Ruby 3.0
10
+ https://github.com/reproio/ecs_deploy/pull/66
11
+ * Wait until stop old tasks
12
+ https://github.com/reproio/ecs_deploy/pull/65
13
+ * Add prioritized_over_upscale_triggers option to triggers
14
+ https://github.com/reproio/ecs_deploy/pull/62
15
+ * Display only unstable services in EcsDeploy::Service#wait_all_running
16
+ https://github.com/reproio/ecs_deploy/pull/61
17
+
18
+ ## Release v1.0.0 - 2019/12/24
19
+
20
+ ### New feature
21
+
22
+ * Add tasks to deploy the application faster
23
+ https://github.com/reproio/ecs_deploy/pull/57
24
+
25
+ ### Enhancement
26
+
27
+ * Add parameters `ecs_wait_until_services_stable_max_attempts` and `ecs_wait_until_services_stable_delay`
28
+ https://github.com/reproio/ecs_deploy/pull/30
29
+ * Detect region automatically according to AWS SDK
30
+ https://github.com/reproio/ecs_deploy/pull/31
31
+ * Support new features of ECS to support Fargate
32
+ https://github.com/reproio/ecs_deploy/pull/32
33
+ * Ignore running tasks which don't belong to the ECS services on deregistering container instances
34
+ https://github.com/reproio/ecs_deploy/pull/33
35
+ * Drop AWS SDK 2 support
36
+ https://github.com/reproio/ecs_deploy/pull/34
37
+ * Support scheduling_strategy option
38
+ https://github.com/reproio/ecs_deploy/pull/35
39
+ * Support execution_role_arn on task_definition
40
+ https://github.com/reproio/ecs_deploy/pull/36
41
+ * Support spot fleet requests and container instance draining
42
+ https://github.com/reproio/ecs_deploy/pull/40
43
+ * Add network_configuration paramters to ScheduledTask
44
+ https://github.com/reproio/ecs_deploy/pull/46
45
+ * Support tagging ECS resources
46
+ https://github.com/reproio/ecs_deploy/pull/48
47
+ https://github.com/reproio/ecs_deploy/pull/49
48
+ * Wait for stopping tasks until tasks stop
49
+ https://github.com/reproio/ecs_deploy/pull/50
50
+ * Improve performance when start tasks
51
+ https://github.com/reproio/ecs_deploy/pull/53
52
+ * Improve stability of auto scaling groups managed by ecs_auto_scaler
53
+ https://github.com/reproio/ecs_deploy/pull/55
54
+
55
+ ### Bug fixes
56
+
57
+ * Fix infinite loop that occurs when there are more than 100 container instances
58
+ https://github.com/reproio/ecs_deploy/pull/38
59
+ * Fix errors that occur on decreasing more than 20 container instances
60
+ https://github.com/reproio/ecs_deploy/pull/39
61
+
62
+ # Ancient releases
63
+
64
+ ## Release v0.3.2 - 2017/23/10
65
+
66
+ ### Enhancement
67
+
68
+ * Remove execution feature
69
+ https://github.com/reproio/ecs_deploy/pull/24
70
+ * Support container overrides in scheduled tasks
71
+ https://github.com/reproio/ecs_deploy/pull/26
72
+
73
+ ### Bug fixes
74
+
75
+ * Fix deployment errors that occur when `ecs_scheduled_tasks` is not set
76
+ https://github.com/reproio/ecs_deploy/pull/27
77
+
78
+ ## Release v0.3.1 - 2017/04/08
79
+
80
+ ### Bug fixes
81
+
82
+ * Fix block parameter name
83
+
84
+ ## Release v0.3.0 - 2017/03/08
85
+
86
+ ### New feature
87
+
88
+ * Support ScheduledTask deployment
89
+ https://github.com/reproio/ecs_deploy/pull/22
90
+
91
+ ### Enhancement
92
+
93
+ * Support network_mode and placement_constraints
94
+ * Introduce `ecs_registered_tasks` capistrano variable
95
+ https://github.com/reproio/ecs_deploy/pull/23
96
+
97
+ ### Bug fixes
98
+
99
+ * Filter inactive services
100
+ https://github.com/reproio/ecs_deploy/pull/19
101
+ * Wait 10 services at once
102
+ https://github.com/reproio/ecs_deploy/pull/20
103
+ https://github.com/reproio/ecs_deploy/pull/21
104
+
105
+ ## Release v0.2.0 - 2016/31/10
106
+
107
+ ### Enhancement
108
+
109
+ * Support task role arn
110
+ https://github.com/reproio/ecs_deploy/pull/13
111
+ * Make the scale-in process safe
112
+ https://github.com/reproio/ecs_deploy/pull/14
113
+ * Support ALB
114
+ https://github.com/reproio/ecs_deploy/pull/15
115
+
116
+ ## Release v0.1.2 - 2016/28/07
117
+
118
+ ### Bug fixes
119
+
120
+ * Fix rollback bug
121
+ https://github.com/reproio/ecs_deploy/pull/11
122
+
123
+ ## Release v0.1.1 - 2016/03/07
124
+
125
+ ### Bug fixes
126
+
127
+ * Add missing desired_count for backend services
128
+ https://github.com/reproio/ecs_deploy/pull/9
129
+
130
+ ## Release v0.1.0 - 2016/27/06
131
+
132
+ 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.
@@ -225,4 +488,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
225
488
 
226
489
  ## Contributing
227
490
 
228
- Bug reports and pull requests are welcome on GitHub at https://github.com/joker1007/ecs_deploy.
491
+ Bug reports and pull requests are welcome on GitHub at https://github.com/reproio/ecs_deploy.