ecs_deployer 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ecs_deployer/client.rb +59 -51
- data/lib/ecs_deployer/commander.rb +36 -56
- data/lib/ecs_deployer/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: 47b8f97fb9482d7736def886976477700742787b
|
4
|
+
data.tar.gz: 4d9f5cf0333818a5df1482ece0fc06ead1b9abb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13d158aa62c0e9e9ffa17f19b6a8c1d4b676e3144f2db0294064f69f0e93e684c7dafa79f936a3eec96a82e45de57733b1fe9872af31460155524aca7991416c
|
7
|
+
data.tar.gz: 9c6a7a38501ca9709762bfd0689bdcea6baac07896504fdd2700a89427f3f772641328227efd8f36ca6133c6e0514bf7ed032f73568deb5d5e1683fd34d340b0
|
data/lib/ecs_deployer/client.rb
CHANGED
@@ -6,15 +6,16 @@ module EcsDeployer
|
|
6
6
|
class Client
|
7
7
|
PAULING_INTERVAL = 20
|
8
8
|
|
9
|
-
# @param [String]
|
9
|
+
# @param [String] cluster
|
10
10
|
# @param [Hash] options
|
11
11
|
# @option options [String] :profile
|
12
12
|
# @option options [String] :region
|
13
13
|
# @return [EcsDeployer::Client]
|
14
|
-
def initialize(
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
14
|
+
def initialize(cluster, options = {})
|
15
|
+
@cluster = cluster
|
16
|
+
@runtime = RuntimeCommand::Builder.new
|
17
|
+
@ecs_command = Commander.new(@runtime, options)
|
18
|
+
@family = ''
|
18
19
|
@revision = ''
|
19
20
|
@new_task_definition_arn = ''
|
20
21
|
end
|
@@ -29,42 +30,43 @@ module EcsDeployer
|
|
29
30
|
# @param [Hash] task_hash
|
30
31
|
# @return [String]
|
31
32
|
def register_task_hash(task_hash)
|
32
|
-
result = @ecs_command.register_task_definition(
|
33
|
-
task_hash['family'],
|
34
|
-
task_hash['containerDefinitions']
|
35
|
-
)
|
33
|
+
result = @ecs_command.register_task_definition(task_hash['family'], task_hash['containerDefinitions'])
|
36
34
|
|
37
|
-
@
|
35
|
+
@family = result['taskDefinition']['family']
|
38
36
|
@revision = result['taskDefinition']['revision']
|
39
37
|
@new_task_definition_arn = result['taskDefinition']['taskDefinitionArn']
|
40
38
|
end
|
41
39
|
|
42
|
-
# @param [String]
|
40
|
+
# @param [String] service
|
43
41
|
# @return [String]
|
44
|
-
def register_clone_task(
|
42
|
+
def register_clone_task(service)
|
45
43
|
detected_service = false
|
46
44
|
|
47
|
-
result = @ecs_command.describe_services(
|
48
|
-
result['services'].each do |
|
49
|
-
if
|
50
|
-
result = @ecs_command.describe_task_definition(
|
51
|
-
@new_task_definition_arn =
|
45
|
+
result = @ecs_command.describe_services([service], { 'cluster': @cluster })
|
46
|
+
result['services'].each do |svc|
|
47
|
+
if svc['serviceName'] == service
|
48
|
+
result = @ecs_command.describe_task_definition(svc['taskDefinition'])
|
49
|
+
@new_task_definition_arn = register_task_hash(result['taskDefinition'])
|
52
50
|
detected_service = true
|
53
51
|
break
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
|
-
raise ServiceNotFoundError.new("'#{
|
55
|
+
raise ServiceNotFoundError.new("'#{service}' service is not found.") unless detected_service
|
58
56
|
|
59
57
|
@new_task_definition_arn
|
60
58
|
end
|
61
59
|
|
62
|
-
# @param [String]
|
60
|
+
# @param [String] service
|
63
61
|
# @param [Fixnum] timeout
|
64
|
-
def update_service(
|
65
|
-
register_clone_task(
|
66
|
-
|
67
|
-
|
62
|
+
def update_service(service, wait = true, timeout = 600)
|
63
|
+
register_clone_task(service) if @new_task_definition_arn.empty?
|
64
|
+
options = {
|
65
|
+
'cluster': @cluster,
|
66
|
+
'task-definition': @family + ':' + @revision.to_s
|
67
|
+
}
|
68
|
+
@ecs_command.update_service(service, options)
|
69
|
+
wait_for_deploy(service, timeout) if wait
|
68
70
|
end
|
69
71
|
|
70
72
|
# @return [String]
|
@@ -73,60 +75,66 @@ module EcsDeployer
|
|
73
75
|
end
|
74
76
|
|
75
77
|
private
|
76
|
-
def wait_for_deploy(
|
78
|
+
def wait_for_deploy(service, timeout)
|
77
79
|
detected_service = false
|
78
80
|
|
79
|
-
result = @ecs_command.describe_services(
|
80
|
-
result['services'].each do |
|
81
|
-
next unless
|
81
|
+
result = @ecs_command.describe_services([service], { 'cluster': @cluster })
|
82
|
+
result['services'].each do |svc|
|
83
|
+
next unless svc['serviceName'] == service
|
82
84
|
detected_service = true
|
83
85
|
|
84
|
-
result = @ecs_command.describe_task_definition(
|
86
|
+
result = @ecs_command.describe_task_definition(svc['taskDefinition'])
|
85
87
|
|
86
|
-
if
|
88
|
+
if svc['desiredCount'] > 0
|
87
89
|
running_new_task = false
|
88
90
|
wait_time = 0
|
89
|
-
puts 'Start deploing...'
|
91
|
+
@runtime.puts 'Start deploing...'
|
90
92
|
|
91
93
|
begin
|
92
94
|
sleep(PAULING_INTERVAL)
|
93
95
|
wait_time += PAULING_INTERVAL
|
94
96
|
|
95
97
|
# Get current tasks
|
96
|
-
|
98
|
+
options = {
|
99
|
+
'cluster': @cluster,
|
100
|
+
'service-name': service,
|
101
|
+
'desired-status': 'RUNNING'
|
102
|
+
}
|
103
|
+
result = @ecs_command.list_tasks(options)
|
97
104
|
|
98
|
-
if result['taskArns'].size
|
99
|
-
success_count = 0
|
105
|
+
raise TaskNotFoundError.new('Desired count is 0.') if result['taskArns'].size == 0
|
100
106
|
|
101
|
-
|
102
|
-
|
103
|
-
success_count += 1 if @new_task_definition_arn == task['taskDefinitionArn']
|
104
|
-
end
|
105
|
-
|
106
|
-
if result['tasks'].size == success_count
|
107
|
-
puts 'Service update succeeded.'
|
108
|
-
puts "New task definition: #{@new_task_definition_arn}"
|
107
|
+
new_running_count = 0
|
108
|
+
result = @ecs_command.describe_tasks(result['taskArns'], { 'cluster': @cluster })
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
else
|
113
|
-
raise TaskNotFoundError.new('Desired count is 0.')
|
110
|
+
result['tasks'].each do |task|
|
111
|
+
new_running_count += 1 if @new_task_definition_arn == task['taskDefinitionArn']
|
114
112
|
end
|
115
113
|
|
116
|
-
|
117
|
-
puts "New task definition: #{@new_task_definition_arn}"
|
118
|
-
raise DeployTimeoutError.new('Service is being updating, but process is timed out.')
|
119
|
-
end
|
114
|
+
current_running_count = result['tasks'].size
|
120
115
|
|
121
|
-
|
116
|
+
if current_running_count == new_running_count
|
117
|
+
@runtime.puts "Service update succeeded. [#{new_running_count}/#{current_running_count}]"
|
118
|
+
@runtime.puts "New task definition: #{@new_task_definition_arn}"
|
122
119
|
|
120
|
+
running_new_task = true
|
121
|
+
|
122
|
+
else
|
123
|
+
@runtime.puts "Deploying... [#{new_running_count}/#{current_running_count}] (#{wait_time} seconds elapsed)"
|
124
|
+
@runtime.puts 'You can stop process with Ctrl+C. Deployment will continue.'
|
125
|
+
|
126
|
+
if wait_time > timeout
|
127
|
+
@runtime.puts "New task definition: #{@new_task_definition_arn}"
|
128
|
+
raise DeployTimeoutError.new('Service is being updating, but process is timed out.')
|
129
|
+
end
|
130
|
+
end
|
123
131
|
end while !running_new_task
|
124
132
|
end
|
125
133
|
|
126
134
|
break
|
127
135
|
end
|
128
136
|
|
129
|
-
raise ServiceNotFoundError.new("'#{
|
137
|
+
raise ServiceNotFoundError.new("'#{service}' service is not found.") unless detected_service
|
130
138
|
end
|
131
139
|
end
|
132
140
|
end
|
@@ -1,80 +1,61 @@
|
|
1
1
|
require 'oj'
|
2
|
-
require 'runtime_command'
|
3
2
|
|
4
3
|
module EcsDeployer
|
5
4
|
class Commander
|
6
|
-
# @param [
|
5
|
+
# @param [RuntimeCommand::Builder] runtime
|
7
6
|
# @param [Hash] options
|
8
7
|
# @return EcsDeployer::Commander
|
9
|
-
def initialize(
|
10
|
-
@runtime =
|
8
|
+
def initialize(runtime, options = {})
|
9
|
+
@runtime = runtime
|
11
10
|
@options = options
|
12
|
-
@cluster_name = cluster_name
|
13
11
|
end
|
14
12
|
|
15
|
-
# @param [String]
|
16
|
-
# @param [
|
17
|
-
# @param [Fixnum] revision
|
13
|
+
# @param [String] service
|
14
|
+
# @param [Hash] options
|
18
15
|
# @return [Hash]
|
19
|
-
def update_service(
|
20
|
-
|
21
|
-
|
22
|
-
'service': service_name,
|
23
|
-
'task-definition': family_name + ':' + revision.to_s
|
24
|
-
}
|
25
|
-
|
26
|
-
exec('update-service', args)
|
16
|
+
def update_service(service, options = {})
|
17
|
+
options['service'] = service
|
18
|
+
exec('update-service', options)
|
27
19
|
end
|
28
20
|
|
29
|
-
# @param [
|
21
|
+
# @param [Hash] options
|
30
22
|
# @return [Hash]
|
31
|
-
def list_tasks(
|
32
|
-
|
33
|
-
'cluster': @cluster_name,
|
34
|
-
'service-name': service_name,
|
35
|
-
'desired-status': 'RUNNING'
|
36
|
-
}
|
37
|
-
exec('list-tasks', args)
|
23
|
+
def list_tasks(options = {})
|
24
|
+
exec('list-tasks', options)
|
38
25
|
end
|
39
26
|
|
40
27
|
# @param [Array] tasks
|
28
|
+
# @param [Hash] options
|
41
29
|
# @return [Hash]
|
42
|
-
def describe_tasks(tasks)
|
43
|
-
|
44
|
-
|
45
|
-
'tasks': tasks.join(' ')
|
46
|
-
}
|
47
|
-
exec('describe-tasks', args)
|
30
|
+
def describe_tasks(tasks, options = {})
|
31
|
+
options['tasks'] = tasks.join(' ')
|
32
|
+
exec('describe-tasks', options)
|
48
33
|
end
|
49
34
|
|
50
35
|
# @param [String] task_definition
|
36
|
+
# @param [Hash] options
|
51
37
|
# @return [Hash]
|
52
|
-
def describe_task_definition(task_definition)
|
53
|
-
|
54
|
-
|
55
|
-
}
|
56
|
-
exec('describe-task-definition', args)
|
38
|
+
def describe_task_definition(task_definition, options = {})
|
39
|
+
options['task-definition'] = task_definition
|
40
|
+
exec('describe-task-definition', options)
|
57
41
|
end
|
58
42
|
|
59
|
-
# @param [
|
43
|
+
# @param [Array] services
|
44
|
+
# @param [Hash] options
|
60
45
|
# @return [Hash]
|
61
|
-
def describe_services(
|
62
|
-
|
63
|
-
|
64
|
-
'services': service_name
|
65
|
-
}
|
66
|
-
exec('describe-services', args)
|
46
|
+
def describe_services(services, options = {})
|
47
|
+
options['services'] = services.join(' ')
|
48
|
+
exec('describe-services', options)
|
67
49
|
end
|
68
50
|
|
69
|
-
# @param [String]
|
51
|
+
# @param [String] family
|
70
52
|
# @param [Hash] container_definitions
|
53
|
+
# @param [Hash] options
|
71
54
|
# @return [Hash]
|
72
|
-
def register_task_definition(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
}
|
77
|
-
exec('register-task-definition', args)
|
55
|
+
def register_task_definition(family, container_definitions, options = {})
|
56
|
+
options['family'] = family
|
57
|
+
options['container-definitions'] = '"' + Oj.dump(container_definitions).gsub('"', '\\"') + '"'
|
58
|
+
exec('register-task-definition', options)
|
78
59
|
end
|
79
60
|
|
80
61
|
# @return [String]
|
@@ -84,24 +65,23 @@ module EcsDeployer
|
|
84
65
|
|
85
66
|
private
|
86
67
|
# @param [String] command
|
87
|
-
# @param [Hash]
|
68
|
+
# @param [Hash] params
|
88
69
|
# @return [Hash]
|
89
|
-
def exec(command,
|
70
|
+
def exec(command, params)
|
90
71
|
arg = ''
|
91
|
-
|
72
|
+
params.each do |name, value|
|
92
73
|
arg << "--#{name} #{value} "
|
93
74
|
end
|
94
75
|
|
95
|
-
arg << "--profile #{
|
96
|
-
arg << "--region #{
|
76
|
+
arg << "--profile #{params[:profile]} " if params.has_key?(:profile)
|
77
|
+
arg << "--region #{params[:region]} " if params.has_key?(:region)
|
97
78
|
|
98
79
|
command = "aws ecs #{command} #{arg}"
|
99
80
|
result = @runtime.exec(command)
|
100
81
|
|
101
82
|
raise CommandError.new unless result.buffered_stderr.empty?
|
102
83
|
|
103
|
-
result
|
104
|
-
Oj.load(result)
|
84
|
+
Oj.load(result.buffered_stdout)
|
105
85
|
end
|
106
86
|
end
|
107
87
|
end
|
data/lib/ecs_deployer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecs_deployer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- naomichi-y
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: runtime_command
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
124
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.6.10
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Deploy application to ECS.
|