opsworks_wrapper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/lib/opsworks_wrapper.rb +129 -0
- data/lib/opsworks_wrapper/version.rb +3 -0
- data/opsworks_wrapper.gemspec +23 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 382ccf56835c9a6787c03a12a2de311989492b72
|
4
|
+
data.tar.gz: 3efeb0cacd432e2e87f8b5d3f34945b289959c5b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fae78c1576999010eb4ac8dfce4582f33d631da2445fec1f8839ac2ef744c1e711644b04ce2b34012dde28478ebde107ea4dde37c1f7e96de4ad405f2552f5d0
|
7
|
+
data.tar.gz: e227d5f12324eb3ef06d5f5b68e7bb38499bb1ad69d09bb2513a4eb2d0824f0f4e891d72b645fa0046fa89f91a77dceb8cbaa83f673bc50519e20495397eade6
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at ukayani@loyalty.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Umair Kayani
|
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,39 @@
|
|
1
|
+
# OpsworksWrapper
|
2
|
+
|
3
|
+
A simple wrapper for aws-sdk to make handling opsworks operations easier.
|
4
|
+
|
5
|
+
## Supported Operations
|
6
|
+
- Update custom cookbooks
|
7
|
+
- Deployment Creation for a particualr layer (by layer name)
|
8
|
+
- Deployment Creation for all layers except a specified layer (exclusion by layer name)
|
9
|
+
- Retrieve all instances for a given layer name
|
10
|
+
|
11
|
+
TODO: Delete this and the text above, and describe your gem
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'opsworks_wrapper'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install opsworks_wrapper
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
TODO: Write usage instructions here
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ukayani/opsworks_wrapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require "opsworks_wrapper/version"
|
2
|
+
|
3
|
+
module OpsworksWrapper
|
4
|
+
class Deployer
|
5
|
+
require 'aws-sdk'
|
6
|
+
require 'colorize'
|
7
|
+
|
8
|
+
def initialize(app_id)
|
9
|
+
@app_id = app_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_sha
|
13
|
+
@current_sha ||= `git rev-parse HEAD`.chomp
|
14
|
+
end
|
15
|
+
|
16
|
+
def opsworks_app
|
17
|
+
@opsworks_app ||= get_opsworks_app
|
18
|
+
end
|
19
|
+
|
20
|
+
def client
|
21
|
+
@client ||= Aws::OpsWorks::Client.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def app_id
|
25
|
+
@app_id
|
26
|
+
end
|
27
|
+
|
28
|
+
def layers
|
29
|
+
@layers ||= get_opsworks_layers
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_opsworks_layers
|
33
|
+
data = client.describe_layers(stack_id: opsworks_app[:stack_id])
|
34
|
+
layers = {}
|
35
|
+
data.layers.each do |layer|
|
36
|
+
layers[layer.name] = layer
|
37
|
+
end
|
38
|
+
layers
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_opsworks_app
|
42
|
+
data = client.describe_apps(app_ids: [app_id])
|
43
|
+
unless data[:apps] && data[:apps].count == 1
|
44
|
+
raise Error, "App #{app_id} not found.", error.backtrace
|
45
|
+
end
|
46
|
+
data[:apps].first
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_instances(layer_name = nil)
|
50
|
+
if layer_name == nil
|
51
|
+
data = client.describe_instances(stack_id: opsworks_app[:stack_id])
|
52
|
+
else
|
53
|
+
layer_id = layers[layer_name].layer_id
|
54
|
+
data = client.describe_instances(layer_id: layer_id)
|
55
|
+
end
|
56
|
+
|
57
|
+
data.instances
|
58
|
+
end
|
59
|
+
|
60
|
+
# update cookbooks on all layers
|
61
|
+
def update_cookbooks(timeout = 150)
|
62
|
+
puts 'Updating cookbooks'.light_white.bold
|
63
|
+
create_deployment({name: 'update_custom_cookbooks'}, nil, timeout)
|
64
|
+
end
|
65
|
+
|
66
|
+
# deploy to specified layer or all layers (default)
|
67
|
+
def deploy(layer_name = nil, timeout = 600)
|
68
|
+
if layer_name
|
69
|
+
puts "Deploying on #{layer_name} layer".light_white.bold
|
70
|
+
instance_ids = get_instances(layer_name).map(&:instance_id)
|
71
|
+
else
|
72
|
+
puts "Deploying on all layers".light_white.bold
|
73
|
+
instance_ids = nil
|
74
|
+
end
|
75
|
+
|
76
|
+
create_deployment({name: 'deploy'}, instance_ids, timeout)
|
77
|
+
end
|
78
|
+
|
79
|
+
# deploy to all layers except specified layer
|
80
|
+
def deploy_exclude(layer_name, timeout = 600)
|
81
|
+
puts "Deploying to all layers except #{layer_name}".light_white.bold
|
82
|
+
create_deployment_exclude({name: 'deploy'}, layer_name, timeout)
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_deployment_exclude(command, layer_to_exclude, timeout)
|
86
|
+
all_instance_ids = get_instances.map(&:instance_id)
|
87
|
+
excluded_instance_ids = get_instances(layer_to_exclude).map(&:instance_id)
|
88
|
+
included_instance_ids = all_instance_ids - excluded_instance_ids
|
89
|
+
|
90
|
+
create_deployment(command, included_instance_ids, timeout)
|
91
|
+
end
|
92
|
+
|
93
|
+
def create_deployment(command, instance_ids, timeout)
|
94
|
+
deployment_config = {
|
95
|
+
stack_id: opsworks_app[:stack_id],
|
96
|
+
app_id: app_id,
|
97
|
+
instance_ids: instance_ids,
|
98
|
+
command: command,
|
99
|
+
comment: "Git Sha: #{current_sha}"
|
100
|
+
}
|
101
|
+
|
102
|
+
deployment = client.create_deployment(deployment_config)
|
103
|
+
puts "Deployment created: #{deployment[:deployment_id]}".blue
|
104
|
+
puts "Running Command: #{command[:name]} ".light_blue
|
105
|
+
|
106
|
+
begin
|
107
|
+
wait_until_deployed(deployment[:deployment_id], timeout)
|
108
|
+
puts "Deployment successful".green
|
109
|
+
true
|
110
|
+
rescue Aws::Waiters::Errors::WaiterFailed => e
|
111
|
+
puts "Failed to deploy: #{e.message}".red
|
112
|
+
false
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Waits on the provided deployment for specified timeout (seconds)
|
117
|
+
def wait_until_deployed(deployment_id, timeout)
|
118
|
+
client.wait_until(:deployment_successful, deployment_ids: [deployment_id]) do |w|
|
119
|
+
w.before_attempt do |attempt|
|
120
|
+
puts "Attempt #{attempt} to check deployment status".light_black
|
121
|
+
end
|
122
|
+
w.interval = 10
|
123
|
+
w.max_attempts = timeout / w.interval
|
124
|
+
end
|
125
|
+
end
|
126
|
+
private :wait_until_deployed
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "opsworks_wrapper"
|
7
|
+
spec.version = '0.1.0'
|
8
|
+
spec.authors = ["Umair Kayani", "Calvin Fernandes"]
|
9
|
+
spec.email = ["ukayani@loyalty.com", "cfernandes@loyalty.com"]
|
10
|
+
|
11
|
+
spec.summary = "A wrapper for AWS OpsWorks to make deploying to the service easier"
|
12
|
+
spec.homepage = "https://github.com/ukayani/opsworks-wrapper"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency 'aws-sdk', '~> 2'
|
20
|
+
spec.add_dependency 'colorize', '0.7.7'
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opsworks_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Umair Kayani
|
8
|
+
- Calvin Fernandes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-04-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: aws-sdk
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: colorize
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.7.7
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.7.7
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.11'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.11'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '10.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10.0'
|
70
|
+
description:
|
71
|
+
email:
|
72
|
+
- ukayani@loyalty.com
|
73
|
+
- cfernandes@loyalty.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- lib/opsworks_wrapper.rb
|
85
|
+
- lib/opsworks_wrapper/version.rb
|
86
|
+
- opsworks_wrapper.gemspec
|
87
|
+
homepage: https://github.com/ukayani/opsworks-wrapper
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: A wrapper for AWS OpsWorks to make deploying to the service easier
|
111
|
+
test_files: []
|