mina-ec2 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +58 -0
- data/lib/mina/.DS_Store +0 -0
- data/lib/mina/ec2.rb +117 -0
- data/lib/mina/ec2/version.rb +5 -0
- data/mina_ec2.gemspec +27 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b82ebdd1c91852b856897e2fe5ff6d91838fa865
|
4
|
+
data.tar.gz: c3b0104de8555b25fee0a9b02f24b3aba2e7ded4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2877cc1120a72cdcaec61dccf1622ec7a469f9078dc1ff4142185fe1263d042527b51d303f5080c9fe9427b05caba83fd539fba5592362ad86f1638dfde31952
|
7
|
+
data.tar.gz: d4cad6a1c63b89b66568b85f85ff8e4b4a2af7cac262360a1c491f81d3405f98bc4f1f1d53f86c806f54bd2a4db32914e0cf22db52688e3eab593c0ee7f4e6b8
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Rickard Dybeck
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Mina EC2
|
2
|
+
Helper library to deploy to several EC2 instances using [Mina](https://github.com/mina-deploy/mina/)
|
3
|
+
|
4
|
+
## Installing
|
5
|
+
|
6
|
+
Add to gemfile:
|
7
|
+
|
8
|
+
gem 'mina-ec2'
|
9
|
+
|
10
|
+
Add to config/deploy.rb
|
11
|
+
|
12
|
+
require 'mina/ec2'
|
13
|
+
|
14
|
+
## Configuration
|
15
|
+
### AWS Credentials
|
16
|
+
Set AWS credentials to use, and which region(s) to deploy to.
|
17
|
+
|
18
|
+
set :ec2_settings, {
|
19
|
+
regions: %w{eu-west-1},
|
20
|
+
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
21
|
+
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY_ID']
|
22
|
+
}
|
23
|
+
|
24
|
+
### Filtering instance
|
25
|
+
Set tags to find your instances by:
|
26
|
+
|
27
|
+
set :ec2_tags, {
|
28
|
+
'Team' => 'my-team',
|
29
|
+
'Project' => 'my-app',
|
30
|
+
'Stages' => 'staging'
|
31
|
+
}
|
32
|
+
|
33
|
+
### Migrations
|
34
|
+
Split out the `rails:db_migrate` invocation, since we don't want to run it from several servers. If you do want to run it from several servers (for example if each of your app servers has their own sqlite3 database), just leave it as a part of the `deploy {}` block.
|
35
|
+
|
36
|
+
desc "Deploys the current version to the server."
|
37
|
+
task :deploy => :environment do
|
38
|
+
deploy do
|
39
|
+
invoke :'git:clone'
|
40
|
+
invoke :'deploy:link_shared_paths'
|
41
|
+
invoke :'bundle:install'
|
42
|
+
invoke :'rails:assets_precompile'
|
43
|
+
invoke :'deploy:cleanup'
|
44
|
+
|
45
|
+
to :launch do
|
46
|
+
queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
|
47
|
+
queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
set :domain, fetch(:ec2_domains).sample
|
52
|
+
invoke :'rails:db_migrate'
|
53
|
+
end
|
54
|
+
|
55
|
+
## Usage
|
56
|
+
Invoke with
|
57
|
+
|
58
|
+
mina ec2:deploy
|
data/lib/mina/.DS_Store
ADDED
Binary file
|
data/lib/mina/ec2.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'aws-sdk-v1'
|
2
|
+
require 'parallel'
|
3
|
+
|
4
|
+
module Mina
|
5
|
+
class EC2
|
6
|
+
attr_accessor :ec2
|
7
|
+
attr_reader :tags, :project_tag
|
8
|
+
|
9
|
+
def initialize(tags, project_tag, settings)
|
10
|
+
@tags = tags
|
11
|
+
@project_tag = project_tag
|
12
|
+
|
13
|
+
@ec2 = {}
|
14
|
+
settings[:regions].each do |region|
|
15
|
+
@ec2[region] = ec2_connect(
|
16
|
+
region: region,
|
17
|
+
access_key_id: settings[:access_key_id],
|
18
|
+
secret_access_key: settings[:secret_access_key]
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def ec2_connect(region: nil, access_key_id:, secret_access_key:)
|
24
|
+
AWS.start_memoizing
|
25
|
+
AWS::EC2.new(
|
26
|
+
access_key_id: access_key_id,
|
27
|
+
secret_access_key: secret_access_key,
|
28
|
+
region: region
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_servers
|
33
|
+
servers = []
|
34
|
+
@ec2.each do |_, ec2|
|
35
|
+
instances = ec2.instances
|
36
|
+
.filter(tag(project_tag), "*#{project}*")
|
37
|
+
.filter('instance-state-name', 'running')
|
38
|
+
servers << instances.select do |i|
|
39
|
+
verify_instance_tags(i)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
servers.flatten.sort_by {|s| s.tags["Name"] || ''}
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_domain(instance)
|
46
|
+
instance.public_dns_name || instance.public_ip_address || instance.private_ip_address
|
47
|
+
end
|
48
|
+
|
49
|
+
def tag(tag_name)
|
50
|
+
"tag:#{tag_name}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def project
|
54
|
+
tags[project_tag]
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def get_regions(regions=nil)
|
59
|
+
unless regions.nil? || regions.empty?
|
60
|
+
return regions
|
61
|
+
else
|
62
|
+
@ec2 = ec2_connect
|
63
|
+
@ec2.regions.map(&:name)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def verify_instance_tags(instance)
|
68
|
+
missing = []
|
69
|
+
|
70
|
+
@tags.each do |name, value|
|
71
|
+
missing << name unless (instance.tags[name.to_s.capitalize] || '').split(',').map(&:strip).include?(value.to_s)
|
72
|
+
end
|
73
|
+
|
74
|
+
missing.empty?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
namespace :ec2 do
|
80
|
+
task :get_domains do
|
81
|
+
mec2 = Mina::EC2.new(
|
82
|
+
fetch(:ec2_tags),
|
83
|
+
fetch(:ec2_project_tag, 'Project'),
|
84
|
+
fetch(:ec2_settings)
|
85
|
+
)
|
86
|
+
|
87
|
+
set :ec2_domains, mec2.get_servers.inject([]) { |memo, instance| memo << mec2.get_domain(instance) }
|
88
|
+
end
|
89
|
+
|
90
|
+
task :setup do
|
91
|
+
to :before_hook do
|
92
|
+
invoke :'ec2:get_domains'
|
93
|
+
end
|
94
|
+
|
95
|
+
isolate do
|
96
|
+
Parallel.each(fetch(:ec2_domains)) do |domain|
|
97
|
+
set :domain, domain
|
98
|
+
invoke :setup
|
99
|
+
run!
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
task :deploy do
|
105
|
+
to :before_hook do
|
106
|
+
invoke :'ec2:get_domains'
|
107
|
+
end
|
108
|
+
|
109
|
+
isolate do
|
110
|
+
Parallel.each(fetch(:ec2_domains)) do |domain|
|
111
|
+
set :domain, domain
|
112
|
+
invoke :deploy
|
113
|
+
run!
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/mina_ec2.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mina/ec2/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mina-ec2"
|
8
|
+
spec.version = Mina::EC2::VERSION
|
9
|
+
spec.authors = ["Rickard Dybeck"]
|
10
|
+
spec.email = ["r.dybeck@gmail.com"]
|
11
|
+
spec.description = %q{Adds support for Mina to deploy to EC2}
|
12
|
+
spec.summary = %q{Adds support for Mina to deploy to EC2}
|
13
|
+
spec.homepage = "http://github.com/alde/mina-ec2"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "mina", ">= 0.2.1"
|
22
|
+
spec.add_dependency "aws-sdk-v1"
|
23
|
+
spec.add_dependency 'parallel'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", ">= 1.3.5"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mina-ec2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rickard Dybeck
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mina
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk-v1
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: parallel
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.5
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.5
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Adds support for Mina to deploy to EC2
|
84
|
+
email:
|
85
|
+
- r.dybeck@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- lib/mina/.DS_Store
|
95
|
+
- lib/mina/ec2.rb
|
96
|
+
- lib/mina/ec2/version.rb
|
97
|
+
- mina_ec2.gemspec
|
98
|
+
homepage: http://github.com/alde/mina-ec2
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.2.2
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Adds support for Mina to deploy to EC2
|
122
|
+
test_files: []
|