infopark_opsworks_helpers 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/opsworks_helpers.rb +5 -0
- data/lib/opsworks_helpers/app.rb +19 -0
- data/lib/opsworks_helpers/deployment.rb +56 -0
- data/lib/opsworks_helpers/opsworks_client.rb +23 -0
- data/lib/opsworks_helpers/opsworks_resource.rb +32 -0
- data/lib/opsworks_helpers/stack.rb +15 -0
- data/lib/opsworks_helpers/version.rb +1 -1
- data/lib/tasks/opsworks_helpers_tasks.rake +33 -11
- metadata +11 -7
- data/lib/opsworks_helpers/deploy.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f49eee75c534efa1ecb3a0daca009e49a65eda9
|
4
|
+
data.tar.gz: e5ce0be36b95a120d4895e911cf8b6abacfa89bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2cbb1f318536d2d66d647a305f8731d276956615212c390af5e6819dd6a52a2bc15332061a4926d37a676acb79e52ee6acf90f61b8eee5da0cff5e94877ad16
|
7
|
+
data.tar.gz: cc09ab81354530ab05ad029e65058e1cc664a0b7afe82fa837381778e93c36b4e47e85dd1002129f654818cb51acda1a8aab42cf2bf6ad7f3412614343bfbea6
|
data/lib/opsworks_helpers.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
require "opsworks_helpers/engine"
|
2
2
|
require "opsworks_helpers/status_checks"
|
3
|
+
require "opsworks_helpers/opsworks_client"
|
4
|
+
require "opsworks_helpers/opsworks_resource"
|
5
|
+
require "opsworks_helpers/deployment"
|
6
|
+
require "opsworks_helpers/stack"
|
7
|
+
require "opsworks_helpers/app"
|
3
8
|
|
4
9
|
module OpsworksHelpers
|
5
10
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module OpsworksHelpers
|
2
|
+
class App < OpsworksResource
|
3
|
+
|
4
|
+
def self.all(stack_id)
|
5
|
+
new.all(stack_id)
|
6
|
+
end
|
7
|
+
|
8
|
+
def all(stack_id)
|
9
|
+
opsworks.describe_apps(stack_id: stack_id).apps.map do |app|
|
10
|
+
self.class.new(app)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def id
|
15
|
+
opsworks_resource.app_id
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
begin
|
2
|
+
require 'aws-sdk'
|
3
|
+
rescue LoadError
|
4
|
+
fail 'Please add `aws-sdk` to your Gemfile if you want to use the deployment features.'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'pry'
|
8
|
+
module OpsworksHelpers
|
9
|
+
class Deployment < OpsworksResource
|
10
|
+
|
11
|
+
attr_accessor :command
|
12
|
+
|
13
|
+
def id
|
14
|
+
opsworks_resource.deployment_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def command_name
|
18
|
+
command[:name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def create(command, comment: 'Run via in-app rake task')
|
22
|
+
@command = command
|
23
|
+
|
24
|
+
@opsworks_resource = opsworks.create_deployment(
|
25
|
+
stack_id: stack_id,
|
26
|
+
app_id: app_id,
|
27
|
+
command: command,
|
28
|
+
comment: comment
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def deploy(stack:nil, app:nil, comment:nil)
|
33
|
+
@stack_id = stack if stack
|
34
|
+
@app_id = app if app
|
35
|
+
|
36
|
+
@command = {
|
37
|
+
name: 'deploy',
|
38
|
+
args: { migrate: ['true'] }
|
39
|
+
}
|
40
|
+
create(command, comment: comment)
|
41
|
+
end
|
42
|
+
|
43
|
+
def display_deployment_result
|
44
|
+
begin
|
45
|
+
puts "[#{id}] Waiting for command '#{command_name}' to finish..."
|
46
|
+
opsworks.wait_until(:deployment_successful, deployment_ids: [id])
|
47
|
+
puts "[#{id}] Command '#{command_name}' successful."
|
48
|
+
true
|
49
|
+
rescue ::Aws::Waiters::Errors::WaiterFailed => e
|
50
|
+
puts "[#{id}] Command '#{command_name}' failed. Message: #{e.message}"
|
51
|
+
false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module OpsworksHelpers
|
2
|
+
module OpsworksClient
|
3
|
+
|
4
|
+
attr_accessor :stack_id, :app_id
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def opsworks
|
9
|
+
@opsworks ||= Aws::OpsWorks::Client.new(region: 'us-east-1')
|
10
|
+
end
|
11
|
+
|
12
|
+
def stack_id
|
13
|
+
@stack_id || ENV['AWS_OPSWORKS_STACK_ID'] ||
|
14
|
+
fail('Please provide AWS_OPSWORKS_STACK_ID in env.')
|
15
|
+
end
|
16
|
+
|
17
|
+
def app_id
|
18
|
+
@app_id || ENV['AWS_OPSWORKS_APP_ID'] ||
|
19
|
+
fail('Please provide AWS_OPSWORKS_APP_ID in env.')
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module OpsworksHelpers
|
2
|
+
class OpsworksResource
|
3
|
+
include OpsworksClient
|
4
|
+
|
5
|
+
def self.all
|
6
|
+
new.all
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(resource=nil)
|
10
|
+
@opsworks_resource = resource
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
string = "#<#{self.class.name}:#{self.object_id} "
|
15
|
+
fields = inspect_fields.map{|field| "#{field}: #{self.send(field)}"}
|
16
|
+
string << fields.join(", ") << ">"
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
opsworks_resource.name
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_accessor :opsworks_resource
|
26
|
+
|
27
|
+
def inspect_fields
|
28
|
+
%i(id name)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -1,30 +1,52 @@
|
|
1
1
|
begin
|
2
|
-
require 'opsworks_helpers/
|
2
|
+
require 'opsworks_helpers/deployment'
|
3
3
|
rescue
|
4
4
|
end
|
5
5
|
|
6
|
-
if defined?(OpsworksHelpers::
|
6
|
+
if defined?(OpsworksHelpers::Deployment)
|
7
7
|
namespace 'opsworks' do
|
8
8
|
|
9
|
-
client = OpsworksHelpers::
|
9
|
+
client = OpsworksHelpers::Deployment.new
|
10
10
|
|
11
11
|
desc 'Deploy application to stack (and migrate database)'
|
12
12
|
task :deploy => :environment do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
stacks = OpsworksHelpers::Stack.all
|
14
|
+
stack_id = if stacks.size > 1
|
15
|
+
STDOUT.puts 'Which stack?'
|
16
|
+
stacks.each_with_index do |stack, index|
|
17
|
+
STDOUT.puts "#{index + 1}. #{stack.name}"
|
18
|
+
end
|
19
|
+
input = STDIN.gets.chomp.to_i
|
20
|
+
|
21
|
+
stacks[input - 1].id
|
22
|
+
else
|
23
|
+
stacks[0].id
|
24
|
+
end
|
25
|
+
|
26
|
+
apps = OpsworksHelpers::App.all(stack_id)
|
27
|
+
app_id = if apps.size > 1
|
28
|
+
STDOUT.puts "\nWhich app?"
|
29
|
+
apps.each_with_index do |app, index|
|
30
|
+
STDOUT.puts "#{index + 1}. #{app.name}"
|
31
|
+
end
|
32
|
+
input = STDIN.gets.chomp.to_i
|
33
|
+
|
34
|
+
apps[input - 1].id
|
35
|
+
else
|
36
|
+
apps[0].id
|
37
|
+
end
|
38
|
+
|
39
|
+
deployment = client.deploy(stack: stack_id, app: app_id)
|
18
40
|
|
19
|
-
client.display_deployment_result
|
41
|
+
client.display_deployment_result
|
20
42
|
end
|
21
43
|
|
22
44
|
%w(rollback restart start stop configure setup).each do |command_name|
|
23
45
|
desc "Run command '#{command_name}' on OpsWorks"
|
24
46
|
task command_name => :environment do
|
25
|
-
deployment_id = client.
|
47
|
+
deployment_id = client.create({name: command_name})
|
26
48
|
|
27
|
-
client.display_deployment_result
|
49
|
+
client.display_deployment_result
|
28
50
|
end
|
29
51
|
|
30
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infopark_opsworks_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infopark AG
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -71,16 +71,16 @@ dependencies:
|
|
71
71
|
name: rails
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - "<"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: 5.1.0
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - "<"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
83
|
+
version: 5.1.0
|
84
84
|
description:
|
85
85
|
email:
|
86
86
|
- info@infopark.de
|
@@ -92,8 +92,12 @@ files:
|
|
92
92
|
- app/controllers/opsworks_helpers/application_controller.rb
|
93
93
|
- config/routes.rb
|
94
94
|
- lib/opsworks_helpers.rb
|
95
|
-
- lib/opsworks_helpers/
|
95
|
+
- lib/opsworks_helpers/app.rb
|
96
|
+
- lib/opsworks_helpers/deployment.rb
|
96
97
|
- lib/opsworks_helpers/engine.rb
|
98
|
+
- lib/opsworks_helpers/opsworks_client.rb
|
99
|
+
- lib/opsworks_helpers/opsworks_resource.rb
|
100
|
+
- lib/opsworks_helpers/stack.rb
|
97
101
|
- lib/opsworks_helpers/status_checks.rb
|
98
102
|
- lib/opsworks_helpers/version.rb
|
99
103
|
- lib/tasks/opsworks_helpers_tasks.rake
|
@@ -1,46 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'aws-sdk'
|
3
|
-
rescue LoadError
|
4
|
-
fail 'Please add `aws-sdk` to your Gemfile if you want to use the deployment features.'
|
5
|
-
end
|
6
|
-
|
7
|
-
module OpsworksHelpers
|
8
|
-
class Deploy
|
9
|
-
|
10
|
-
def deploy(command, comment='Run via in-app rake task')
|
11
|
-
client.create_deployment(
|
12
|
-
stack_id: opsworks_stack_id,
|
13
|
-
app_id: opsworks_app_id,
|
14
|
-
command: command,
|
15
|
-
comment: comment
|
16
|
-
).deployment_id
|
17
|
-
end
|
18
|
-
|
19
|
-
def display_deployment_result(command_name, deployment_id)
|
20
|
-
begin
|
21
|
-
puts "[#{deployment_id}] Waiting for command '#{command_name}' to finish..."
|
22
|
-
client.wait_until(:deployment_successful, deployment_ids: [deployment_id])
|
23
|
-
puts "[#{deployment_id}] Command '#{command_name}' successful."
|
24
|
-
true
|
25
|
-
rescue ::Aws::Waiters::Errors::WaiterFailed => e
|
26
|
-
puts "[#{deployment_id}] Command '#{command_name}' failed. Message: #{e.message}"
|
27
|
-
false
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def client
|
34
|
-
@client ||= Aws::OpsWorks::Client.new(region: 'us-east-1')
|
35
|
-
end
|
36
|
-
|
37
|
-
def opsworks_stack_id
|
38
|
-
ENV['AWS_OPSWORKS_STACK_ID'] || fail('Please provide AWS_OPSWORKS_STACK_ID in env.')
|
39
|
-
end
|
40
|
-
|
41
|
-
def opsworks_app_id
|
42
|
-
ENV['AWS_OPSWORKS_APP_ID'] || fail('Please provide AWS_OPSWORKS_APP_ID in env.')
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|