capistrano-ops_works 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .rbenv-gemsets
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-ops_works.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Hubert Liu
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,104 @@
1
+ # Capistrano::OpsWorks
2
+
3
+ A gem to help deploy rails applications to AWS OpsWorks, which hopefully works with capistrano 3
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-ops_works'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-ops_works
18
+
19
+ ## Usage
20
+
21
+ If you haven't installed [Capistrano](https://github.com/capistrano/capistrano), do that and make sure you
22
+
23
+ $ bundle exec cap install
24
+
25
+ Require the gem in your Capfile (example taken from default generated Capfile)
26
+
27
+ ```ruby
28
+
29
+ # Load DSL and Setup Up Stages
30
+ require 'capistrano/setup'
31
+
32
+ # Includes default deployment tasks
33
+ require 'capistrano/deploy'
34
+
35
+ require 'capistrano/ops_works'
36
+
37
+ # Includes tasks from other gems included in your Gemfile
38
+ #
39
+ # For documentation on these, see for example:
40
+ #
41
+ # https://github.com/capistrano/rvm
42
+ # https://github.com/capistrano/rbenv
43
+ # https://github.com/capistrano/chruby
44
+ # https://github.com/capistrano/bundler
45
+ # https://github.com/capistrano/rails/tree/master/assets
46
+ # https://github.com/capistrano/rails/tree/master/migrations
47
+ #
48
+ # require 'capistrano/rvm'
49
+ # require 'capistrano/rbenv'
50
+ # require 'capistrano/chruby'
51
+ # require 'capistrano/bundler'
52
+ # require 'capistrano/rails/assets'
53
+ # require 'capistrano/rails/migrations'
54
+
55
+ # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
56
+ Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
57
+
58
+ ```
59
+
60
+ In the appropriate stage deploy file, add your OpsWorks details
61
+
62
+ ```ruby
63
+
64
+ # /config/deploy/staging.rb
65
+ set :stage, :staging
66
+
67
+ set :access_key_id, '<aws_access_key_id>'
68
+ set :secret_access_key, '<aws_secret_access_key>'
69
+ set :stack_id, '<opsworks_stack_id>'
70
+ set :app_id, '<opsworks_app_id>'
71
+
72
+ ```
73
+
74
+ Check the task list using
75
+
76
+ $ bundle exec cap -T
77
+
78
+ Check your app_id
79
+
80
+ $ bundle exec cap staging opsworks:check
81
+
82
+ Deploy your app (you'll get a deployment_id back if it worked)
83
+
84
+ $ bundle exec cap staging opsworks
85
+ $ bundle exec cap staging opsworks:migrate
86
+
87
+ Check the history of your app deployments
88
+
89
+ $ bundle exec cap staging opsworks:history
90
+
91
+ ## FAQ
92
+
93
+ 1. Why is the name so ugly?
94
+ * [capistrano-opsworks](https://github.com/onemightyroar/capistrano-opsworks) was already taken, but unfortunately doesn't work with capistrano 3.
95
+ 2. Why are the task names namespaced with opsworks instead of ops_works?
96
+ * to make it less ugly, and easier to type
97
+
98
+ ## Contributing
99
+
100
+ 1. Fork it
101
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
102
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
103
+ 4. Push to the branch (`git push origin my-new-feature`)
104
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 'capistrano/ops_works/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-ops_works"
8
+ spec.version = Capistrano::OpsWorks::VERSION
9
+ spec.authors = ["Hubert Liu"]
10
+ spec.email = ["hubert.c.liu@gmail.com"]
11
+ spec.description = %q{AWS OpsWorks deployment with capistrano}
12
+ spec.summary = %q{Providing simple tasks to deploy to AWS OpsWorks using capistrano 3}
13
+ spec.homepage = "https://github.com/hcliu/capistrano-opsworks"
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "aws"
24
+ end
@@ -0,0 +1,68 @@
1
+ require 'aws/ops_works'
2
+
3
+ module Capistrano
4
+ module OpsWorks
5
+ class Connection
6
+
7
+ attr_reader :client
8
+
9
+ def initialize aws={}
10
+ access_key_id = aws.fetch(:access_key_id)
11
+ secret_access_key = aws.fetch(:secret_access_key)
12
+
13
+ @client = AWS::OpsWorks.new(\
14
+ :access_key_id => access_key_id,
15
+ :secret_access_key => secret_access_key).client
16
+
17
+ self
18
+ end
19
+
20
+ def deploy args={}
21
+ create_deployment args
22
+ end
23
+
24
+ def check args={}
25
+ stack_apps = describe args
26
+ app_id = args.fetch(:app_id)
27
+
28
+ stack_apps.data[:apps].collect { |a| a[:app_id] }.include? app_id
29
+ end
30
+
31
+ def history args={}
32
+ describe_deployments args
33
+ end
34
+
35
+ private
36
+
37
+ def describe_deployments args={}
38
+ client.describe_deployments(:app_id => args.fetch(:app_id))
39
+ end
40
+
41
+ def describe args={}
42
+ client.describe_apps(\
43
+ :stack_id => args.fetch(:stack_id)
44
+ )
45
+ end
46
+
47
+ def create_deployment args={}
48
+ stack_id = args.fetch(:stack_id)
49
+ app_id = args.fetch(:app_id)
50
+ command = args.fetch(:command)
51
+ comment = args.fetch(:comment, "")
52
+ custom_json = args.fetch(:custom_json, "")
53
+
54
+ client.create_deployment(\
55
+ :stack_id => stack_id,
56
+ :app_id => app_id,
57
+ :command => {
58
+ :name => command[:name],
59
+ :args => command[:args]
60
+ },
61
+ :comment => comment,
62
+ :custom_json => custom_json
63
+ )
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module OpsWorks
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'capistrano/ops_works/version'
2
+ require 'capistrano/ops_works/connection'
3
+
4
+ load File.expand_path("../tasks/ops_works.rake", __FILE__)
@@ -0,0 +1,54 @@
1
+ require 'capistrano/ops_works'
2
+
3
+ namespace :opsworks do
4
+
5
+ def opsworks
6
+ Capistrano::OpsWorks::Connection.new(\
7
+ :access_key_id => fetch(:access_key_id),
8
+ :secret_access_key => fetch(:secret_access_key)
9
+ )
10
+ end
11
+
12
+ def deployment_ids
13
+ {
14
+ :stack_id => fetch(:stack_id),
15
+ :app_id => fetch(:app_id)
16
+ }
17
+ end
18
+
19
+ def start_deploy command_args={}
20
+ ids = deployment_ids
21
+ deploy_opts = {
22
+ :command => {
23
+ :name => 'deploy',
24
+ :args => command_args
25
+ },
26
+ :comment => 'Capistrano OpsWorks Deploy'
27
+ }
28
+ opts = ids.merge(deploy_opts)
29
+
30
+ opsworks.deploy(opts)
31
+ end
32
+
33
+ task :default do
34
+ puts start_deploy
35
+ end
36
+
37
+ desc "Add command arg migrate=true to deploy (Rails app specific?)"
38
+ task :migrate do
39
+ puts start_deploy({"migrate"=>["true"]})
40
+ end
41
+
42
+ desc "Checks your app_id for validity"
43
+ task :check do
44
+ puts "app_id #{fetch(:app_id)} is valid" if opsworks.check(deployment_ids)
45
+ end
46
+
47
+ task :history do
48
+ puts opsworks.history(deployment_ids)
49
+ end
50
+
51
+ end
52
+
53
+ desc "Deploy to opsworks"
54
+ task :opsworks => ["opsworks:default"]
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-ops_works
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hubert Liu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: aws
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: AWS OpsWorks deployment with capistrano
63
+ email:
64
+ - hubert.c.liu@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - capistrano-ops_works.gemspec
75
+ - lib/capistrano/ops_works.rb
76
+ - lib/capistrano/ops_works/connection.rb
77
+ - lib/capistrano/ops_works/version.rb
78
+ - lib/capistrano/tasks/ops_works.rake
79
+ homepage: https://github.com/hcliu/capistrano-opsworks
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.23
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Providing simple tasks to deploy to AWS OpsWorks using capistrano 3
104
+ test_files: []