ecs_deployer 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 022b3442f88234d68a859aea13ab1be47f7d357b
4
- data.tar.gz: 62578b367ebf2d506b745d304068a1ac07ccd3cd
3
+ metadata.gz: 5fd6d6f9f5273217eda74eb3591b68d995756699
4
+ data.tar.gz: b8c28e3077e600f1819af1c5962b72932304a83f
5
5
  SHA512:
6
- metadata.gz: 590fb52f78f7181d1e1a2cf2c8a68dfb0847718aa9a2ee84d4d61ec1d55bf8a0f7d74fdc7abd89491ea0d5b0def2fb4c3a7bcf7af6c19a47cfbf9588c7d488e3
7
- data.tar.gz: ac1d5b859568aa7f6d5efb95c0f5f62faef1d17ba247b870c3424600bb065af54e9d3356299a04473277aab4212075ad165126704ba4e431093ee248ecf2963c
6
+ metadata.gz: 7cf7d00b7a60e0f4adeab84e64195c7461ac652c94589a60c0258ae1a8dd279b06e82f172370314e88f7e0c89e19f714b0c9e73f3f6f4294385dd95cb397627c
7
+ data.tar.gz: a827047b284fb20d6c1418b774b4bb624e309e33b7a63f7cd4dab61c331f3b9bd0cbd111cfae6d2fe7453b45c045acbdf939611b6bfb8f158881f1b8649d44f8
data/README.md CHANGED
@@ -25,14 +25,14 @@ For available parameters see [Task Definition Parameters](http://docs.aws.amazon
25
25
  The sample file is in `example/fixtures/task.yml`.
26
26
 
27
27
  ```
28
- containerDefinitions:
28
+ container_definitions:
29
29
  - name: wordpress
30
30
  links:
31
31
  - mysql
32
32
  image: wordpress
33
33
  essential: true
34
- portMappings:
35
- - containerPort: 80
34
+ port_mappings:
35
+ - container_port: 80
36
36
  hostPort: 80
37
37
  memory: 500
38
38
  cpu: 10
@@ -50,7 +50,7 @@ family: hello_world
50
50
  ## Usage
51
51
 
52
52
  ```
53
- ecs_deployer = EcsDeployer::Client.new()
53
+ ecs_deployer = EcsDeployer::Client.new
54
54
  ecs_deployer.register_task('development.yml')
55
- ecs_deployer.update_service('cluster', 'application')
55
+ ecs_deployer.update_service('cluster', 'development')
56
56
  ```
data/ecs_deployer.gemspec CHANGED
@@ -29,8 +29,11 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
- spec.add_dependency 'runtime_command'
33
- spec.add_dependency 'oj'
32
+ spec.add_dependency "runtime_command"
33
+ spec.add_dependency "oj"
34
+ spec.add_dependency "thor"
35
+ spec.add_dependency "aws-sdk"
36
+ spec.add_dependency "aws_config"
34
37
  spec.add_development_dependency "bundler", "~> 1.14"
35
38
  spec.add_development_dependency "rake", "~> 10.0"
36
39
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -1,12 +1,12 @@
1
- containerDefinitions:
1
+ container_definitions:
2
2
  - name: wordpress
3
3
  links:
4
4
  - mysql
5
5
  image: wordpress
6
6
  essential: true
7
- portMappings:
8
- - containerPort: 80
9
- hostPort: 80
7
+ port_mappings:
8
+ - container_port: 80
9
+ host_port: 80
10
10
  memory: 500
11
11
  cpu: 10
12
12
  - environment:
data/example/sample.rb CHANGED
@@ -3,7 +3,6 @@ require 'ecs_deployer'
3
3
 
4
4
  task_path = File.expand_path('./fixtures/task.yml', File.dirname(File.realpath(__FILE__)))
5
5
 
6
- ecs_deployer = EcsDeployer::Client.new('sandbox-ecs-production')
6
+ ecs_deployer = EcsDeployer::Client.new
7
7
  ecs_deployer.register_task(task_path)
8
- ecs_deployer.update_service('application')
9
- #ecs_deployer.log
8
+ # ecs_deployer.update_service('sandbox', 'production')
data/exe/ecs_deployer ADDED
@@ -0,0 +1,3 @@
1
+ require 'ecs_deployer'
2
+
3
+ EcsDeployer::CLI.start
@@ -0,0 +1,10 @@
1
+ require 'thor'
2
+
3
+ module EcsDeployer
4
+ class CLI < Thor
5
+ desc 'hello', 'world'
6
+ def update
7
+ puts 'hello'
8
+ end
9
+ end
10
+ end
@@ -1,21 +1,24 @@
1
1
  require 'yaml'
2
+ require 'oj'
3
+ require 'aws-sdk'
2
4
  require 'runtime_command'
3
- require 'ecs_deployer/commander'
4
5
 
5
6
  module EcsDeployer
6
7
  class Client
7
8
  PAULING_INTERVAL = 20
8
9
 
10
+ attr_reader :commander
11
+
9
12
  # @param [Hash] options
10
13
  # @option options [String] :profile
11
14
  # @option options [String] :region
12
15
  # @return [EcsDeployer::Client]
13
16
  def initialize(options = {})
14
- @runtime = RuntimeCommand::Builder.new
15
- @ecs_command = Commander.new(@runtime, options)
17
+ @command = RuntimeCommand::Builder.new
16
18
  @family = ''
17
19
  @revision = ''
18
20
  @new_task_definition_arn = ''
21
+ @commander = Aws::ECS::Client.new(options)
19
22
  end
20
23
 
21
24
  # @param [String] task_path
@@ -28,11 +31,17 @@ module EcsDeployer
28
31
  # @param [Hash] task_hash
29
32
  # @return [String]
30
33
  def register_task_hash(task_hash)
31
- result = @ecs_command.register_task_definition(task_hash['family'], task_hash['containerDefinitions'])
34
+ task_hash = Oj.load(Oj.dump(task_hash), symbol_keys: true)
35
+
36
+ result = @commander.register_task_definition({
37
+ container_definitions: task_hash[:container_definitions],
38
+ family: task_hash[:family],
39
+ task_role_arn: task_hash[:task_role_arn]
40
+ })
32
41
 
33
- @family = result['taskDefinition']['family']
34
- @revision = result['taskDefinition']['revision']
35
- @new_task_definition_arn = result['taskDefinition']['taskDefinitionArn']
42
+ @family = result[:task_definition][:family]
43
+ @revision = result[:task_definition][:revision]
44
+ @new_task_definition_arn = result[:task_definition][:task_definition_arn]
36
45
  end
37
46
 
38
47
  # @param [String] cluster
@@ -41,11 +50,17 @@ module EcsDeployer
41
50
  def register_clone_task(cluster, service)
42
51
  detected_service = false
43
52
 
44
- result = @ecs_command.describe_services([service], { 'cluster': cluster })
45
- result['services'].each do |svc|
46
- if svc['serviceName'] == service
47
- result = @ecs_command.describe_task_definition(svc['taskDefinition'])
48
- @new_task_definition_arn = register_task_hash(result['taskDefinition'])
53
+ result = @commander.describe_services({
54
+ cluster: cluster,
55
+ services: [service]
56
+ })
57
+
58
+ result[:services].each do |svc|
59
+ if svc[:service_name] == service
60
+ result = @commander.describe_task_definition({
61
+ task_definition: svc[:task_definition]
62
+ })
63
+ @new_task_definition_arn = register_task_hash(result[:task_definition])
49
64
  detected_service = true
50
65
  break
51
66
  end
@@ -61,17 +76,13 @@ module EcsDeployer
61
76
  # @param [Fixnum] timeout
62
77
  def update_service(cluster, service, wait = true, timeout = 600)
63
78
  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(cluster, service, timeout) if wait
70
- end
71
79
 
72
- # @return [String]
73
- def log
74
- @ecs_command.log
80
+ @commander.update_service({
81
+ cluster: cluster,
82
+ service: service,
83
+ task_definition: @family + ':' + @revision.to_s
84
+ })
85
+ wait_for_deploy(cluster, service, timeout) if wait
75
86
  end
76
87
 
77
88
  private
@@ -81,53 +92,61 @@ module EcsDeployer
81
92
  def wait_for_deploy(cluster, service, timeout)
82
93
  detected_service = false
83
94
 
84
- result = @ecs_command.describe_services([service], { 'cluster': cluster })
85
- result['services'].each do |svc|
86
- next unless svc['serviceName'] == service
95
+ result = @commander.describe_services({
96
+ cluster: cluster,
97
+ services: [service]
98
+ })
99
+ result[:services].each do |svc|
100
+ next unless svc[:service_name] == service
87
101
  detected_service = true
88
102
 
89
- result = @ecs_command.describe_task_definition(svc['taskDefinition'])
103
+ result = @commander.describe_task_definition({
104
+ task_definition: svc[:task_definition]
105
+ })
90
106
 
91
- if svc['desiredCount'] > 0
107
+ if svc[:desired_count] > 0
92
108
  running_new_task = false
93
109
  wait_time = 0
94
- @runtime.puts 'Start deploing...'
110
+ @command.puts 'Start deploing...'
95
111
 
96
112
  begin
97
113
  sleep(PAULING_INTERVAL)
98
114
  wait_time += PAULING_INTERVAL
99
115
 
100
116
  # Get current tasks
101
- options = {
102
- 'cluster': cluster,
103
- 'service-name': service,
104
- 'desired-status': 'RUNNING'
105
- }
106
- result = @ecs_command.list_tasks(options)
117
+ result = @commander.list_tasks({
118
+ cluster: cluster,
119
+ service_name: service,
120
+ desired_status: 'RUNNING'
121
+ })
107
122
 
108
- raise TaskNotFoundError.new('Desired count is 0.') if result['taskArns'].size == 0
123
+ raise TaskNotFoundError.new('Desired count is 0.') if result[:task_arns].size == 0
109
124
 
110
125
  new_running_count = 0
111
- result = @ecs_command.describe_tasks(result['taskArns'], { 'cluster': cluster })
126
+ result = @commander.describe_tasks({
127
+ tasks: result[:task_arns],
128
+ cluster: cluster
129
+ })
112
130
 
113
- result['tasks'].each do |task|
114
- new_running_count += 1 if @new_task_definition_arn == task['taskDefinitionArn']
131
+ result[:tasks].each do |task|
132
+ new_running_count += 1 if @new_task_definition_arn == task[:task_definition_arn]
115
133
  end
116
134
 
117
- current_running_count = result['tasks'].size
135
+ current_running_count = result[:tasks].size
118
136
 
119
137
  if current_running_count == new_running_count
120
- @runtime.puts "Service update succeeded. [#{new_running_count}/#{current_running_count}]"
121
- @runtime.puts "New task definition: #{@new_task_definition_arn}"
138
+ @command.puts "Service update succeeded. [#{new_running_count}/#{current_running_count}]"
139
+ @command.puts "New task definition: #{@new_task_definition_arn}"
122
140
 
123
141
  running_new_task = true
124
142
 
125
143
  else
126
- @runtime.puts "Deploying... [#{new_running_count}/#{current_running_count}] (#{wait_time} seconds elapsed)"
127
- @runtime.puts 'You can stop process with Ctrl+C. Deployment will continue.'
144
+ @command.puts "Deploying... [#{new_running_count}/#{current_running_count}] (#{wait_time} seconds elapsed)"
145
+ @command.puts "New task: #{@new_task_definition_arn}"
146
+ @command.puts 'You can stop process with Ctrl+C. Deployment will continue.'
128
147
 
129
148
  if wait_time > timeout
130
- @runtime.puts "New task definition: #{@new_task_definition_arn}"
149
+ @command.puts "New task definition: #{@new_task_definition_arn}"
131
150
  raise DeployTimeoutError.new('Service is being updating, but process is timed out.')
132
151
  end
133
152
  end
@@ -1,3 +1,3 @@
1
1
  module EcsDeployer
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/ecs_deployer.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'ecs_deployer/version'
2
2
  require 'ecs_deployer/client'
3
3
  require 'ecs_deployer/error'
4
+ require 'ecs_deployer/cli'
4
5
 
5
6
  module EcsDeployer
6
7
  class ServiceNotFoundError < EcsDeployer::Error; end
7
8
  class TaskNotFoundError < EcsDeployer::Error; end
8
9
  class DeployTimeoutError < EcsDeployer::Error; end
9
- class CommandError < EcsDeployer::Error; end
10
10
  end
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.5
4
+ version: 0.1.7
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-03-01 00:00:00.000000000 Z
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: runtime_command
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws_config
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: bundler
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +125,8 @@ dependencies:
83
125
  description: This package provides the service deployment function of ECS.
84
126
  email:
85
127
  - n.yamakita@gmail.com
86
- executables: []
128
+ executables:
129
+ - ecs_deployer
87
130
  extensions: []
88
131
  extra_rdoc_files: []
89
132
  files:
@@ -98,9 +141,10 @@ files:
98
141
  - ecs_deployer.gemspec
99
142
  - example/fixtures/task.yml
100
143
  - example/sample.rb
144
+ - exe/ecs_deployer
101
145
  - lib/ecs_deployer.rb
146
+ - lib/ecs_deployer/cli.rb
102
147
  - lib/ecs_deployer/client.rb
103
- - lib/ecs_deployer/commander.rb
104
148
  - lib/ecs_deployer/error.rb
105
149
  - lib/ecs_deployer/version.rb
106
150
  homepage: https://github.com/naomichi-y/ecs_deployer
@@ -1,87 +0,0 @@
1
- require 'oj'
2
-
3
- module EcsDeployer
4
- class Commander
5
- # @param [RuntimeCommand::Builder] runtime
6
- # @param [Hash] options
7
- # @return EcsDeployer::Commander
8
- def initialize(runtime, options = {})
9
- @runtime = runtime
10
- @options = options
11
- end
12
-
13
- # @param [String] service
14
- # @param [Hash] options
15
- # @return [Hash]
16
- def update_service(service, options = {})
17
- options['service'] = service
18
- exec('update-service', options)
19
- end
20
-
21
- # @param [Hash] options
22
- # @return [Hash]
23
- def list_tasks(options = {})
24
- exec('list-tasks', options)
25
- end
26
-
27
- # @param [Array] tasks
28
- # @param [Hash] options
29
- # @return [Hash]
30
- def describe_tasks(tasks, options = {})
31
- options['tasks'] = tasks.join(' ')
32
- exec('describe-tasks', options)
33
- end
34
-
35
- # @param [String] task_definition
36
- # @param [Hash] options
37
- # @return [Hash]
38
- def describe_task_definition(task_definition, options = {})
39
- options['task-definition'] = task_definition
40
- exec('describe-task-definition', options)
41
- end
42
-
43
- # @param [Array] services
44
- # @param [Hash] options
45
- # @return [Hash]
46
- def describe_services(services, options = {})
47
- options['services'] = services.join(' ')
48
- exec('describe-services', options)
49
- end
50
-
51
- # @param [String] family
52
- # @param [Hash] container_definitions
53
- # @param [Hash] options
54
- # @return [Hash]
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)
59
- end
60
-
61
- # @return [String]
62
- def log
63
- @runtime.buffered_log
64
- end
65
-
66
- private
67
- # @param [String] command
68
- # @param [Hash] params
69
- # @return [Hash]
70
- def exec(command, params)
71
- arg = ''
72
- params.each do |name, value|
73
- arg << "--#{name} #{value} "
74
- end
75
-
76
- arg << "--profile #{params[:profile]} " if params.has_key?(:profile)
77
- arg << "--region #{params[:region]} " if params.has_key?(:region)
78
-
79
- command = "aws ecs #{command} #{arg}"
80
- result = @runtime.exec(command)
81
-
82
- raise CommandError.new unless result.buffered_stderr.empty?
83
-
84
- Oj.load(result.buffered_stdout)
85
- end
86
- end
87
- end