ecs_deploy 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -5
- data/lib/ecs_deploy/auto_scaler.rb +0 -1
- data/lib/ecs_deploy/capistrano.rb +3 -11
- data/lib/ecs_deploy/scheduled_task.rb +16 -12
- data/lib/ecs_deploy/task_definition.rb +0 -36
- data/lib/ecs_deploy/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b00504a25168d2bc3b6c700c8ec8ff5ccded3ff3
|
4
|
+
data.tar.gz: 97c42178d1adec1876d319ddb8776cf28f687231
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa259524dc7c1c0d0b2a61228d61014106df9ecc9c5b0ae21eda2300917935103f4122d8d2682e51f4232da6d9037b79a7f4646ff189915a64c12330bb39a33c
|
7
|
+
data.tar.gz: b2d4350db7dd4083fceef62a38c9dc229e20bdfec903a09ee5cfbf5ba8a4a9089c1177fb23a7dfb2ba1659515f2b94e12c9a3df15b4ebaa9c03f3c6f6942c6f3
|
data/README.md
CHANGED
@@ -28,8 +28,6 @@ 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
|
@@ -87,12 +85,27 @@ set :ecs_tasks, [
|
|
87
85
|
}
|
88
86
|
],
|
89
87
|
volumes: [{name: "sockets_path", host: {}}],
|
90
|
-
executions: [ # execution task on deploy timing
|
91
|
-
{container_overrides: [{name: "myapp", command: ["db_migrate"]}]},
|
92
|
-
]
|
93
88
|
},
|
94
89
|
]
|
95
90
|
|
91
|
+
set :ecs_scheduled_tasks, [
|
92
|
+
{
|
93
|
+
cluster: "default", # Unless this key, use fetch(:ecs_default_cluster)
|
94
|
+
rule_name: "schedule_name",
|
95
|
+
schedule_expression: "cron(0 12 * * ? *"),
|
96
|
+
description: "schedule_description", # Optional
|
97
|
+
target_id: "task_name", # Unless this key, use task_definition_name
|
98
|
+
task_definition_name: "myapp-#{fetch(:rails_env)}",
|
99
|
+
task_count: 2, # Default 1
|
100
|
+
revision: 12, # Optional
|
101
|
+
role_arn: "TaskRoleArn", # Optional
|
102
|
+
container_overrides: [ # Optional
|
103
|
+
name: "myapp-main",
|
104
|
+
command: ["ls"],
|
105
|
+
]
|
106
|
+
}
|
107
|
+
]
|
108
|
+
|
96
109
|
set :ecs_services, [
|
97
110
|
{
|
98
111
|
name: "myapp-#{fetch(:rails_env)}",
|
@@ -116,6 +129,7 @@ set :ecs_services, [
|
|
116
129
|
|
117
130
|
```sh
|
118
131
|
cap <stage> ecs:register_task_definition # register ecs_tasks as TaskDefinition
|
132
|
+
cap <stage> ecs:deploy_scheduled_task # register ecs_scheduled_tasks to CloudWatchEvent
|
119
133
|
cap <stage> ecs:deploy # create or update Service by ecs_services info
|
120
134
|
|
121
135
|
cap <stage> ecs:rollback # deregister current task definition and update Service by previous revision of current task definition
|
@@ -36,15 +36,6 @@ namespace :ecs do
|
|
36
36
|
)
|
37
37
|
result = task_definition.register
|
38
38
|
ecs_registered_tasks[region][t[:name]] = result
|
39
|
-
|
40
|
-
executions = t[:executions].to_a
|
41
|
-
unless executions.empty?
|
42
|
-
warn "`executions` config is deprecated. I will remove this in near future"
|
43
|
-
end
|
44
|
-
executions.each do |exec|
|
45
|
-
exec[:cluster] ||= fetch(:ecs_default_cluster)
|
46
|
-
task_definition.run(exec)
|
47
|
-
end
|
48
39
|
end
|
49
40
|
end
|
50
41
|
|
@@ -53,14 +44,14 @@ namespace :ecs do
|
|
53
44
|
end
|
54
45
|
|
55
46
|
task deploy_scheduled_task: [:configure, :register_task_definition] do
|
56
|
-
if fetch(:
|
47
|
+
if fetch(:ecs_scheduled_tasks)
|
57
48
|
regions = Array(fetch(:ecs_region))
|
58
49
|
regions = [nil] if regions.empty?
|
59
50
|
regions.each do |r|
|
60
51
|
fetch(:ecs_scheduled_tasks).each do |t|
|
61
52
|
scheduled_task = EcsDeploy::ScheduledTask.new(
|
62
53
|
region: r,
|
63
|
-
cluster: t[:cluster],
|
54
|
+
cluster: t[:cluster] || fetch(:ecs_default_cluster),
|
64
55
|
rule_name: t[:rule_name],
|
65
56
|
schedule_expression: t[:schedule_expression],
|
66
57
|
enabled: t[:enabled] != false,
|
@@ -70,6 +61,7 @@ namespace :ecs do
|
|
70
61
|
revision: t[:revision],
|
71
62
|
task_count: t[:task_count],
|
72
63
|
role_arn: t[:role_arn],
|
64
|
+
container_overrides: t[:container_overrides],
|
73
65
|
)
|
74
66
|
scheduled_task.deploy
|
75
67
|
end
|
@@ -9,7 +9,7 @@ module EcsDeploy
|
|
9
9
|
def initialize(
|
10
10
|
cluster:, rule_name:, schedule_expression:, enabled: true, description: nil, target_id: nil,
|
11
11
|
task_definition_name:, revision: nil, task_count: nil, role_arn:,
|
12
|
-
region: nil
|
12
|
+
region: nil, container_overrides: nil
|
13
13
|
)
|
14
14
|
@cluster = cluster
|
15
15
|
@rule_name = rule_name
|
@@ -22,6 +22,7 @@ module EcsDeploy
|
|
22
22
|
@revision = revision
|
23
23
|
@role_arn = role_arn
|
24
24
|
@region = region || EcsDeploy.config.default_region || ENV["AWS_DEFAULT_REGION"]
|
25
|
+
@container_overrides = container_overrides
|
25
26
|
|
26
27
|
@client = Aws::ECS::Client.new(region: @region)
|
27
28
|
@cloud_watch_events = Aws::CloudWatchEvents::Client.new(region: @region)
|
@@ -58,19 +59,22 @@ module EcsDeploy
|
|
58
59
|
end
|
59
60
|
|
60
61
|
def put_targets
|
62
|
+
target = {
|
63
|
+
id: @target_id,
|
64
|
+
arn: cluster_arn,
|
65
|
+
role_arn: @role_arn,
|
66
|
+
ecs_parameters: {
|
67
|
+
task_definition_arn: task_definition_arn,
|
68
|
+
task_count: @task_count,
|
69
|
+
},
|
70
|
+
}
|
71
|
+
if @container_overrides
|
72
|
+
target.merge!(input: { containerOverrides: @container_overrides }.to_json)
|
73
|
+
end
|
74
|
+
|
61
75
|
res = @cloud_watch_events.put_targets(
|
62
76
|
rule: @rule_name,
|
63
|
-
targets: [
|
64
|
-
{
|
65
|
-
id: @target_id,
|
66
|
-
arn: cluster_arn,
|
67
|
-
role_arn: @role_arn,
|
68
|
-
ecs_parameters: {
|
69
|
-
task_definition_arn: task_definition_arn,
|
70
|
-
task_count: @task_count,
|
71
|
-
},
|
72
|
-
}
|
73
|
-
]
|
77
|
+
targets: [target]
|
74
78
|
)
|
75
79
|
if res.failed_entry_count.zero?
|
76
80
|
EcsDeploy.logger.info "create cloudwatch event target [#{@target_id}] [#{@region}] [#{Paint['OK', :green]}]"
|
@@ -56,41 +56,5 @@ module EcsDeploy
|
|
56
56
|
EcsDeploy.logger.info "register task definition [#{@task_definition_name}] [#{@region}] [#{Paint['OK', :green]}]"
|
57
57
|
res.task_definition
|
58
58
|
end
|
59
|
-
|
60
|
-
def run(info)
|
61
|
-
resp = @client.run_task({
|
62
|
-
cluster: info[:cluster],
|
63
|
-
task_definition: @task_definition_name,
|
64
|
-
overrides: {
|
65
|
-
container_overrides: info[:container_overrides] || []
|
66
|
-
},
|
67
|
-
count: info[:count] || 1,
|
68
|
-
started_by: "capistrano",
|
69
|
-
})
|
70
|
-
unless resp.failures.empty?
|
71
|
-
resp.failures.each do |f|
|
72
|
-
raise "#{f.arn}: #{f.reason}"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
wait_targets = Array(info[:wait_stop])
|
77
|
-
unless wait_targets.empty?
|
78
|
-
@client.wait_until(:tasks_running, cluster: info[:cluster], tasks: resp.tasks.map { |t| t.task_arn })
|
79
|
-
@client.wait_until(:tasks_stopped, cluster: info[:cluster], tasks: resp.tasks.map { |t| t.task_arn })
|
80
|
-
|
81
|
-
resp = @client.describe_tasks(cluster: info[:cluster], tasks: resp.tasks.map { |t| t.task_arn })
|
82
|
-
resp.tasks.each do |t|
|
83
|
-
t.containers.each do |c|
|
84
|
-
next unless wait_targets.include?(c.name)
|
85
|
-
|
86
|
-
unless c.exit_code.zero?
|
87
|
-
raise "Task has errors: #{c.reason}"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
EcsDeploy.logger.info "run task [#{@task_definition_name} #{info.inspect}] [#{@region}] [#{Paint['OK', :green]}]"
|
94
|
-
end
|
95
59
|
end
|
96
60
|
end
|
data/lib/ecs_deploy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecs_deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.6.
|
126
|
+
rubygems_version: 2.6.13
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: AWS ECS deploy helper
|