capistrano-aws 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36f8068fe4189961d4b658b2327961eba895a6d7
4
+ data.tar.gz: 964f33859ec0721fb3c3d4680c16eec25d1f76f3
5
+ SHA512:
6
+ metadata.gz: c45c598219bb94f3df58a60aace8e89d309601bcbaf0de8f67e5cc0bc4217ce40c641396dce549983cf7e073a4e28faf769224b47dab0abd3965d7c9fc32e06b
7
+ data.tar.gz: 913f99fc03edcebc48f02d39e65debdce046f01bc0c2c3f91f95f20219beee908b88460b61ffd184eab9c2af79ffb83f4fe1a313bf4fff5db928f7d5f7eb21d8
data/.editorconfig ADDED
@@ -0,0 +1,3 @@
1
+ [*]
2
+ indent_style = space
3
+ indent_size = 2
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .bundle
2
+ vendor
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ Metrics/AbcSize:
2
+ Max: 20
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Metrics/MethodLength:
8
+ Max: 25
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-aws (0.0.1)
5
+ aws-sdk (~> 2.9)
6
+ colorize (~> 0.8)
7
+ terminal-table (~> 1.7)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.3.0)
13
+ aws-sdk (2.9.15)
14
+ aws-sdk-resources (= 2.9.15)
15
+ aws-sdk-core (2.9.15)
16
+ aws-sigv4 (~> 1.0)
17
+ jmespath (~> 1.0)
18
+ aws-sdk-resources (2.9.15)
19
+ aws-sdk-core (= 2.9.15)
20
+ aws-sigv4 (1.0.0)
21
+ colorize (0.8.1)
22
+ jmespath (1.3.1)
23
+ parser (2.4.0.0)
24
+ ast (~> 2.2)
25
+ powerpack (0.1.1)
26
+ rainbow (2.2.2)
27
+ rake
28
+ rake (12.0.0)
29
+ rubocop (0.48.1)
30
+ parser (>= 2.3.3.1, < 3.0)
31
+ powerpack (~> 0.1)
32
+ rainbow (>= 1.99.1, < 3.0)
33
+ ruby-progressbar (~> 1.7)
34
+ unicode-display_width (~> 1.0, >= 1.0.1)
35
+ ruby-progressbar (1.8.1)
36
+ terminal-table (1.7.0)
37
+ unicode-display_width (~> 1.1)
38
+ unicode-display_width (1.2.1)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ capistrano-aws!
45
+ rubocop (~> 0.48)
46
+
47
+ BUNDLED WITH
48
+ 1.14.6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Fernando Carletti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ Capistrano AWS
2
+ ==============
3
+
4
+ This gem is slightly based on [cap-ec2](https://github.com/forward3d/cap-ec2), which is not maintained for a while, becoming outdated.
5
+
6
+ The purpose of this gem is to provide a flexible and simple integration to AWS EC2, exposing the aws-sdk connection in order to allow any customization.
7
+
8
+ # Requirements
9
+
10
+ * Capistrano 3
11
+
12
+ # Installation
13
+
14
+ Add to your `Gemfile` and run `bundler`:
15
+ ```ruby
16
+ gem 'capistrano-aws'
17
+ ```
18
+
19
+ Or install the gem system-wide:
20
+ ```bash
21
+ gem install cap-ec2
22
+ ```
23
+
24
+ In your `Capfile`:
25
+ ```ruby
26
+ require 'capistrano/aws'
27
+ ```
28
+
29
+ # Configuration
30
+
31
+ ```ruby
32
+ # AWS regions to use.
33
+ set :aws_ec2_regions, ['us-east-1']
34
+
35
+ # Application name to match application tag.
36
+ set :aws_ec2_application, (proc { fetch(:application) })
37
+
38
+ # Tag to be used for Capistrano stage.
39
+ set :aws_ec2_stage_tag, 'Stage'
40
+
41
+ # Tag to be used to match the application.
42
+ set :aws_ec2_application_tag, 'Application'
43
+
44
+ # Tag to be used for Capistrano roles of the server (comma separated list).
45
+ set :aws_ec2_roles_tag, 'Roles'
46
+
47
+ # How to contact the instance (:public_ip, :public_dns, :private_ip).
48
+ set :aws_ec2_contact_point, :public_ip
49
+ ```
50
+
51
+ The AWS credentials are loaded from your system. Check https://github.com/aws/aws-sdk-ruby#configuration for more information.
52
+
53
+ # Usage
54
+
55
+ The instances must be registered in each stage. In your `config/deploy/<stage_name>.rb`, add the following line:
56
+
57
+ ```ruby
58
+ aws_ec2_register
59
+ ```
60
+
61
+ It will use the instance tags to call the `server` function in capistrano. You can pass a hash as an argument, and it will be merged into the function call:
62
+
63
+ ```ruby
64
+ aws_ec2_register user: 'hello', port: 2222
65
+ ```
66
+
67
+ # Utility tasks
68
+
69
+ ## aws:ec2:instances
70
+
71
+ List all the instances found for with the current configuration.
72
+
73
+ ```bash
74
+ cap production aws:ec2:instances
75
+ ```
76
+
77
+ # Contributing
78
+
79
+ Open an issue or make a PR, feel free to contribute!
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'capistrano-aws'
8
+ gem.version = '1.0.0'
9
+ gem.author = 'Fernando Carletti'
10
+ gem.email = 'contact@fernandocarletti.net'
11
+ gem.homepage = 'http://github.com/xurumelous/capistrano-aws'
12
+ gem.summary = 'Integrates capistrano with AWS.'
13
+ gem.description = 'Allow dynamically add servers based on EC2.'
14
+
15
+ gem.license = 'MIT'
16
+
17
+ gem.files = `git ls-files -z`.split("\x0").reject { |f| f =~ /^docs/ }
18
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ['lib']
21
+
22
+ gem.required_ruby_version = '>= 2.0'
23
+
24
+ gem.add_dependency 'aws-sdk', '~>2.9'
25
+ gem.add_dependency 'terminal-table', '~>1.7'
26
+ gem.add_dependency 'colorize', '~>0.8'
27
+
28
+ gem.add_development_dependency 'rubocop', '~>0.48'
29
+ end
@@ -0,0 +1,11 @@
1
+ require 'capistrano/aws/ec2/ec2'
2
+ require 'capistrano/dsl/aws'
3
+ extend Capistrano::DSL::Aws
4
+
5
+ load File.expand_path('../tasks/ec2.rake', __FILE__)
6
+
7
+ namespace :load do
8
+ task :defaults do
9
+ load 'capistrano/aws/defaults.rb'
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ # AWS regions to use.
2
+ set :aws_ec2_regions, ['us-east-1']
3
+
4
+ # Application name to match application tag.
5
+ set :aws_ec2_application, (proc { fetch(:application) })
6
+
7
+ # Tag to be used for Capistrano stage.
8
+ set :aws_ec2_stage_tag, 'Stage'
9
+
10
+ # Tag to be used to match the application.
11
+ set :aws_ec2_application_tag, 'Application'
12
+
13
+ # Tag to be used for Capistrano roles of the server (comma separated list).
14
+ set :aws_ec2_roles_tag, 'Roles'
15
+
16
+ # How to contact the instance (:public_ip, :public_dns, :private_ip).
17
+ set :aws_ec2_contact_point, :public_ip
@@ -0,0 +1,77 @@
1
+ require 'singleton'
2
+ require 'aws-sdk'
3
+
4
+ module Capistrano
5
+ module Aws
6
+ # EC2 module.
7
+ module EC2
8
+ # Handle EC2.
9
+ class EC2
10
+ include Singleton
11
+
12
+ def initialize
13
+ @ec2 = {}
14
+
15
+ regions.each do |region|
16
+ @ec2[region] = ::Aws::EC2::Resource.new(region: region)
17
+ end
18
+ end
19
+
20
+ def regions
21
+ fetch(:aws_ec2_regions)
22
+ end
23
+
24
+ def instances
25
+ application = fetch(:aws_ec2_application)
26
+ raise 'application not set.' if application.nil?
27
+
28
+ instances = []
29
+
30
+ filters = [
31
+ {
32
+ name: "tag:#{fetch(:aws_ec2_application_tag)}",
33
+ values: [fetch(:aws_ec2_application)]
34
+ },
35
+ {
36
+ name: "tag:#{fetch(:aws_ec2_stage_tag)}",
37
+ values: [fetch(:stage)]
38
+ },
39
+ {
40
+ name: 'instance-state-name',
41
+ values: ['running']
42
+ }
43
+ ]
44
+
45
+ @ec2.each do |_region, client|
46
+ client.instances(filters: filters).each do |instance|
47
+ instances << instance
48
+ end
49
+ end
50
+
51
+ instances
52
+ end
53
+ end
54
+
55
+ def self.contact_point(instance)
56
+ case fetch(:aws_ec2_contact_point)
57
+ when :private_ip
58
+ instance.private_ip_address
59
+ when :public_dns
60
+ instance.public_dns_name
61
+ else
62
+ instance.public_ip_address
63
+ end
64
+ end
65
+
66
+ def self.parse_tag(instance, tag_name)
67
+ tag = instance.tags.select { |instance_tag| instance_tag.key == tag_name }.first
68
+
69
+ if tag.nil?
70
+ ''
71
+ else
72
+ tag.value
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,61 @@
1
+ require 'terminal-table'
2
+ require 'colorize'
3
+
4
+ module Capistrano
5
+ module Aws
6
+ module EC2
7
+ # Generates instances table.
8
+ class InstancesTable
9
+ def initialize(instances)
10
+ @instances = instances
11
+ end
12
+
13
+ def render
14
+ table = Terminal::Table.new(
15
+ style: {
16
+ border_x: '',
17
+ border_i: '',
18
+ border_y: ''
19
+ }
20
+ )
21
+
22
+ table.add_row header_row
23
+
24
+ number = 1
25
+ @instances.each do |instance|
26
+ table.add_row instance_row(number, instance)
27
+ number += 1
28
+ end
29
+
30
+ puts table
31
+ end
32
+
33
+ def header_row
34
+ [
35
+ 'Num'.colorize(mode: :bold),
36
+ 'ID'.colorize(mode: :bold),
37
+ 'Name'.colorize(mode: :bold),
38
+ 'Type'.colorize(mode: :bold),
39
+ 'Contact Point'.colorize(mode: :bold),
40
+ 'Availability Zone'.colorize(mode: :bold),
41
+ 'Roles'.colorize(mode: :bold),
42
+ 'Stages'.colorize(mode: :bold)
43
+ ]
44
+ end
45
+
46
+ def instance_row(number, instance)
47
+ [
48
+ format('%02d:', number),
49
+ instance.id.colorize(:red),
50
+ Capistrano::Aws::EC2.parse_tag(instance, 'Name').colorize(:green),
51
+ instance.instance_type.colorize(:cyan),
52
+ Capistrano::Aws::EC2.contact_point(instance).colorize(:blue),
53
+ instance.placement.availability_zone.colorize(:magenta),
54
+ Capistrano::Aws::EC2.parse_tag(instance, fetch(:aws_ec2_roles_tag)).colorize(:yellow),
55
+ Capistrano::Aws::EC2.parse_tag(instance, fetch(:aws_ec2_stage_tag)).colorize(:yellow)
56
+ ]
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,19 @@
1
+ module Capistrano
2
+ module DSL
3
+ # Capistrano Aws module.
4
+ module Aws
5
+ def aws_ec2
6
+ Capistrano::Aws::EC2::EC2.instance
7
+ end
8
+
9
+ def aws_ec2_register(options = {})
10
+ aws_ec2.instances.each do |instance|
11
+ ip = Capistrano::Aws::EC2.contact_point(instance)
12
+ roles = Capistrano::Aws::EC2.parse_tag(instance, fetch(:aws_ec2_roles_tag)).split(',')
13
+
14
+ server ip, options.merge(roles: roles, aws_instance_id: instance.id)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ require 'capistrano/aws/ec2/instances_table'
2
+
3
+ namespace :aws do
4
+ namespace :ec2 do
5
+ desc 'List available instances.'
6
+ task :instances do
7
+ Capistrano::Aws::EC2::InstancesTable.new(aws_ec2.instances).render
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-aws
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Fernando Carletti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-05 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: '2.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: terminal-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.48'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.48'
69
+ description: Allow dynamically add servers based on EC2.
70
+ email: contact@fernandocarletti.net
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".editorconfig"
76
+ - ".gitignore"
77
+ - ".rubocop.yml"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE
81
+ - README.md
82
+ - capistrano-aws.gemspec
83
+ - lib/capistrano/aws.rb
84
+ - lib/capistrano/aws/defaults.rb
85
+ - lib/capistrano/aws/ec2/ec2.rb
86
+ - lib/capistrano/aws/ec2/instances_table.rb
87
+ - lib/capistrano/dsl/aws.rb
88
+ - lib/capistrano/tasks/ec2.rake
89
+ homepage: http://github.com/xurumelous/capistrano-aws
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '2.0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.11
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Integrates capistrano with AWS.
113
+ test_files: []