cap-aws-ec2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e942cb6af746db998577eb87de1daa113cd12d4c
4
+ data.tar.gz: 96c8d6b295e3399216ec52a5c06be307d14c2a95
5
+ SHA512:
6
+ metadata.gz: 0f45663a63372a298e4b5a0f8beb3e40cdc4cb893e9d1d951c1177ca1e3daf82b3c61663cb02a35ab6a6e5c7f341f718f16174722b11d01f005ce60a0afdea77
7
+ data.tar.gz: f61a5080476aba0311840e1594999ba284a417d1711ad3a59df076ea67935f09c6cafe3ea924196592e0251b2c52c62eb4d0c8bd02bfda773ce8ba7a426acf2b
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cap-aws-ec2.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Erez Rabih
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.
@@ -0,0 +1,66 @@
1
+ # Cap::Aws::Ec2
2
+
3
+ Tired of setting hardcoded ips or dns names in your capistrano deploy script?
4
+ You just found the solution!
5
+
6
+ cap-aws-ec2 will fetch instances from you EC2 region and define them by
7
+ project, environment and roles.
8
+
9
+ This gem should be used in conjunction with [capistrano multistage](https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension)
10
+
11
+ Note: This gem is only compatibale with Capistrano 2.x
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'cap-aws-ec2'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install cap-aws-ec2
26
+
27
+ ## Usage
28
+
29
+ 1. Define tags for your servers on EC2:
30
+
31
+ | Name Tag | Project Tag | Environment Tag | Roles Tag | Public IP |
32
+ | ------------- |:-------------:|:---------------:|:---------------:| ---------:|
33
+ | ftbpro-web1 | ftbpro-web | production | app,web | 1.1.1.1 |
34
+ | ftbpro-web2 | ftbpro-web | production | app,web | 2.2.2.2 |
35
+ | ftbpro-resque | ftbpro-web | production | app,resque | 3.3.3.3 |
36
+
37
+ 2. In your `deploy.rb` script:
38
+ ```ruby
39
+ require 'cap-aws-ec2'
40
+ set :aws_key_id, 'XXXXXXXXXXXXXX'
41
+ set :secret_access_key, 'XXXXXXXXXXXXXXXXXXXX'
42
+ set :aws_region, 'us-west-2'
43
+ set :ec2_project, 'my-project-tag-value'
44
+ set(:ec2_env) { stage }
45
+ ```
46
+
47
+ 3. In your corresponding stage file (`config/deploy/production.rb`):
48
+ ```ruby
49
+ define_servers
50
+ ```
51
+
52
+ This will result in the following statements:
53
+
54
+ ```ruby
55
+ server 1.1.1.1, :app, :web
56
+ server 2.2.2.2, :app, :web
57
+ server 3.3.3.3, :app, :resque
58
+ ```
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it ( http://github.com/<my-github-username>/cap-aws-ec2/fork )
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cap-aws-ec2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cap-aws-ec2"
8
+ spec.version = CapAwsEc2::VERSION
9
+ spec.authors = ["Erez Rabih"]
10
+ spec.email = ["erez.rabih@gmail.com"]
11
+ spec.summary = %q{Automatically defines servers in your capistrano deploy script}
12
+ spec.description = %q{Tired of changing dns names or ips in your deploy.rb? You found a solution! This gem uses EC2 tags in order to define servers in your deploy script. You can set project, environment and roles tags per instance to have total control.}
13
+
14
+ spec.homepage = "https://github.com/FTBpro/cap-aws-ec2"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake", '10.1.1'
24
+ spec.add_runtime_dependency "aws-sdk-core", "~> 2.0.0.rc2"
25
+
26
+ end
@@ -0,0 +1,66 @@
1
+ require "cap-aws-ec2/version"
2
+ require 'aws-sdk-core'
3
+
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ def define_servers
6
+ instances = CapAwsEc2.new(fetch(:aws_key_id), fetch(:secret_access_key), fetch(:aws_region), fetch(:ec2_project), fetch(:ec2_env)).execute
7
+ instances.each {|s| server *s}
8
+ end
9
+ end
10
+
11
+ class CapAwsEc2
12
+
13
+ def initialize(key, secret, aws_region, project, environment)
14
+ @key = key
15
+ @secret = secret
16
+ @region = aws_region
17
+ @project = project.to_s
18
+ @environment = environment.to_s
19
+ end
20
+
21
+ def execute
22
+ instances = ec2.describe_instances(instance_ids: tagged_instances,
23
+ filters: [
24
+ {name: "instance-state-name", values: ["running"]},
25
+ {name: "tag:Env", values: [@environment]},
26
+ {name: "tag:Project", values: [@project]},
27
+ {name: "tag-key", values: ["Roles"]}
28
+ ]
29
+ )
30
+ instances = instances.reservations.map {|r| r.instances }.flatten
31
+
32
+ server_definitions(instances)
33
+ end
34
+
35
+ private
36
+
37
+ def ec2
38
+ @ec2 ||= begin
39
+ Aws.config = { access_key_id: @key,
40
+ secret_access_key: @secret,
41
+ region: @region }
42
+ Aws::EC2.new
43
+ end
44
+ end
45
+
46
+ def tagged_instances
47
+ tags = ec2.describe_tags({filters: [
48
+ {name: "resource-type", values: ["instance"]},
49
+ {name: "key", values: ["Project"]}]
50
+ })
51
+
52
+ tags.tags.map(&:resource_id)
53
+ end
54
+
55
+ def server_definitions(instances)
56
+ instances.map {|i| make_args(i)}
57
+ end
58
+
59
+ def make_args(instance)
60
+ ip = instance.public_ip_address
61
+ roles_tag = instance.tags.find {|t| t.key == "Roles"}.value
62
+ roles = roles_tag.split(/,|;/)
63
+ [ip, roles].flatten
64
+ end
65
+
66
+ end
@@ -0,0 +1,3 @@
1
+ class CapAwsEc2
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cap-aws-ec2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Erez Rabih
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 10.1.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 10.1.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-core
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0.rc2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0.rc2
55
+ description: Tired of changing dns names or ips in your deploy.rb? You found a solution!
56
+ This gem uses EC2 tags in order to define servers in your deploy script. You can
57
+ set project, environment and roles tags per instance to have total control.
58
+ email:
59
+ - erez.rabih@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - cap-aws-ec2.gemspec
70
+ - lib/cap-aws-ec2.rb
71
+ - lib/cap-aws-ec2/version.rb
72
+ homepage: https://github.com/FTBpro/cap-aws-ec2
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Automatically defines servers in your capistrano deploy script
96
+ test_files: []
97
+ has_rdoc: