capistrano-fast_deploy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +1 -0
- data/capistrano-fast_deploy.gemspec +22 -0
- data/lib/capistrano/fast_deploy/integration.rb +115 -0
- data/lib/capistrano/fast_deploy/version.rb +5 -0
- data/lib/capistrano/fast_deploy.rb +2 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Aaron Jensen
|
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,71 @@
|
|
1
|
+
# Capistrano::FastDeploy
|
2
|
+
|
3
|
+
A couple Capistrano tweaks to speed up deploys:
|
4
|
+
|
5
|
+
* All changes occur in `current` folder, git clones directly to this
|
6
|
+
folder and uses `reset` to deploy.
|
7
|
+
* Symlinks in `deploy:finalize_update` all happen in one ssh connection
|
8
|
+
* Rollback uses git as well
|
9
|
+
|
10
|
+
This overrides the following default capistrano tasks:
|
11
|
+
|
12
|
+
* `deploy:update_cod` - Uses `git reset` instead of the standard
|
13
|
+
`:scm` and `:deploy_via`providers.
|
14
|
+
* `deploy:finalize_update` - Concatenates all symlink commands from
|
15
|
+
`shared_children into a single ssh command. Also adds support for
|
16
|
+
`mapped_shared_children` so you can add additional symlinks like this:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
set :mapped_shared_children, {
|
20
|
+
'config/database.yml' => 'config/database.yml'
|
21
|
+
}
|
22
|
+
```
|
23
|
+
* `deploy:create_symlink` - This is now a no-op, there are no longer
|
24
|
+
individual release directories.
|
25
|
+
* `deploy:rollback`, `deploy:rollback:repo`, `deploy:rollback:cleanup` -
|
26
|
+
Goes back to the previous place that `HEAD`
|
27
|
+
was pointing (`HEAD@{1}`). You don't want to do this if you go and
|
28
|
+
monkey around with your `current` folder manually.
|
29
|
+
* `deploy:create_symlink` - This is now a no-op, there are no longer
|
30
|
+
individual release directories.
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
gem 'capistrano-fast_deploy'
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle
|
41
|
+
|
42
|
+
Or install it yourself as:
|
43
|
+
|
44
|
+
$ gem install capistrano-fast_deploy
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
Add the following to your deploy.rb:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'capistrano/fast_deploy'
|
52
|
+
```
|
53
|
+
|
54
|
+
## Upgrading an existing project
|
55
|
+
|
56
|
+
It should just work automatically. `deploy:update_code` will "unsymlink"
|
57
|
+
your current directory. After that you can safely delete your releases
|
58
|
+
folder if you like.
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
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
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
* http://ariejan.net/2011/09/14/lighting-fast-zero-downtime-deployments-with-git-capistrano-nginx-and-unicorn
|
71
|
+
* https://github.com/blog/470-deployment-script-spring-cleaning
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/fast_deploy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capistrano-fast_deploy"
|
8
|
+
gem.version = Capistrano::FastDeploy::VERSION
|
9
|
+
gem.authors = ["Aaron Jensen"]
|
10
|
+
gem.email = ["aaronjensen@gmail.com"]
|
11
|
+
|
12
|
+
gem.summary = %q{Enable git style deploys in capistrano}
|
13
|
+
gem.description = %q{A couple Capistrano tweaks to speed up deploys using git style deploys and a few optimizations}
|
14
|
+
gem.homepage = ""
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_runtime_dependency "capistrano", "~>2.13"
|
22
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module FastDeploy
|
5
|
+
module Integration
|
6
|
+
def self.load_into(capistrano_config)
|
7
|
+
capistrano_config.load do
|
8
|
+
set(:latest_release) { fetch(:current_path) }
|
9
|
+
set(:release_path) { fetch(:current_path) }
|
10
|
+
set(:current_release) { fetch(:current_path) }
|
11
|
+
|
12
|
+
set(:releases_path) { fetch(:current_path) }
|
13
|
+
|
14
|
+
set(:current_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
|
15
|
+
set(:latest_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
|
16
|
+
set(:previous_revision) { capture("cd #{current_path}; git rev-parse --short HEAD@{1}").strip }
|
17
|
+
|
18
|
+
set :mapped_shared_children, { } unless defined?(mapped_shared_children)
|
19
|
+
|
20
|
+
namespace :deploy do
|
21
|
+
def git_reset(ref)
|
22
|
+
update_command = []
|
23
|
+
|
24
|
+
update_command << "cd #{deploy_to}"
|
25
|
+
# Fix up symlinked current folder
|
26
|
+
update_command << 'RELEASE=`readlink current`; if [ "$RELEASE" ]; then rm -rf current; mv "$RELEASE" "current"; fi'
|
27
|
+
# Git clone if it hasn't happened already
|
28
|
+
update_command << "if [ ! -d \"#{current_path}/.git\" ]; then git clone -q #{repository} #{current_path}; fi"
|
29
|
+
|
30
|
+
update_command << "cd #{current_path}"
|
31
|
+
# Fetch and reset
|
32
|
+
update_command << ["git fetch -q origin && git reset --hard #{ref}"]
|
33
|
+
# Write the revision file
|
34
|
+
update_command << "git rev-parse --verify HEAD > #{current_path}/REVISION"
|
35
|
+
run update_command.join(' && ')
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Update the deployed code."
|
39
|
+
task :update_code, :except => { :no_release => true } do
|
40
|
+
git_reset(branch)
|
41
|
+
|
42
|
+
on_rollback do
|
43
|
+
git_reset("HEAD@{1}")
|
44
|
+
finalize_update
|
45
|
+
rollback.cleanup
|
46
|
+
end
|
47
|
+
|
48
|
+
finalize_update
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "This is a no-op when fast_deploy is in use"
|
52
|
+
task :create_symlink do
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "This is a no-op when fast_deploy is in use"
|
56
|
+
task :cleanup do
|
57
|
+
end
|
58
|
+
|
59
|
+
task :finalize_update, :except => { :no_release => true } do
|
60
|
+
commands = []
|
61
|
+
commands << "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
|
62
|
+
|
63
|
+
# mkdir -p is making sure that the directories are there for some SCM's that don't
|
64
|
+
# save empty folders
|
65
|
+
shared_children.map do |d|
|
66
|
+
if (d.rindex('/')) then
|
67
|
+
commands << "rm -rf #{latest_release}/#{d} && mkdir -p #{latest_release}/#{d.slice(0..(d.rindex('/')))}"
|
68
|
+
else
|
69
|
+
commands << "rm -rf #{latest_release}/#{d}"
|
70
|
+
end
|
71
|
+
commands << "ln -s #{shared_path}/#{d.split('/').last} #{latest_release}/#{d}"
|
72
|
+
end
|
73
|
+
|
74
|
+
mapped_shared_children.map do |src, dest|
|
75
|
+
commands << "rm -rf #{latest_release}/#{dest}"
|
76
|
+
commands << "ln -s #{shared_path}/#{src} #{latest_release}/#{dest}"
|
77
|
+
end
|
78
|
+
|
79
|
+
run commands.join(" && ")
|
80
|
+
|
81
|
+
if fetch(:normalize_asset_timestamps, true)
|
82
|
+
stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
|
83
|
+
asset_paths = fetch(:public_children, %w(images stylesheets javascripts)).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
|
84
|
+
run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
namespace :rollback do
|
89
|
+
desc "Moves the repo back to the previous version of HEAD"
|
90
|
+
task :repo, :except => { :no_release => true } do
|
91
|
+
set :branch, "HEAD@{1}"
|
92
|
+
deploy.default
|
93
|
+
end
|
94
|
+
|
95
|
+
desc "Rewrite reflog so HEAD@{1} will continue to point to at the next previous release."
|
96
|
+
task :cleanup, :except => { :no_release => true } do
|
97
|
+
run "cd #{current_path}; git reflog delete --rewrite HEAD@{1}; git reflog delete --rewrite HEAD@{1}"
|
98
|
+
end
|
99
|
+
|
100
|
+
desc "Rolls back to the previously deployed version."
|
101
|
+
task :default do
|
102
|
+
rollback.repo
|
103
|
+
rollback.cleanup
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
if Capistrano::Configuration.instance
|
114
|
+
Capistrano::FastDeploy::Integration.load_into(Capistrano::Configuration.instance)
|
115
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-fast_deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aaron Jensen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.13'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.13'
|
30
|
+
description: A couple Capistrano tweaks to speed up deploys using git style deploys
|
31
|
+
and a few optimizations
|
32
|
+
email:
|
33
|
+
- aaronjensen@gmail.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- capistrano-fast_deploy.gemspec
|
44
|
+
- lib/capistrano/fast_deploy.rb
|
45
|
+
- lib/capistrano/fast_deploy/integration.rb
|
46
|
+
- lib/capistrano/fast_deploy/version.rb
|
47
|
+
homepage: ''
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.24
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Enable git style deploys in capistrano
|
71
|
+
test_files: []
|