opsworks_rolling_deploy 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/opsworks_rolling_deploy +5 -0
- data/lib/opsworks_rolling_deploy/cli.rb +12 -0
- data/lib/opsworks_rolling_deploy/clients.rb +13 -0
- data/lib/opsworks_rolling_deploy/commands/deploy_command.rb +28 -0
- data/lib/opsworks_rolling_deploy/commands/describe.rb +16 -0
- data/lib/opsworks_rolling_deploy/commands/describe_command.rb +23 -0
- data/lib/opsworks_rolling_deploy/elb_methods.rb +76 -0
- data/lib/opsworks_rolling_deploy/output_methods.rb +14 -0
- data/lib/opsworks_rolling_deploy/services/deploy_service.rb +123 -0
- data/lib/opsworks_rolling_deploy/services/describe_service.rb +56 -0
- data/lib/opsworks_rolling_deploy/version.rb +3 -0
- data/lib/opsworks_rolling_deploy.rb +23 -0
- data/opsworks_rolling_deploy.gemspec +30 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4054e11c4859a5584dad6e81f55472fb89b934fd
|
4
|
+
data.tar.gz: b20a274f6ce780a672e1d72ae387f61fa3507184
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c8803ed1cd90cd341c2222902d9d6df5a91e377705c531af31f9ae0006722bb3c3eb6823f59ec260c4baeac2902672057625e0fff22c0378fe2242cb9e1c5ca
|
7
|
+
data.tar.gz: f133d1376ecbcee88b5fcfa95d30209709a86b12ffc9a4a1d75dbf22c954053dff99a19218c46f5ff6f9ba60892a7d3557382e4f8ccc26e357874de468ade888
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# OpsworksRollingDeploy
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/opsworks_rolling_deploy`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'opsworks_rolling_deploy'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install opsworks_rolling_deploy
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/opsworks_rolling_deploy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'clamp'
|
2
|
+
require 'opsworks_rolling_deploy'
|
3
|
+
require 'opsworks_rolling_deploy/commands/describe_command'
|
4
|
+
require 'opsworks_rolling_deploy/commands/deploy_command'
|
5
|
+
|
6
|
+
module OpsworksRollingDeploy
|
7
|
+
class Cli < Clamp::Command
|
8
|
+
|
9
|
+
subcommand ['describe'], 'Describe current OpsWorks Structure', OpsworksRollingDeploy::Commands::DescribeCommand
|
10
|
+
subcommand %w(deploy roll), 'Perform a rolling deploy', OpsworksRollingDeploy::Commands::DeployCommand
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# AWS clients utility
|
2
|
+
module OpsworksRollingDeploy
|
3
|
+
|
4
|
+
module Clients
|
5
|
+
def ops_client
|
6
|
+
@ops_client ||= Aws::OpsWorks::Client.new(region: 'us-east-1')
|
7
|
+
end
|
8
|
+
def elb_client(region = 'us-east-1')
|
9
|
+
@elb_client ||={}
|
10
|
+
@elb_client[region] ||= Aws::ElasticLoadBalancing::Client.new(region: region)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'clamp'
|
2
|
+
require 'opsworks_rolling_deploy/services/deploy_service'
|
3
|
+
require 'JSON'
|
4
|
+
module OpsworksRollingDeploy
|
5
|
+
module Commands
|
6
|
+
class DeployCommand < Clamp::Command
|
7
|
+
option "--aws-id", "AWS_ACCESS_KEY_ID", "aws access key id", environment_variable: "AWS_ACCESS_KEY_ID"
|
8
|
+
option "--aws-secret", "AWS_SECRET_ACCESS_KEY", "aws secret access key", environment_variable: "AWS_SECRET_ACCESS_KEY"
|
9
|
+
|
10
|
+
option "--stack", "STACK_NAME", "the stack name", required: true
|
11
|
+
option "--app", "APP_NAME", "the application name", required: true
|
12
|
+
option "--layer", "LAYER_NAME", "the layer name", required: false
|
13
|
+
|
14
|
+
option "--command", "COMMAND", "the command to be executed by opsworks", default: 'deploy'
|
15
|
+
option "--command-args", "COMMAND_ARGS", "the args to the command to be executed by opsworks as JSON (e.g. '{\"migrate\":[\"true\"]}'", default: '{}'
|
16
|
+
|
17
|
+
option "--pretend", :flag, "pretend execution"
|
18
|
+
option "--verbose", :flag, "display aws commands"
|
19
|
+
option "--exclude", "PATTERN" , "wildcard pattern to exclude hosts", multivalued: true
|
20
|
+
|
21
|
+
def execute
|
22
|
+
OpsworksRollingDeploy.set_verbose(verbose?)
|
23
|
+
OpsworksRollingDeploy.set_auth_default(aws_id, aws_secret) if aws_id
|
24
|
+
Services::DeployService.new.deploy(stack, layer, app, command, JSON.parse(command_args), pretend?, exclude_list)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'clamp'
|
2
|
+
require 'opsworks_rolling_deploy/services/describe_service'
|
3
|
+
|
4
|
+
module OpsworksRollingDeploy
|
5
|
+
module Commands
|
6
|
+
class DescribeCommand < Clamp::Command
|
7
|
+
option "--stack", "STACK_NAME", "the stack name", :required => false
|
8
|
+
option "--app", "APP_NAME", "the application name", :required => false
|
9
|
+
option "--layer", "LAYER_NAME", "the layer name", :required => false
|
10
|
+
|
11
|
+
def execute
|
12
|
+
OpsworksRollingDeploy::Services::DescribeService.new.describe(stack, app, layer)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'clamp'
|
2
|
+
require 'opsworks_rolling_deploy/services/describe_service'
|
3
|
+
|
4
|
+
module OpsworksRollingDeploy
|
5
|
+
module Commands
|
6
|
+
class DescribeCommand < Clamp::Command
|
7
|
+
option "--aws-id", "AWS_ACCESS_KEY_ID", "aws access key id", environment_variable: "AWS_ACCESS_KEY_ID"
|
8
|
+
option "--aws-secret", "AWS_SECRET_ACCESS_KEY", "aws secret access key", environment_variable: "AWS_SECRET_ACCESS_KEY"
|
9
|
+
|
10
|
+
option "--stack", "STACK_NAME", "the stack name", :required => false
|
11
|
+
option "--app", "APP_NAME", "the application name", :required => false
|
12
|
+
option "--layer", "LAYER_NAME", "the layer name", :required => false
|
13
|
+
option "--verbose", :flag, "display aws commands"
|
14
|
+
|
15
|
+
def execute
|
16
|
+
OpsworksRollingDeploy.set_verbose(verbose?)
|
17
|
+
|
18
|
+
OpsworksRollingDeploy.set_auth_default(aws_id, aws_secret) if aws_id
|
19
|
+
OpsworksRollingDeploy::Services::DescribeService.new.describe(stack, app, layer)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module OpsworksRollingDeploy
|
2
|
+
module ElbMethods
|
3
|
+
ELB_STATUS_INSERVICE = "InService"
|
4
|
+
ELB_STATUS_OUTOFSERVICE = "OutOfService"
|
5
|
+
|
6
|
+
def pools_of_instance(_stack, instance)
|
7
|
+
ops_client.describe_elastic_load_balancers({
|
8
|
+
layer_ids: instance.layer_ids,
|
9
|
+
}).elastic_load_balancers
|
10
|
+
end
|
11
|
+
|
12
|
+
def remove_from_pools(stack, _app, instance)
|
13
|
+
# XXX I did not figure out how to filter instances running the app
|
14
|
+
pools = pools_of_instance(stack, instance).each do |elb|
|
15
|
+
info 'Instance', instance.hostname, instance.ec2_instance_id, "Remove from pool #{elb.elastic_load_balancer_name}"
|
16
|
+
deregister_instances_from_load_balancer(elb, instance.ec2_instance_id) unless pretend?
|
17
|
+
end
|
18
|
+
|
19
|
+
pools.each do |elb|
|
20
|
+
wait_status(elb, instance.ec2_instance_id, ELB_STATUS_OUTOFSERVICE)
|
21
|
+
end unless pretend?
|
22
|
+
|
23
|
+
pools
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_into_pools(_stack, instance, pools)
|
27
|
+
pools.each do |elb|
|
28
|
+
info 'Instance', instance.hostname, instance.ec2_instance_id, "Adding back to pool #{elb.elastic_load_balancer_name}"
|
29
|
+
register_instances_with_load_balancer(elb, instance.ec2_instance_id) unless pretend?
|
30
|
+
end
|
31
|
+
|
32
|
+
pools.each do |elb|
|
33
|
+
wait_status(elb, instance.ec2_instance_id, ELB_STATUS_INSERVICE)
|
34
|
+
end unless pretend?
|
35
|
+
end
|
36
|
+
|
37
|
+
def deregister_instances_from_load_balancer(elb, instance_id)
|
38
|
+
elb_client(elb.region).deregister_instances_from_load_balancer({
|
39
|
+
load_balancer_name: elb.elastic_load_balancer_name,
|
40
|
+
instances: [ # required
|
41
|
+
{ instance_id: instance_id }
|
42
|
+
]
|
43
|
+
})
|
44
|
+
end
|
45
|
+
|
46
|
+
def register_instances_with_load_balancer(elb, instance_id)
|
47
|
+
elb_client(elb.region).register_instances_with_load_balancer({
|
48
|
+
load_balancer_name: elb.elastic_load_balancer_name,
|
49
|
+
instances: [ # required
|
50
|
+
{ instance_id: instance_id }
|
51
|
+
]
|
52
|
+
})
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_elb_status(elb, instance_id)
|
56
|
+
elb_client(elb.region).describe_instance_health({
|
57
|
+
load_balancer_name: elb.elastic_load_balancer_name,
|
58
|
+
instances: [ {instance_id: instance_id} ]
|
59
|
+
}).instance_states.last.state
|
60
|
+
end
|
61
|
+
|
62
|
+
def wait_status(elb, instance_id, status)
|
63
|
+
$stdout.write get_elb_status(elb, instance_id)
|
64
|
+
100.times do
|
65
|
+
$stdout.write '.'
|
66
|
+
instance_status = get_elb_status(elb, instance_id)
|
67
|
+
if instance_status == status
|
68
|
+
puts instance_status
|
69
|
+
return true
|
70
|
+
end
|
71
|
+
sleep 5
|
72
|
+
end
|
73
|
+
fail "Time out while waiting status"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'opsworks_rolling_deploy/clients'
|
3
|
+
require 'opsworks_rolling_deploy/output_methods'
|
4
|
+
require 'opsworks_rolling_deploy/elb_methods'
|
5
|
+
|
6
|
+
module OpsworksRollingDeploy
|
7
|
+
module Services
|
8
|
+
class DeployService
|
9
|
+
|
10
|
+
include OpsworksRollingDeploy::Clients
|
11
|
+
include OpsworksRollingDeploy::OutputMethods
|
12
|
+
include OpsworksRollingDeploy::ElbMethods
|
13
|
+
|
14
|
+
def deploy(stack_name, layer_name, app_name, command, command_args, pretend = true, exclude_patterns = [])
|
15
|
+
@pretend = pretend
|
16
|
+
stack = get_stack(stack_name) || fail("Stack not found #{stack_name}'")
|
17
|
+
app = get_app(stack, app_name) || fail("App not found #{app_name}'")
|
18
|
+
layer = layer_name && get_layer(stack, layer_name) # || fail("Layer not found #{layer_name}'")
|
19
|
+
|
20
|
+
instances = instances_to_deploy(stack, layer, app, exclude_patterns)
|
21
|
+
instances.shuffle!
|
22
|
+
instances.each_with_index do |instance, idx|
|
23
|
+
pools = remove_from_pools(stack, app, instance)
|
24
|
+
comment = [ (layer ? layer.name : 'Full'), "#{idx+1}/#{instances.size}" ].compact.join(' ')
|
25
|
+
create_deployment(stack, app, instance, command, command_args, comment)
|
26
|
+
add_into_pools(stack, instance, pools)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def match?(hostname, patterns)
|
33
|
+
patterns.any?{|pattern| File.fnmatch?(pattern, hostname)}
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_stack(stack_name)
|
37
|
+
get_stacks.detect{|s| s.name == stack_name }
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_stacks
|
41
|
+
@stacks ||= ops_client.describe_stacks().stacks
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_app(stack, app_name)
|
45
|
+
get_apps(stack).detect{|a| a.name == app_name }
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_layer(stack, layer_name)
|
49
|
+
get_layers(stack).detect{|a| a.name == layer_name }
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_layers(stack)
|
53
|
+
@layers ||= {}
|
54
|
+
@layers[stack.stack_id] ||= ops_client.describe_layers(stack_id: stack.stack_id).layers
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_apps(stack)
|
58
|
+
@apps ||= {}
|
59
|
+
@apps[stack.stack_id] ||= ops_client.describe_apps(stack_id: stack.stack_id).apps
|
60
|
+
end
|
61
|
+
|
62
|
+
def instances_to_deploy(stack, layer, _app, exclude_patterns)
|
63
|
+
# XXX I did not figure out how to filter instances running the app
|
64
|
+
|
65
|
+
ops_client.describe_instances(stack_id: stack.stack_id).instances.select do |instance|
|
66
|
+
if layer && !instance.layer_ids.include?(layer.layer_id)
|
67
|
+
warn 'Instance', instance.hostname, instance.ec2_instance_id, "Skipping because it's not part of given layer"
|
68
|
+
next false
|
69
|
+
end
|
70
|
+
|
71
|
+
if match?(instance.hostname, exclude_patterns)
|
72
|
+
warn 'Instance', instance.hostname, instance.ec2_instance_id, "Skipping because it's excluded"
|
73
|
+
next false
|
74
|
+
end
|
75
|
+
|
76
|
+
if instance.status != 'online'
|
77
|
+
warn 'Instance', instance.hostname, instance.ec2_instance_id, "Skipping because it's not online"
|
78
|
+
next false
|
79
|
+
end
|
80
|
+
true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def create_deployment(stack, app, instance, command, command_args, comment)
|
85
|
+
info 'Instance', instance.hostname, instance.ec2_instance_id, "Deploying", comment
|
86
|
+
return if pretend?
|
87
|
+
deployment = ops_client.create_deployment({
|
88
|
+
stack_id: stack.stack_id,
|
89
|
+
command: {name: command, args: command_args || {}},
|
90
|
+
comment: comment,
|
91
|
+
custom_json: '{}',
|
92
|
+
app_id: app.app_id,
|
93
|
+
instance_ids: [instance.instance_id],
|
94
|
+
})
|
95
|
+
wait_until_deployed(deployment.deployment_id)
|
96
|
+
end
|
97
|
+
|
98
|
+
def wait_until_deployed(deployment_id)
|
99
|
+
deployment = nil
|
100
|
+
|
101
|
+
status = ops_client.describe_deployments(deployment_ids: [deployment_id]).deployments.first.status
|
102
|
+
$stdout.write status
|
103
|
+
|
104
|
+
loop do
|
105
|
+
sleep 5
|
106
|
+
|
107
|
+
$stdout.write "."
|
108
|
+
status = ops_client.describe_deployments(deployment_ids: [deployment_id]).deployments.first.status
|
109
|
+
|
110
|
+
if status != "running"
|
111
|
+
puts status
|
112
|
+
fail "Deploy status #{status}}" if status != 'successful'
|
113
|
+
return
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def pretend?
|
119
|
+
@pretend && true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'colorize'
|
3
|
+
require 'opsworks_rolling_deploy/clients'
|
4
|
+
|
5
|
+
module OpsworksRollingDeploy
|
6
|
+
module Services
|
7
|
+
class DescribeService
|
8
|
+
include OpsworksRollingDeploy::Clients
|
9
|
+
|
10
|
+
def describe(stack_name, app_name, layer_name)
|
11
|
+
ops_client.describe_stacks.stacks.each do |stack|
|
12
|
+
next if stack_name and stack_name != stack.name
|
13
|
+
puts "STACK = #{stack.name.green} #{stack.stack_id}"
|
14
|
+
describe_stack_apps(stack, app_name)
|
15
|
+
describe_stack_layers(stack, layer_name)
|
16
|
+
end
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def describe_stack_apps(stack, app_name)
|
23
|
+
puts " APPS:"
|
24
|
+
ops_client.describe_apps(stack_id: stack.stack_id).apps.each do |app|
|
25
|
+
next if app_name and app_name != app.name
|
26
|
+
puts " APP: #{app.name.cyan} #{app.app_id} #{app.type}@#{app.app_source[:revision].to_s.magenta}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def describe_stack_layers(stack, layer_name)
|
31
|
+
puts " LAYERS:"
|
32
|
+
ops_client.describe_layers(stack_id: stack.stack_id).layers.each do |layer|
|
33
|
+
next if layer_name and layer_name != layer.name
|
34
|
+
describe_layer(layer)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def describe_layer(layer)
|
39
|
+
puts " layer: #{layer.name.blue} #{layer.layer_id}"
|
40
|
+
ops_client.describe_elastic_load_balancers(layer_ids: [layer.layer_id]).elastic_load_balancers.each do |elb|
|
41
|
+
puts " ELB: #{elb.elastic_load_balancer_name.red} "
|
42
|
+
describe_instance_health(elb) if elb.ec2_instance_ids.any?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def describe_instance_health(elb)
|
47
|
+
elb_client(elb.region).describe_instance_health({
|
48
|
+
load_balancer_name: elb.elastic_load_balancer_name,
|
49
|
+
instances: elb.ec2_instance_ids.map{ |id| {instance_id: id} }
|
50
|
+
}).instance_states.each do |state|
|
51
|
+
puts " #{state.instance_id}: #{state.state}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'opsworks_rolling_deploy/version'
|
2
|
+
require 'aws-sdk'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
# Module for rolling deploy management over opsworks
|
6
|
+
module OpsworksRollingDeploy
|
7
|
+
def self.set_auth_default(aws_id, aws_secret)
|
8
|
+
Aws.config.update(credentials: Aws::Credentials.new(aws_id, aws_secret) )
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.set_verbose(verbose)
|
12
|
+
Aws.config.update(logger: logger) if verbose
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.logger
|
16
|
+
@logger ||= begin
|
17
|
+
Logger.new(STDOUT).tap do |l|
|
18
|
+
$stdout.sync = true
|
19
|
+
l.level = Logger::DEBUG
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'opsworks_rolling_deploy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'opsworks_rolling_deploy'
|
8
|
+
spec.version = OpsworksRollingDeploy::VERSION
|
9
|
+
spec.authors = ['Romeu Henrique Capparelli Fonseca']
|
10
|
+
spec.email = ['romeu.hcf@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Utilities for opsworks rolling deploy'
|
13
|
+
spec.description = 'Manage a rolling deploy over opsworks stack instances, removing each node from ELB while deploying to it'
|
14
|
+
spec.homepage = 'https://bitbucket.org/truckpad/opsworks_rolling_deploy'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'bin'
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'clamp'
|
23
|
+
spec.add_runtime_dependency 'aws-sdk'
|
24
|
+
spec.add_runtime_dependency 'colorize'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec'
|
28
|
+
spec.add_development_dependency 'simplecov'
|
29
|
+
spec.add_development_dependency 'byebug'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opsworks_rolling_deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Romeu Henrique Capparelli Fonseca
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: clamp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
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: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Manage a rolling deploy over opsworks stack instances, removing each
|
112
|
+
node from ELB while deploying to it
|
113
|
+
email:
|
114
|
+
- romeu.hcf@gmail.com
|
115
|
+
executables:
|
116
|
+
- opsworks_rolling_deploy
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- .gitignore
|
121
|
+
- .rspec
|
122
|
+
- .travis.yml
|
123
|
+
- CODE_OF_CONDUCT.md
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/opsworks_rolling_deploy
|
129
|
+
- lib/opsworks_rolling_deploy.rb
|
130
|
+
- lib/opsworks_rolling_deploy/cli.rb
|
131
|
+
- lib/opsworks_rolling_deploy/clients.rb
|
132
|
+
- lib/opsworks_rolling_deploy/commands/deploy_command.rb
|
133
|
+
- lib/opsworks_rolling_deploy/commands/describe.rb
|
134
|
+
- lib/opsworks_rolling_deploy/commands/describe_command.rb
|
135
|
+
- lib/opsworks_rolling_deploy/elb_methods.rb
|
136
|
+
- lib/opsworks_rolling_deploy/output_methods.rb
|
137
|
+
- lib/opsworks_rolling_deploy/services/deploy_service.rb
|
138
|
+
- lib/opsworks_rolling_deploy/services/describe_service.rb
|
139
|
+
- lib/opsworks_rolling_deploy/version.rb
|
140
|
+
- opsworks_rolling_deploy.gemspec
|
141
|
+
homepage: https://bitbucket.org/truckpad/opsworks_rolling_deploy
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.4.6
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: Utilities for opsworks rolling deploy
|
165
|
+
test_files: []
|