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 +4 -4
- data/lib/opsworks/app.rb +1 -7
- data/lib/opsworks/cli/helpers/options.rb +1 -1
- data/lib/opsworks/cli/subcommands/deploy.rb +10 -2
- data/lib/opsworks/cli/subcommands/exec.rb +10 -2
- data/lib/opsworks/cli/subcommands/status.rb +1 -1
- data/lib/opsworks/cli/subcommands/update.rb +10 -2
- data/lib/opsworks/cli/version.rb +1 -1
- data/lib/opsworks/deployment.rb +49 -0
- data/lib/opsworks/stack.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18ef86da686c271e0ca39400b1fdfd653933f038
|
4
|
+
data.tar.gz: 49fdede59882e9141496a5421857b5e25c052c15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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,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.
|
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.
|
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
|
@@ -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.
|
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
|
data/lib/opsworks/cli/version.rb
CHANGED
data/lib/opsworks/deployment.rb
CHANGED
@@ -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
|
data/lib/opsworks/stack.rb
CHANGED
@@ -52,7 +52,10 @@ module OpsWorks
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def create_deployment(options = {})
|
55
|
-
self.class.client.create_deployment(
|
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.
|
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-
|
11
|
+
date: 2014-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|