oops 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 +42 -0
- data/Rakefile +1 -0
- data/lib/oops.rb +3 -0
- data/lib/oops/opsworks_deploy.rb +51 -0
- data/lib/oops/railtie.rb +7 -0
- data/lib/oops/tasks.rb +87 -0
- data/lib/oops/version.rb +3 -0
- data/oops.gemspec +24 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 25f445dd4117d2685174f1f49b8d6fddc276459b
|
4
|
+
data.tar.gz: cc969909cddf2345c33d0947012e33f0bd082890
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 289500d92d7d4210b49e83abe11913c3c0107df1b335c21155a87e249bdd3f274e57e146030fa1b202b60ac67394dce30ee86d739389f1202560caf71265d5ea
|
7
|
+
data.tar.gz: bcb8243910928257e81679d8113f26199e23312253b9b56973fa48534fd6e01f740c7b8c6738750c5a50a81dd130926c164a274983b74312dff5f52f8d5570eb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Clarke Brunsdon
|
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,42 @@
|
|
1
|
+
# Oops: The Opsworks Postal Service
|
2
|
+
|
3
|
+
Oops handles the creation and deployment of rails applications to Amazon's Opsworks (http://aws.amazon.com/opsworks/).
|
4
|
+
|
5
|
+
It provides rake tasks to bundle your application, along with all of its assets, into a .zip that is uploaded to s3. That artifact is then used to deploy your application. This saves production boxes from running asset precompiles and avoids git checkouts on your running servers.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'oops'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install oops
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Variables are passed into ops using both environment variables and rake arguements.
|
24
|
+
|
25
|
+
To create a build:
|
26
|
+
AWS_ACCESS_KEY_ID=MY_ACCESS_KEY AWS_SECRET_ACCESS_KEY=MY_SECRET_KEY DEPLOY_BUCKET=oops-deploy PACKAGE_FOLDER=opsbuilds bundle exec rake oops:build
|
27
|
+
|
28
|
+
To upload a build:
|
29
|
+
AWS_ACCESS_KEY_ID=MY_ACCESS_KEY AWS_SECRET_ACCESS_KEY=MY_SECRET_KEY DEPLOY_BUCKET=oops-deploy PACKAGE_FOLDER=opsbuilds bundle exec rake oops:upload
|
30
|
+
|
31
|
+
To deploy a build:
|
32
|
+
AWS_ACCESS_KEY_ID=MY_ACCESS_KEY AWS_SECRET_ACCESS_KEY=MY_SECRET_KEY DEPLOY_BUCKET=oops-deploy PACKAGE_FOLDER=opsbuilds bundle exec rake oops:deploy[my_application_name,my_stack_name]
|
33
|
+
|
34
|
+
By default, these tasks will all deploy what is in your current HEAD, but can also be passed an optional ref to deploy a specific revision.
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/oops.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Oops class OpsworksDeploy
|
2
|
+
attr_accessor :stack_name, :app_name
|
3
|
+
|
4
|
+
def initialize(app_name, stack_name)
|
5
|
+
@client = AWS::OpsWorks::Client.new
|
6
|
+
self.stack_name = stack_name
|
7
|
+
self.app_name = app_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def deploy(file_url)
|
11
|
+
@client.update_app(app_id: app_id, app_source: { url: file_url })
|
12
|
+
instance_ids = @client.describe_instances(stack_id: stack_id).instances.map(&:instance_id).to_a
|
13
|
+
deployment = @client.create_deployment(stack_id: stack_id, app_id: app_id, command: { name: 'deploy', args: { "migrate"=>["true"] } }, instance_ids: instance_ids )
|
14
|
+
Deployment.new(@client, deployment)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Deployment
|
18
|
+
|
19
|
+
def finished?
|
20
|
+
status != 'running'
|
21
|
+
end
|
22
|
+
|
23
|
+
def status
|
24
|
+
@client.describe_deployments(deployment_ids: [@deployment.deployment_id]).deployments[0].status
|
25
|
+
end
|
26
|
+
|
27
|
+
def failed?
|
28
|
+
status == 'failed'
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def initialize(client, deployment)
|
33
|
+
@client = client
|
34
|
+
@deployment = deployment
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def stack_id
|
42
|
+
@stack_id ||= @client.describe_stacks[:stacks].detect { |x| x[:name] == stack_name }[:stack_id]
|
43
|
+
end
|
44
|
+
|
45
|
+
def app_id
|
46
|
+
@app_id ||= @client.describe_apps(stack_id: stack_id)[:apps].detect { |x| x[:name] == app_name }[:app_id]
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/oops/railtie.rb
ADDED
data/lib/oops/tasks.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'oops/opsworks_deploy'
|
2
|
+
require 'aws'
|
3
|
+
namespace :oops do
|
4
|
+
task :build, :ref do |t, args|
|
5
|
+
args.with_defaults ref: build_hash
|
6
|
+
|
7
|
+
file_path = zip_file args.ref
|
8
|
+
|
9
|
+
sh %{mkdir -p build}
|
10
|
+
sh %{git archive --format zip --output build/#{file_path} HEAD}
|
11
|
+
|
12
|
+
sh %{rm -rf public/assets}
|
13
|
+
sh %{rake assets:precompile:all RAILS_ENV=deploy RAILS_GROUPS=assets}
|
14
|
+
|
15
|
+
sh %{zip -r -g build/#{file_path} public/}
|
16
|
+
sh %{zip build/#{file_path} -d .gitignore}
|
17
|
+
|
18
|
+
puts "Packaged Application: #{file_path}"
|
19
|
+
end
|
20
|
+
|
21
|
+
task :upload, :ref do |t, args|
|
22
|
+
args.with_defaults ref: build_hash
|
23
|
+
|
24
|
+
file_path = zip_file args.ref
|
25
|
+
s3 = s3_object(file_path)
|
26
|
+
|
27
|
+
puts "Starting upload..."
|
28
|
+
s3.write(file: "build/#{file_path}")
|
29
|
+
puts "Uploaded Application: #{s3.url_for(:read)}"
|
30
|
+
end
|
31
|
+
|
32
|
+
task :deploy, :app_name, :stack_name, :ref do |t, args|
|
33
|
+
raise "app_name variable is required" unless (app_name = args.app_name)
|
34
|
+
raise "stack_name variable is required" unless (stack_name = args.stack_name)
|
35
|
+
args.with_defaults ref: build_hash
|
36
|
+
file_path = zip_file args.ref
|
37
|
+
file_url = s3_url file_path
|
38
|
+
|
39
|
+
ENV['AWS_REGION'] = 'us-east-1'
|
40
|
+
|
41
|
+
if !s3_object(file_path).exists?
|
42
|
+
raise "Artifact \"#{file_url}\" doesn't seem to exist\nMake sure you've run `RAILS_ENV=deploy rake opsworks:build opsworks:upload` before deploying"
|
43
|
+
end
|
44
|
+
|
45
|
+
ops = Oops::OpsworksDeploy.new args.app_name, args.stack_name
|
46
|
+
deployment = ops.deploy(file_url)
|
47
|
+
|
48
|
+
STDOUT.sync = true
|
49
|
+
STDOUT.print "Deploying"
|
50
|
+
loop do
|
51
|
+
STDOUT.print "."
|
52
|
+
break if deployment.finished?
|
53
|
+
sleep 5
|
54
|
+
end
|
55
|
+
|
56
|
+
STDOUT.puts "\nStatus: #{deployment.status}"
|
57
|
+
raise "Deploy failed. Check the OpsWorks console." if deployment.failed?
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def s3_object file_path
|
62
|
+
AWS::S3.new.buckets[bucket_name].objects["#{package_folder}/#{file_path}"]
|
63
|
+
end
|
64
|
+
|
65
|
+
def s3_url file_path
|
66
|
+
s3_object(file_path).public_url.to_s
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_hash
|
70
|
+
@build_hash ||= `git rev-parse HEAD`.strip
|
71
|
+
end
|
72
|
+
|
73
|
+
def zip_file ref
|
74
|
+
"git-#{ref}.zip"
|
75
|
+
end
|
76
|
+
|
77
|
+
def package_folder
|
78
|
+
raise "PACKAGE_FOLDER environment variable required" unless ENV['PACKAGE_FOLDER']
|
79
|
+
ENV['PACKAGE_FOLDER']
|
80
|
+
end
|
81
|
+
|
82
|
+
def bucket_name
|
83
|
+
raise "DEPLOY_BUCKET environment variable required" unless ENV['DEPLOY_BUCKET']
|
84
|
+
ENV['DEPLOY_BUCKET']
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/lib/oops/version.rb
ADDED
data/oops.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oops/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "oops"
|
8
|
+
spec.version = Oops::VERSION
|
9
|
+
spec.authors = ["Clarke Brunsdon"]
|
10
|
+
spec.email = ["clarke@freerunningtechnologies.com"]
|
11
|
+
spec.description = %q{Oops Opsworks Postal Service: Made to ship code}
|
12
|
+
spec.summary = %q{Provides rake tasks to create and deploy build artifacts to opsworks}
|
13
|
+
spec.homepage = "http://github.com/freerunningtech/oops"
|
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{^(spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "aws-sdk", "~> 1.11"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oops
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Clarke Brunsdon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-15 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: '1.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: 'Oops Opsworks Postal Service: Made to ship code'
|
56
|
+
email:
|
57
|
+
- clarke@freerunningtechnologies.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/oops.rb
|
68
|
+
- lib/oops/opsworks_deploy.rb
|
69
|
+
- lib/oops/railtie.rb
|
70
|
+
- lib/oops/tasks.rb
|
71
|
+
- lib/oops/version.rb
|
72
|
+
- oops.gemspec
|
73
|
+
homepage: http://github.com/freerunningtech/oops
|
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.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Provides rake tasks to create and deploy build artifacts to opsworks
|
97
|
+
test_files: []
|