capistrano-aws-autodiscover 2.0.0
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 +66 -0
- data/Rakefile +1 -0
- data/capistrano-aws-autodiscover.gemspec +26 -0
- data/lib/capistrano-aws-autodiscover.rb +66 -0
- data/lib/capistrano-aws-autodiscover/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c11063d1134ca7606a74185cb350632db469411
|
4
|
+
data.tar.gz: c694f743462e694b1718d7eb8b219129931748cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f556bf87d21157ef6ed8b17c5df51fbe264377161dc040c8b23a6967602edd95f0d76359a6f301192246a9a18bf34cd59332878facea105f0794a8a2880f3fc
|
7
|
+
data.tar.gz: 7af3577d5e0ba04ef9af861b27181143a11205fb636bd7924b0fc8aa51faa5b0a10522d1b9b17062dcc2015db27523423b611c445e11a8e3827d90c6d2621012
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -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', require: false
|
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
|
data/Rakefile
ADDED
@@ -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 'capistrano-aws-autodiscover/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capistrano-aws-autodiscover"
|
8
|
+
spec.version = CapistranoAwsAutodiscover::VERSION
|
9
|
+
spec.authors = ["Erez Rabih"]
|
10
|
+
spec.email = ["techutil@minutemedia.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/capistrano-aws-autodiscover"
|
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.7.11'
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "capistrano-aws-autodiscover/version"
|
2
|
+
require 'aws-sdk-core'
|
3
|
+
|
4
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
5
|
+
def define_servers
|
6
|
+
instances = CapistranoAwsAutodiscover.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 CapistranoAwsAutodiscover
|
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::Client.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
|
+
public_dns = instance.public_dns_name
|
61
|
+
roles_tag = instance.tags.find {|t| t.key == "Roles"}.value
|
62
|
+
roles = roles_tag.split(/,|;/)
|
63
|
+
[public_dns, roles].flatten
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-aws-autodiscover
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Erez Rabih
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-14 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.7.11
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.7.11
|
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
|
+
- techutil@minutemedia.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- capistrano-aws-autodiscover.gemspec
|
70
|
+
- lib/capistrano-aws-autodiscover.rb
|
71
|
+
- lib/capistrano-aws-autodiscover/version.rb
|
72
|
+
homepage: https://github.com/FTBpro/capistrano-aws-autodiscover
|
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.4.6
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Automatically defines servers in your capistrano deploy script
|
96
|
+
test_files: []
|
97
|
+
has_rdoc:
|