opsworks-deploy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/lib/opsworks/deploy/deploy.rb +82 -0
- data/lib/opsworks/deploy/railtie.rb +10 -0
- data/lib/opsworks/deploy/version.rb +5 -0
- data/lib/opsworks/tasks/opsworks.rake +16 -0
- data/lib/opsworks-deploy.rb +1 -0
- data/opsworks-deploy.gemspec +25 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e82a69d510154428bd0aef2d0a27b06759025039
|
4
|
+
data.tar.gz: 206e3ca74911ae1d84507abb5d72e390349c9c61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1cc54964ac80288d7d64a8d9633b9c706580cb7b876df5bca5d1530fc2aab31c6656c2e8e48572b8850b1fca102bed9ffbbfde93ff149ff11d40650393ea180
|
7
|
+
data.tar.gz: 76fe3636fcd3c3d8474c331b4311740b64e857fd5474e2529513e21e3984cf257fa3b87be105a24e431c763b73617a85518e094c862d0efb794bc6855ec89a15
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Geoff Hayes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Opsworks::Deploy
|
2
|
+
|
3
|
+
Simple tool to allow to do deploy to AWS Opsworks via a `rake` task.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'opsworks-deploy'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install opsworks-deploy
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To deploy, you will need an set of IAM keys as well as the `stack id` and `app id` from Opsworks.
|
22
|
+
|
23
|
+
You can run:
|
24
|
+
|
25
|
+
IAM_KEY=... IAM_SECRET=... STACK_ID=... APP_ID=... rake opsworks:deploy
|
26
|
+
|
27
|
+
Or, if you would prefer to add items to config files:
|
28
|
+
|
29
|
+
config/stacks.json
|
30
|
+
|
31
|
+
{
|
32
|
+
"staging": { "stack_id": "...", "app_id": "..." }
|
33
|
+
}
|
34
|
+
|
35
|
+
~/.aws_config
|
36
|
+
|
37
|
+
aws_access_key_id=...
|
38
|
+
aws_secret_access_key=...
|
39
|
+
|
40
|
+
Then run:
|
41
|
+
|
42
|
+
RAILS_ENV=staging AWS_CONFIG_FILE=~/.aws_config rake opsworks:deploy
|
43
|
+
|
44
|
+
Note, your IAM keys should only allow deploy access to OpsWorks, but you should never check them into source control.
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
53
|
+
|
54
|
+
## TODO
|
55
|
+
|
56
|
+
This is a quick alpha. We need to add test cases to project.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "opsworks/deploy/version"
|
2
|
+
require 'aws-sdk'
|
3
|
+
|
4
|
+
module Opsworks::Deploy
|
5
|
+
|
6
|
+
require 'opsworks/deploy/railtie' if defined?(Rails)
|
7
|
+
|
8
|
+
def self.wait_on_deployment(deployment)
|
9
|
+
deployment_id = deployment.data[:deployment_id]
|
10
|
+
deployment_desc = nil
|
11
|
+
|
12
|
+
while true
|
13
|
+
deployment_desc = AWS.ops_works.client.describe_deployments(deployment_ids: [deployment_id])
|
14
|
+
|
15
|
+
status = deployment_desc.data[:deployments].first[:status]
|
16
|
+
|
17
|
+
case status
|
18
|
+
when 'running'
|
19
|
+
sleep 10
|
20
|
+
when 'successful'
|
21
|
+
return true
|
22
|
+
else
|
23
|
+
raise "Failed to run deployment: #{deployment_id} - #{status}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
return true if deployment_desc.data[:status] == 'successful'
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_stack
|
31
|
+
if ENV['STACK_ID'].present? && ENV['APP_ID'].present?
|
32
|
+
return {stack_id: ENV['STACK_ID'], app_id: ENV['APP_ID']}
|
33
|
+
elsif File.exists?("#{Rails.root}/config/stacks.json")
|
34
|
+
# Try to grab from .stack file
|
35
|
+
stacks = JSON(File.read("#{Rails.root}/config/stacks.json"))
|
36
|
+
raise "Missing stacks configuration for #{RAILS_ENV}" if stacks[RAILS_ENV].empty?
|
37
|
+
|
38
|
+
return stacks[RAILS_ENV].with_indifferent_access
|
39
|
+
else
|
40
|
+
raise "Must set STACK_ID/APP_ID or have config/stacks.json for RAILS_ENV"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.configure_aws!
|
45
|
+
# First, try to pull these from the environment
|
46
|
+
iam_key = ENV['IAM_KEY']
|
47
|
+
iam_secret = ENV['IAM_SECRET']
|
48
|
+
|
49
|
+
# Otherwise, we'll pull them from config
|
50
|
+
if ( iam_key.nil? || iam_secret.nil? ) && ENV['AWS_CONFIG_FILE']
|
51
|
+
config = File.read(ENV['AWS_CONFIG_FILE'])
|
52
|
+
iam_key = $1 if config =~ /^aws_access_key_id=(.*)$/
|
53
|
+
iam_secret = $1 if config =~ /^aws_secret_access_key=(.*)$/
|
54
|
+
end
|
55
|
+
|
56
|
+
raise ArgumentError, "Must set IAM_KEY environment variable" if iam_key.nil? || iam_key.length == 0
|
57
|
+
raise ArgumentError, "Must set IAM_SECRET environment variable" if iam_secret.nil? || iam_secret.length == 0
|
58
|
+
|
59
|
+
AWS.config({
|
60
|
+
access_key_id: iam_key,
|
61
|
+
secret_access_key: iam_secret,
|
62
|
+
})
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.deploy(opts={})
|
66
|
+
opts = {
|
67
|
+
migrate: true,
|
68
|
+
wait: false
|
69
|
+
}.merge(opts)
|
70
|
+
|
71
|
+
stack = Opsworks::Deploy.get_stack # Get stack environment
|
72
|
+
|
73
|
+
Opsworks::Deploy.configure_aws! # Ensure we are properly configured
|
74
|
+
|
75
|
+
deployment = AWS.ops_works.client.create_deployment( stack_id: stack[:stack_id], app_id: stack[:app_id], command: {name: 'deploy', args: {"migrate" => [opts[:migrate] ? "true" : "false"]}} )
|
76
|
+
|
77
|
+
puts deployment.inspect
|
78
|
+
|
79
|
+
Opsworks::Deploy.wait_on_deployment(deployment) if opts[:wait]
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
namespace :opsworks do
|
3
|
+
|
4
|
+
desc 'Deploy to Opsworks'
|
5
|
+
task :deploy do |t, args|
|
6
|
+
RAILS_ENV ||= ENV['RAILS_ENV']
|
7
|
+
raise "Please set RAILS_ENV environment var" if RAILS_ENV.blank?
|
8
|
+
|
9
|
+
puts "Deploying #{RAILS_ENV}..."
|
10
|
+
|
11
|
+
Opsworks::Deploy.deploy
|
12
|
+
|
13
|
+
puts "Finished successfully"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'opsworks/deploy/deploy'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'opsworks/deploy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "opsworks-deploy"
|
8
|
+
spec.version = Opsworks::Deploy::VERSION
|
9
|
+
spec.authors = ["Geoff Hayes"]
|
10
|
+
spec.email = ["hayesgm@gmail.com"]
|
11
|
+
spec.description = %q{Quick and easy rake task for deploying to AWS OpsWorks}
|
12
|
+
spec.summary = %q{A quick rake task that will deploy to AWS OpsWorks. This can be added as a post-step in Continuous Integration. `rake opsworks:deply`}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'aws-sdk'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opsworks-deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Geoff Hayes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Quick and easy rake task for deploying to AWS OpsWorks
|
56
|
+
email:
|
57
|
+
- hayesgm@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/opsworks-deploy.rb
|
68
|
+
- lib/opsworks/deploy/deploy.rb
|
69
|
+
- lib/opsworks/deploy/railtie.rb
|
70
|
+
- lib/opsworks/deploy/version.rb
|
71
|
+
- lib/opsworks/tasks/opsworks.rake
|
72
|
+
- opsworks-deploy.gemspec
|
73
|
+
homepage: ''
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.1.11
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A quick rake task that will deploy to AWS OpsWorks. This can be added as
|
97
|
+
a post-step in Continuous Integration. `rake opsworks:deply`
|
98
|
+
test_files: []
|