capistrano3-ec2-minimal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/capistrano3-ec2-minimal.gemspec +29 -0
- data/lib/capistrano/ec2/minimal.rb +49 -0
- data/lib/capistrano/ec2/minimal/version.rb +7 -0
- data/lib/capistrano/tasks/ec2.rake +43 -0
- data/lib/capistrano3-ec2-minimal.rb +0 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dcb8cbb8b4e34f5586fd25e5989011a1bf79ef60
|
4
|
+
data.tar.gz: 714ffc0672f998b9ae31cad7c6528091d0db0f4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 649658729eefb79d889fc8c1f2087c0f5a42fc7d6bd71f743edbd1e301e610f8e04201825bcb597178acc06c55cf4d0583bac147994f7aed1c90d4cfe0df0756
|
7
|
+
data.tar.gz: 2c2ff0836a8c1afab8169c71299a6d375538752fd10be6437c7e6e1bca3cc2e7936a3e36bf1789ad3b964f7c12b465e626c4b48c90acf5ee037be944b83f6762
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Capistrano3::Ec2::Minimal
|
2
|
+
|
3
|
+
AWS SDK v2 を使って [forward3d/cap-ec2](https://github.com/forward3d/cap-ec2) の最小限の機能を実装する。
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'capistrano3-ec2-minimal'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install capistrano3-ec2-minimal
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In config/deploy.rb:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Rake::Task[fetch(:stage)].enhance do
|
27
|
+
ec2_set_servers user: 'ec2-user'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
tag:Project > tag:Stage > running で絞り込んだインスタンスが対象。
|
32
|
+
roles は tag:Roles (カンマ区切りで複数指定可) から読み取って設定される。
|
33
|
+
|
34
|
+
※ 注) cap-ec2 では tag:Stages と複数前提だが、ここでは tag:Stage で単一指定としている。
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( https://github.com/[my-github-username]/capistrano3-ec2-minimal/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "capistrano/ec2/minimal"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/ec2/minimal/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capistrano3-ec2-minimal"
|
8
|
+
spec.version = Capistrano::Ec2::Minimal::VERSION
|
9
|
+
spec.authors = ["koshigoe"]
|
10
|
+
spec.email = ["koshigoeb@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This is an minimal ec2 support for Capistrano3 using AWS SDK v2. (like cap-ec2) }
|
13
|
+
spec.description = %q{This is an minimal ec2 support for Capistrano3 using AWS SDK v2. (like cap-ec2) }
|
14
|
+
spec.homepage = "https://github.com/koshigoe/capistrano3-ec2-minimal"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
spec.add_dependency 'capistrano', '~> 3.0'
|
26
|
+
spec.add_dependency 'aws-sdk', '~> 2.0'
|
27
|
+
spec.add_dependency 'terminal-table'
|
28
|
+
spec.add_dependency 'colorize'
|
29
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'capistrano/ec2/minimal/version'
|
2
|
+
require 'aws-sdk-core'
|
3
|
+
|
4
|
+
module Capistrano
|
5
|
+
module DSL
|
6
|
+
module Ec2
|
7
|
+
module Minimal
|
8
|
+
class Instances
|
9
|
+
include Enumerable
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
ec2 = Aws::EC2::Client.new
|
13
|
+
filters = [
|
14
|
+
{ name: 'tag:Project', values: [fetch(:application)] },
|
15
|
+
{ name: 'tag:Stage', values: [fetch(:stage)] },
|
16
|
+
{ name: 'instance-state-name', values: %w(running) },
|
17
|
+
]
|
18
|
+
@reservations = ec2.describe_instances(filters: filters).reservations
|
19
|
+
end
|
20
|
+
|
21
|
+
def each
|
22
|
+
@reservations.each do |reservation|
|
23
|
+
reservation.instances.each do |instance|
|
24
|
+
yield(instance)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def ec2_each_instances
|
31
|
+
Instances.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def ec2_set_servers(options = {})
|
35
|
+
Instances.new.each do |instance|
|
36
|
+
if roles_tag = instance.tags.find { |tag| tag.key == 'Roles' }
|
37
|
+
roles = roles_tag.value.split(',').map(&:strip).reject(&:empty?).uniq
|
38
|
+
options[:roles] = roles unless roles.empty?
|
39
|
+
end
|
40
|
+
server instance.private_ip_address, options
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
extend Capistrano::DSL::Ec2::Minimal
|
48
|
+
|
49
|
+
load File.expand_path("../../tasks/ec2.rake", __FILE__)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'terminal-table'
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
namespace :ec2 do
|
5
|
+
desc 'Show matched ec2 instances.'
|
6
|
+
task :list do
|
7
|
+
table = Terminal::Table.new(
|
8
|
+
:style => {
|
9
|
+
:border_x => "",
|
10
|
+
:border_i => "",
|
11
|
+
:border_y => ""
|
12
|
+
}
|
13
|
+
)
|
14
|
+
table.add_row [
|
15
|
+
"Num".colorize(:bold),
|
16
|
+
"Name".colorize(:bold),
|
17
|
+
"ID".colorize(:bold),
|
18
|
+
"Type".colorize(:bold),
|
19
|
+
"Zone".colorize(:bold),
|
20
|
+
"Roles".colorize(:bold),
|
21
|
+
"Stage".colorize(:bold)
|
22
|
+
]
|
23
|
+
ec2_each_instances.each_with_index do |instance, index|
|
24
|
+
name_tag = instance.tags.find{|t| t.key == 'Name' }
|
25
|
+
name_tag = name_tag ? name_tag.value : ''
|
26
|
+
roles_tag = instance.tags.find{|t| t.key == 'Roles' }
|
27
|
+
roles_tag = roles_tag ? roles_tag.value : ''
|
28
|
+
stage_tag = instance.tags.find{|t| t.key == 'Stage' }
|
29
|
+
stage_tag = stage_tag ? stage_tag.value : ''
|
30
|
+
|
31
|
+
table.add_row [
|
32
|
+
sprintf("%02d:", index),
|
33
|
+
name_tag.colorize(:green),
|
34
|
+
instance.instance_id.colorize(:red),
|
35
|
+
instance.instance_type.colorize(:cyan),
|
36
|
+
instance.placement.availability_zone.colorize(:magenta),
|
37
|
+
roles_tag.colorize(:yellow),
|
38
|
+
stage_tag.colorize(:yellow),
|
39
|
+
]
|
40
|
+
end
|
41
|
+
puts table.to_s
|
42
|
+
end
|
43
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano3-ec2-minimal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- koshigoe
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-07 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.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
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.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capistrano
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: terminal-table
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: colorize
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: 'This is an minimal ec2 support for Capistrano3 using AWS SDK v2. (like
|
98
|
+
cap-ec2) '
|
99
|
+
email:
|
100
|
+
- koshigoeb@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Gemfile
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- bin/console
|
110
|
+
- bin/setup
|
111
|
+
- capistrano3-ec2-minimal.gemspec
|
112
|
+
- lib/capistrano/ec2/minimal.rb
|
113
|
+
- lib/capistrano/ec2/minimal/version.rb
|
114
|
+
- lib/capistrano/tasks/ec2.rake
|
115
|
+
- lib/capistrano3-ec2-minimal.rb
|
116
|
+
homepage: https://github.com/koshigoe/capistrano3-ec2-minimal
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.4.5
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: This is an minimal ec2 support for Capistrano3 using AWS SDK v2. (like cap-ec2)
|
140
|
+
test_files: []
|