opsworks-cli 0.1.2 → 0.2.0

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
2
  SHA1:
3
- metadata.gz: d80d65b9937273607a19fc3ea4eecd4f1b15311a
4
- data.tar.gz: a0200344f6e62a71341c51584e5893d6e8b68de5
3
+ metadata.gz: 18ef86da686c271e0ca39400b1fdfd653933f038
4
+ data.tar.gz: 49fdede59882e9141496a5421857b5e25c052c15
5
5
  SHA512:
6
- metadata.gz: f8847f8697a405dd22a31a16751623a2b429788cdf0c9fd31ea51b2d6a1c4c9e885872fe7c6d0ddba84d4c3e3310e5cb11df3e42b72e1dffa21c055dfc42e911
7
- data.tar.gz: f6b8a09606fda4acbfbc600562a60782a6afbfe29cc68fe0b787d144adff694aa2baa4d67dfed8cd0da4ed274896f1b4bf259532ac60e0e410493e846492a7d3
6
+ metadata.gz: ee72de4769bfa43179a859bbc512cfadc4ba5342103ea9de8cbd5f653a21d988b7810f589753e2cf1b6dcb9406df4e9f42585ec1dee35ad57b9d6274da2c3faa
7
+ data.tar.gz: a58f99d1895c9f4bf4f673c739387717c464ad1b45064766c77e5d53283f7eafbb285d9515e96cf8a0093ce264e3104eefc8cffb36583bfd8bd44f5331826493
data/lib/opsworks/app.rb CHANGED
@@ -18,13 +18,7 @@ module OpsWorks
18
18
  def initialize_deployments
19
19
  return [] unless id
20
20
  response = self.class.client.describe_deployments(app_id: id)
21
- response.data[:deployments].map do |hash|
22
- Deployment.new(
23
- id: hash[:deployment_id],
24
- created_at: hash[:created_at],
25
- status: hash[:status]
26
- )
27
- end
21
+ Deployment.from_collection_response(response)
28
22
  end
29
23
  end
30
24
  end
@@ -7,7 +7,7 @@ module OpsWorks
7
7
  def parse_stacks(options = {})
8
8
  stacks = OpsWorks::Stack.all
9
9
  if options[:stack]
10
- stacks.select! { |stack| stack.name == options[:stack] }
10
+ stacks.select! { |stack| options[:stack].include?(stack.name) }
11
11
  end
12
12
  stacks
13
13
  end
@@ -7,15 +7,23 @@ module OpsWorks
7
7
  def self.included(thor)
8
8
  thor.class_eval do
9
9
  desc 'deploy [--stack STACK] APP', 'Deploy an OpsWorks app'
10
- option :stack
10
+ option :stack, type: :array
11
11
  def deploy(name)
12
12
  fetch_keychain_credentials unless env_credentials?
13
13
  stacks = parse_stacks(options)
14
- stacks.each do |stack|
14
+ deployments = stacks.map do |stack|
15
15
  next unless (app = stack.find_app_by_name(name))
16
16
  say "Deploying to #{stack.name}..."
17
17
  stack.deploy_app(app)
18
18
  end
19
+ Deployment.wait(deployments)
20
+ unless deployments.all?(&:success?)
21
+ failures = []
22
+ deployments.each_with_index do |deployment, i|
23
+ failures << stacks[i].name if deployment.failed?
24
+ end
25
+ fail "Deploy failed on #{failures.join(', ')}"
26
+ end
19
27
  end
20
28
  end
21
29
  end
@@ -7,14 +7,22 @@ module OpsWorks
7
7
  def self.included(thor)
8
8
  thor.class_eval do
9
9
  desc 'exec [--stack STACK] RECIPE', 'Execute a Chef recipe'
10
- option :stack
10
+ option :stack, type: :array
11
11
  def exec(recipe)
12
12
  fetch_keychain_credentials unless env_credentials?
13
13
  stacks = parse_stacks(options)
14
- stacks.each do |stack|
14
+ deployments = stacks.map do |stack|
15
15
  say "Executing recipe on #{stack.name}..."
16
16
  stack.execute_recipe(recipe)
17
17
  end
18
+ Deployment.wait(deployments)
19
+ unless deployments.all?(&:success?)
20
+ failures = []
21
+ deployments.each_with_index do |deployment, i|
22
+ failures << stacks[i].name if deployment.failed?
23
+ end
24
+ fail "Command failed on #{failures.join(', ')}"
25
+ end
18
26
  end
19
27
  end
20
28
  end
@@ -11,7 +11,7 @@ module OpsWorks
11
11
 
12
12
  desc 'status [--stack STACK] APP',
13
13
  'Display the most recent deployment of an app'
14
- option :stack
14
+ option :stack, type: :array
15
15
  def status(name)
16
16
  fetch_keychain_credentials unless env_credentials?
17
17
 
@@ -12,14 +12,22 @@ module OpsWorks
12
12
  include Helpers::Options
13
13
 
14
14
  desc 'update [--stack STACK]', 'Update OpsWorks custom cookbooks'
15
- option :stack
15
+ option :stack, type: :array
16
16
  def update
17
17
  fetch_keychain_credentials unless env_credentials?
18
18
  stacks = parse_stacks(options)
19
- stacks.each do |stack|
19
+ deployments = stacks.map do |stack|
20
20
  say "Updating #{stack.name}..."
21
21
  stack.update_custom_cookbooks
22
22
  end
23
+ Deployment.wait(deployments)
24
+ unless deployments.all?(&:success?)
25
+ failures = []
26
+ deployments.each_with_index do |deployment, i|
27
+ failures << stacks[i].name if deployment.failed?
28
+ end
29
+ fail "Update failed on #{failures.join(', ')}"
30
+ end
23
31
  end
24
32
  end
25
33
  end
@@ -1,5 +1,5 @@
1
1
  module OpsWorks
2
2
  module CLI
3
- VERSION = '0.1.2'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -4,10 +4,59 @@ module OpsWorks
4
4
  class Deployment < Resource
5
5
  attr_accessor :id, :status, :created_at
6
6
 
7
+ POLL_INTERVAL = 5
8
+
9
+ # rubocop:disable MethodLength
10
+ def self.wait(deployments)
11
+ while deployments.any?(&:running?)
12
+ sleep POLL_INTERVAL
13
+ response = client.describe_deployments(
14
+ deployment_ids: deployments.map(&:id)
15
+ )
16
+ updates = from_collection_response(response)
17
+ deployments.each do |deployment|
18
+ update = updates.find { |u| u.id == deployment.id }
19
+ deployment.status = update.status
20
+ end
21
+ end
22
+ end
23
+ # rubocop:enble MethodLength
24
+
25
+ def self.from_collection_response(response)
26
+ response.data[:deployments].map do |hash|
27
+ new(
28
+ id: hash[:deployment_id],
29
+ created_at: hash[:created_at],
30
+ status: hash[:status]
31
+ )
32
+ end
33
+ end
34
+
35
+ def self.from_response(response)
36
+ new(id: response[:deployment_id])
37
+ end
38
+
39
+ def wait
40
+ while deployment.running?
41
+ sleep POLL_INTERVAL
42
+ response = client.describe_deployments(deployment_ids: [id])
43
+ update = from_collection_response(response).first
44
+ deployment.status = update.status
45
+ end
46
+ end
47
+
48
+ def running?
49
+ status.nil? || status == 'running'
50
+ end
51
+
7
52
  def success?
8
53
  status == 'successful'
9
54
  end
10
55
 
56
+ def failed?
57
+ status == 'failed'
58
+ end
59
+
11
60
  def created_at
12
61
  Time.parse(@created_at)
13
62
  rescue
@@ -52,7 +52,10 @@ module OpsWorks
52
52
  end
53
53
 
54
54
  def create_deployment(options = {})
55
- self.class.client.create_deployment(options.merge(stack_id: id))
55
+ response = self.class.client.create_deployment(
56
+ options.merge(stack_id: id)
57
+ )
58
+ Deployment.from_response(response)
56
59
  end
57
60
  end
58
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsworks-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-19 00:00:00.000000000 Z
11
+ date: 2014-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor