capistrano-ec2ami 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 636017ca7ebbbd82abc780c96fbfc882a42299e3
4
+ data.tar.gz: 395b4d14e92b9af3b6b4a64fcf5bad07322fd84e
5
+ SHA512:
6
+ metadata.gz: 0d30568292efb623b0a1d1a891ef407c715e29eb55dcf40dbfc3d789651297e3f6b068b686770b9a07d9d72b9b4276e9e1f817867d7814c61ca5f220d793b9c4
7
+ data.tar.gz: c199c23ef29d33ab9fa59c689b7eff1a6645a7f6d251b6b49392185001440508680a50a4772e7f5acf4bad47cd596889d3200799153977321e4033e1cab77c8a
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,49 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-ec2ami (1.0.0)
5
+ capistrano (>= 2.1.0)
6
+ fog (>= 1.5.0)
7
+ rake
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ builder (3.2.2)
13
+ capistrano (2.15.5)
14
+ highline
15
+ net-scp (>= 1.0.0)
16
+ net-sftp (>= 2.0.0)
17
+ net-ssh (>= 2.0.14)
18
+ net-ssh-gateway (>= 1.1.0)
19
+ excon (0.25.3)
20
+ fog (1.14.0)
21
+ builder
22
+ excon (~> 0.25.0)
23
+ formatador (~> 0.2.0)
24
+ mime-types
25
+ multi_json (~> 1.0)
26
+ net-scp (~> 1.1)
27
+ net-ssh (>= 2.1.3)
28
+ nokogiri (~> 1.5)
29
+ ruby-hmac
30
+ formatador (0.2.4)
31
+ highline (1.6.19)
32
+ mime-types (1.23)
33
+ mini_portile (0.5.1)
34
+ multi_json (1.7.7)
35
+ net-scp (1.1.2)
36
+ net-ssh (>= 2.6.5)
37
+ net-sftp (2.1.2)
38
+ net-ssh (>= 2.6.5)
39
+ net-ssh (2.6.8)
40
+ net-ssh-gateway (1.2.0)
41
+ net-ssh (>= 2.6.5)
42
+ nokogiri (1.6.0)
43
+ mini_portile (~> 0.5.0)
44
+ rake (10.1.0)
45
+ ruby-hmac (0.4.0)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ capistrano-ec2ami!
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Alfred Moreno
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ = capistrano-ec2ami
2
+
3
+ Create AMI's from your EC2 instances with your capistrano scripts.
4
+
5
+ ## Usage
6
+
7
+ The following is a small example of how to create an AMI of a machine with role[:web]:
8
+
9
+ ```
10
+ require 'capistrano-ec2ami'
11
+
12
+ create_ami({
13
+ role: :web
14
+ name: 'ami-name-here',
15
+ description: 'ami-description-here',
16
+ no_reboot: true
17
+ })
18
+
19
+ ```
20
+
21
+ ## Requirements
22
+ You are expected to have ENV variables for your AWS credentials
23
+ * ENV['AWS_SECRET_ACCESS_KEY']
24
+ * ENV['AWS_ACCESS_KEY_ID']
25
+
26
+ ## Notes
27
+
28
+ * In my own experience, creating an AMI immediately after a deployment caused some kind of corruption in the AMI.
29
+ It may be some kind of latency issue with EBS and creating an AMI; I'm not sure. I solved the issue by
30
+ placing a 60s with `sleep 60` before creating my AMI.
31
+
32
+ * All parameters for options are optional. Capistrano-Ec2Ami will, by default, create your AMI with a name and description as
33
+ well as not reboot your instance.
34
+
35
+ == Contributing to capistrano-ec2ami
36
+
37
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
38
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
39
+ * Fork the project.
40
+ * Start a feature/bugfix branch.
41
+ * Commit and push until you are happy with your contribution.
42
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
43
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
44
+
45
+ == Copyright
46
+
47
+ Copyright (c) 2013 Alfred Moreno. See LICENSE.txt for
48
+ further details.
49
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano-ec2ami'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "capistrano-ec2ami"
8
+ gem.version = '1.0.0'
9
+ gem.authors = ["Alfred Moreno"]
10
+ gem.email = ["alfred.moreno@zumba.com"]
11
+ gem.description = %q{A capistrano plugin for creating EC2 AMIs}
12
+ gem.summary = %q{A capistrano plugin for creating EC2 AMIs}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'capistrano', '>=2.1.0'
21
+ gem.add_dependency 'fog', '>=1.5.0'
22
+ gem.add_dependency 'rake'
23
+
24
+ gem.license = 'MIT'
25
+ end
@@ -0,0 +1,87 @@
1
+ require 'fog'
2
+ require 'capistrano'
3
+
4
+ module Capistrano
5
+ module EC2AMI
6
+
7
+ ######################################################################
8
+ # def extend
9
+ #
10
+ # Purpose: Extends the module methods to the Capistrano class
11
+ #
12
+ # Returns: nothing
13
+ ######################################################################
14
+ def self.extend(configuration)
15
+
16
+ configuration.load do
17
+ Capistrano::Configuration.instance.load do
18
+
19
+ _cset(:aws_secret_access_key, ENV['AWS_SECRET_ACCESS_KEY'])
20
+ _cset(:aws_access_key_id, ENV['AWS_ACCESS_KEY_ID'])
21
+
22
+ ######################################################################
23
+ # def ec2
24
+ #
25
+ # Purpose: Creates a class variable for accessing AWS
26
+ #
27
+ # Returns: Fog::Compute::AWS
28
+ ######################################################################
29
+ def ec2
30
+ @@ec2 = Fog::Compute::AWS.new(
31
+ aws_secret_access_key: fetch(:aws_secret_access_key),
32
+ aws_access_key_id: fetch(:aws_access_key_id)
33
+ )
34
+ end
35
+
36
+ ######################################################################
37
+ # def find_instance_id
38
+ #
39
+ # Purpose: Returns the instance ID for a particular IP address
40
+ #
41
+ # Returns: String
42
+ ######################################################################
43
+ def find_instance_id(address)
44
+ ec2.servers.detect { |server|
45
+ server if (server.public_ip_address == address) || (server.private_ip_address == address)
46
+ }
47
+
48
+ end
49
+
50
+ ######################################################################
51
+ # def create_ami
52
+ #
53
+ # Purpose: Facilitates the creation of an AMI on AWS's EC2 service
54
+ #
55
+ # Parameters:
56
+ # options<~Hash>
57
+ # name<~Symbol>: The name for the AMI
58
+ # description<~Symbol>: The description for the AMI
59
+ # no_reboot<~Boolean>: Whether or not to reboot the instance
60
+ #
61
+ # Returns: String
62
+ ######################################################################
63
+ def create_ami(options={})
64
+ logger.info "\e[1;44m ## Creating AMI!\e[0m"
65
+ instance = find_instance_id(roles[options[:role]].servers.sample.host).id
66
+
67
+ ami_id = ec2.create_image(
68
+ instance,
69
+ options[:name] || "capistrano-ec2ami-#{Time.now.to_i}",
70
+ options[:description] || "AMI of instance #{instance} created by capistrano-ec2ami (#{Time.now})",
71
+ options[:no_reboot] || true
72
+ )
73
+
74
+ logger.info "\e[1;44m Successfully created AMI: #{ami_id.body['imageId']}\e[0m"
75
+ end
76
+
77
+
78
+ end
79
+ end
80
+
81
+ end
82
+ end
83
+ end
84
+
85
+ if Capistrano::Configuration.instance
86
+ Capistrano::EC2AMI.extend(Capistrano::Configuration.instance)
87
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'capistrano-ec2ami'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCapistranoEc2ami < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-ec2ami
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alfred Moreno
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: fog
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.0
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: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A capistrano plugin for creating EC2 AMIs
56
+ email:
57
+ - alfred.moreno@zumba.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .document
63
+ - .gitignore
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - capistrano-ec2ami.gemspec
70
+ - lib/capistrano-ec2ami.rb
71
+ - test/helper.rb
72
+ - test/test_capistrano-ec2ami.rb
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.0.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: A capistrano plugin for creating EC2 AMIs
97
+ test_files:
98
+ - test/helper.rb
99
+ - test/test_capistrano-ec2ami.rb