capistrano-releases 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/.rubocop.yml +51 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/capistrano-releases.gemspec +30 -0
- data/exe/releases +6 -0
- data/lib/capistrano/releases/cli.rb +53 -0
- data/lib/capistrano/releases/manager.rb +164 -0
- data/lib/capistrano/releases/version.rb +5 -0
- data/lib/capistrano/releases.rb +13 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f576772197a855bce09ece4f0886056a0b348adf
|
4
|
+
data.tar.gz: c8a7c0db269716dee53900117f70cb2db42c5ee9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 77883e54409de8e099b7d83b9718d2aba263eecd511d6f5cf5be0eec6b367d86450e3178e7050f27343aaf75b06738d95c5dd44072c5d322aa9d48dd136f9516
|
7
|
+
data.tar.gz: 9c6d41797623cebd8052ff02268ea83a8921ea9cfd510621e534da579f42142b927ed7e2b905cee225f1b8896f3ea99a4ab9baf7df82bfd5f9086bd0b50043c2
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
DisplayCopNames: true
|
4
|
+
|
5
|
+
Metrics/LineLength:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
MethodLength:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Metrics/AbcSize:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/BlockNesting:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/PerceivedComplexity:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/Documentation:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Style/ClassAndModuleChildren:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Metrics/CyclomaticComplexity:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/DoubleNegation:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Metrics/ClassLength:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/GuardClause:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/IfInsideElse:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Lint/HandleExceptions:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Style/SingleLineBlockParams:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Style/IdenticalConditionalBranches:
|
51
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.7
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Chad Remesch
|
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,40 @@
|
|
1
|
+
# Capistrano::Releases
|
2
|
+
Auto scaling AWS EC2 environments need a way to share the Capistrano 'releases' directory and 'current' symlink.
|
3
|
+
This gem provides that capability using AWS S3 to store releases.
|
4
|
+
Each release is stored as a zip file.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'capistrano-releases'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install capistrano-releases
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
$ releases --help
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
29
|
+
Then, run `rake test` to run the tests.
|
30
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
|
+
|
32
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/chadrem/capistrano-releases.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'capistrano/releases'
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'capistrano/releases/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'capistrano-releases'
|
9
|
+
spec.version = Capistrano::Releases::VERSION
|
10
|
+
spec.authors = ['Chad Remesch']
|
11
|
+
spec.email = ['chad@remesch.com']
|
12
|
+
|
13
|
+
spec.summary = 'Release manager for auto scaling environments.'
|
14
|
+
spec.description = 'Auto scaling environments need a way to share the releases directory. This gem provides that capability using AWS S3.'
|
15
|
+
spec.homepage = 'https://github.com/chadrem/capistrano-releases'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
28
|
+
|
29
|
+
spec.add_dependency 'aws-sdk', '> 2'
|
30
|
+
end
|
data/exe/releases
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Releases
|
3
|
+
# Command line interface class for Manager class.
|
4
|
+
class CLI
|
5
|
+
def run
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = 'Usage: manager [options]'
|
10
|
+
|
11
|
+
opts.on('-bBUCKET', '--bucket=BUCKET',
|
12
|
+
'S3 bucket to pull/push releases.') do |v|
|
13
|
+
options[:bucket] = v
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on('-dDEPLOY_TO', '--deploy-to=DEPLOY_TO',
|
17
|
+
'App directory to deploy to.') do |v|
|
18
|
+
options[:deploy_to] = v
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-mMODE', '--mode=MODE',
|
22
|
+
"Mode to run: 'push' or 'pull'") do |v|
|
23
|
+
options[:mode] = v
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
parser.parse!
|
28
|
+
|
29
|
+
unless options[:bucket]
|
30
|
+
puts('-b or --bucket is a required option.') && exit(1)
|
31
|
+
end
|
32
|
+
|
33
|
+
unless options[:deploy_to]
|
34
|
+
puts('-d or --deploy-to is a required option.') && exit(1)
|
35
|
+
end
|
36
|
+
|
37
|
+
puts('-m or --mode is a required option.') && exit(1) unless options[:mode]
|
38
|
+
|
39
|
+
manager = ::Capistrano::Releases::Manager.new(options)
|
40
|
+
|
41
|
+
case options[:mode]
|
42
|
+
when 'push'
|
43
|
+
manager.push
|
44
|
+
when 'pull'
|
45
|
+
manager.pull
|
46
|
+
else
|
47
|
+
puts 'Invalid mode.'
|
48
|
+
exit(1)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Releases
|
3
|
+
# Class for pushing/pulling Capistrano releases.
|
4
|
+
class Manager
|
5
|
+
attr_reader :params
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_reader :defaults
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_writer :defaults
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(parameters = {})
|
16
|
+
@params = parameters
|
17
|
+
|
18
|
+
params[:bucket] ||=
|
19
|
+
defaults[:bucket] || raise('bucket_name is a required parameter')
|
20
|
+
|
21
|
+
params[:deploy_to] ||=
|
22
|
+
defaults[:deploy_to] || raise('deploy_to is a required parameter')
|
23
|
+
|
24
|
+
params[:keep_releases] ||=
|
25
|
+
(defaults[:keep_releases] || 5)
|
26
|
+
end
|
27
|
+
|
28
|
+
def push
|
29
|
+
make_dirs
|
30
|
+
remotes = Set.new(remote_releases)
|
31
|
+
to_upload = local_releases.reject { |r| remotes.include?(r) }
|
32
|
+
to_upload.each { |r| upload(r) }
|
33
|
+
self.remote_current = local_current
|
34
|
+
|
35
|
+
to_upload
|
36
|
+
end
|
37
|
+
|
38
|
+
def pull
|
39
|
+
make_dirs
|
40
|
+
locals = Set.new(local_releases)
|
41
|
+
puts "Local releases: #{locals.to_a.inspect}"
|
42
|
+
to_download = remote_releases.last(params[:keep_releases])
|
43
|
+
.reject { |r| locals.include?(r) }
|
44
|
+
to_download.each do |r|
|
45
|
+
puts "Downloading release: #{r}"
|
46
|
+
download(r)
|
47
|
+
end
|
48
|
+
self.local_current = remote_current
|
49
|
+
puts "Setting local current to: #{local_current}"
|
50
|
+
Dir.chdir(File.join(params[:deploy_to], 'current'))
|
51
|
+
|
52
|
+
to_download
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def make_dirs
|
58
|
+
dirs = %w[
|
59
|
+
shared
|
60
|
+
shared/public
|
61
|
+
shared/public/assets
|
62
|
+
shared/public/system
|
63
|
+
shared/log
|
64
|
+
shared/tmp
|
65
|
+
shared/tmp/cache
|
66
|
+
shared/tmp/pids
|
67
|
+
shared/tmp/sockets
|
68
|
+
shared/vendor
|
69
|
+
releases
|
70
|
+
]
|
71
|
+
|
72
|
+
dirs.each do |dir|
|
73
|
+
full_dir = File.join(params[:deploy_to], dir)
|
74
|
+
unless Dir.exist?(full_dir)
|
75
|
+
Dir.mkdir(full_dir)
|
76
|
+
puts "Creating directory: #{full_dir}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def defaults
|
82
|
+
self.class.defaults || {}
|
83
|
+
end
|
84
|
+
|
85
|
+
def local_releases_path
|
86
|
+
File.join(params[:deploy_to], 'releases')
|
87
|
+
end
|
88
|
+
|
89
|
+
def local_releases
|
90
|
+
Dir.glob("#{local_releases_path}/*")
|
91
|
+
.sort
|
92
|
+
.map { |r| r.split('/').last }.sort
|
93
|
+
end
|
94
|
+
|
95
|
+
def remote_releases
|
96
|
+
bucket.objects
|
97
|
+
.map(&:key)
|
98
|
+
.select { |k| k.end_with?('.tar.gz') }
|
99
|
+
.map { |k| k.gsub(/\.tar\.gz\z/, '') }
|
100
|
+
.sort
|
101
|
+
end
|
102
|
+
|
103
|
+
def local_current
|
104
|
+
File.readlink(File.join(params[:deploy_to], 'current')).split('/').last
|
105
|
+
end
|
106
|
+
|
107
|
+
def remote_current
|
108
|
+
bucket.object('current.txt').get.body.read
|
109
|
+
end
|
110
|
+
|
111
|
+
def local_current=(release)
|
112
|
+
cur_path = File.join(params[:deploy_to], 'current')
|
113
|
+
rel_path = File.join(local_releases_path, release)
|
114
|
+
|
115
|
+
File.unlink(cur_path) if File.symlink?(cur_path)
|
116
|
+
File.symlink(rel_path, cur_path)
|
117
|
+
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
|
121
|
+
def remote_current=(release)
|
122
|
+
bucket.object('current.txt').put(body: release)
|
123
|
+
|
124
|
+
nil
|
125
|
+
end
|
126
|
+
|
127
|
+
def upload(release)
|
128
|
+
tmp = Tempfile.new(["capistrano-releases_upload-#{release}", '.tar.gz'],
|
129
|
+
Dir.tmpdir, encoding: 'BINARY')
|
130
|
+
|
131
|
+
begin
|
132
|
+
system!(['tar', 'Ccfz', local_releases_path, tmp.path, release])
|
133
|
+
bucket.object("#{release}.tar.gz").put(body: tmp)
|
134
|
+
ensure
|
135
|
+
tmp.close
|
136
|
+
tmp.unlink
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def download(release)
|
141
|
+
tmp = Tempfile.new(["capistrano-releases_download-#{release}", '.tar.gz'],
|
142
|
+
Dir.tmpdir, encoding: 'BINARY')
|
143
|
+
|
144
|
+
begin
|
145
|
+
bucket.object("#{release}.tar.gz").get(response_target: tmp)
|
146
|
+
system!(['tar', 'Cxfz', local_releases_path, tmp.path])
|
147
|
+
ensure
|
148
|
+
tmp.close
|
149
|
+
tmp.unlink
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def bucket
|
154
|
+
@bucket ||= Aws::S3::Bucket.new(params[:bucket])
|
155
|
+
end
|
156
|
+
|
157
|
+
def system!(cmd_array)
|
158
|
+
raise 'Must be an array' unless cmd_array.is_a?(Array)
|
159
|
+
cmd = cmd_array.map { |c| Shellwords.shellescape(c) }.join(' ')
|
160
|
+
raise "command failed: #{cmd}" unless system(cmd)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'shellwords'
|
3
|
+
require 'optparse'
|
4
|
+
require 'aws-sdk'
|
5
|
+
|
6
|
+
require 'capistrano/releases/version'
|
7
|
+
require 'capistrano/releases/cli'
|
8
|
+
require 'capistrano/releases/manager'
|
9
|
+
|
10
|
+
module Capistrano
|
11
|
+
module Releases
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-releases
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chad Remesch
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-31 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.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'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2'
|
69
|
+
description: Auto scaling environments need a way to share the releases directory.
|
70
|
+
This gem provides that capability using AWS S3.
|
71
|
+
email:
|
72
|
+
- chad@remesch.com
|
73
|
+
executables:
|
74
|
+
- releases
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- ".ruby-version"
|
81
|
+
- ".travis.yml"
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- capistrano-releases.gemspec
|
89
|
+
- exe/releases
|
90
|
+
- lib/capistrano/releases.rb
|
91
|
+
- lib/capistrano/releases/cli.rb
|
92
|
+
- lib/capistrano/releases/manager.rb
|
93
|
+
- lib/capistrano/releases/version.rb
|
94
|
+
homepage: https://github.com/chadrem/capistrano-releases
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.4.5.2
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Release manager for auto scaling environments.
|
118
|
+
test_files: []
|