capistrano-redeploy 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 +107 -0
- data/Rakefile +1 -0
- data/capistrano-redeploy.gemspec +24 -0
- data/lib/capistrano-redeploy.rb +135 -0
- data/lib/capistrano-redeploy/version.rb +5 -0
- metadata +102 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Yamashita Yuu
|
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,107 @@
|
|
1
|
+
# capistrano-redeploy
|
2
|
+
|
3
|
+
A dangerous recipe that overwrites your running application.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capistrano-redeploy'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capistrano-redeploy
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
*THIS RECIPE MAY CORRUPT YOUR RUNNING APPLICATION. TAKE SPECIAL CARE FOR YOUR CONFIGURATION/OPERATION.*
|
22
|
+
|
23
|
+
The `capistrano-redeploy` will try to perform following actions.
|
24
|
+
|
25
|
+
1. Deploy application to temporary directory on remote servers
|
26
|
+
2. Copy sources from temporary directory to running application
|
27
|
+
|
28
|
+
To enable `capistrano-redeploy`, add require line in your `config/deploy.rb`.
|
29
|
+
|
30
|
+
# config/deploy.rb
|
31
|
+
require "capistrano-redeploy"
|
32
|
+
|
33
|
+
Then, you can overwrite running application. By default, files in `public` will be overwritten on redeployment.
|
34
|
+
|
35
|
+
% cap redeploy
|
36
|
+
|
37
|
+
There are some options to configure redeployment for your application.
|
38
|
+
|
39
|
+
* `:redeploy_path` - The directory to redeploy to. Use `:current_release` by default.
|
40
|
+
* `:redeploy_children` - The list of directories to redeploy. Use `["public"]` by default.
|
41
|
+
* `:redeploy_exclusions` - The exclude list for redeployment. Use `["assets", "system"]` by default.
|
42
|
+
* `:redeploy_variables` - Supplimental variables for redeployment. See [Examples](#examples) for usage.
|
43
|
+
* `:redeploy_use_assets` - Invoke `assets:precompile` after redeploy. Disabled by default.
|
44
|
+
|
45
|
+
## Examples
|
46
|
+
|
47
|
+
### Redeploy files from repository
|
48
|
+
|
49
|
+
Redeploy files in `public` (except `public/assets` and `public/system`) from external repository.
|
50
|
+
|
51
|
+
# config/deploy.rb
|
52
|
+
set :scm, :git
|
53
|
+
set :deploy_via, :copy
|
54
|
+
set :repository, "git://example.com/example.git"
|
55
|
+
set :redeploy_children, ["public"]
|
56
|
+
set :redeploy_exclusions, ["assets", "system"]
|
57
|
+
|
58
|
+
### Redeploy files from local path
|
59
|
+
|
60
|
+
Redeploy files in `public` (except `public/assets` and `public/system`) from current directory.
|
61
|
+
|
62
|
+
# config/deploy.rb
|
63
|
+
set :scm, :git
|
64
|
+
set :deploy_via, :copy
|
65
|
+
set :repository, "git://example.com/example.git"
|
66
|
+
set :redeploy_variables, {
|
67
|
+
:scm => :none,
|
68
|
+
:deploy_via => :copy,
|
69
|
+
:repository => ".", # redeploy from current directory
|
70
|
+
}
|
71
|
+
set :redeploy_children, ["public"]
|
72
|
+
set :redeploy_exclusions, ["assets", "system"]
|
73
|
+
|
74
|
+
### Redeploy files from local path with different names
|
75
|
+
|
76
|
+
Redeploy files in `src/main/resources` from current directory to `target/webapp/WEB-INF`.
|
77
|
+
|
78
|
+
# config/deploy.rb
|
79
|
+
set :scm, :git
|
80
|
+
set :deploy_via, :copy
|
81
|
+
set :repository, "git://example.com/example.git"
|
82
|
+
set :redeploy_variables, {
|
83
|
+
:scm => :none,
|
84
|
+
:deploy_via => :copy,
|
85
|
+
:repository => ".", # redeploy from current directory
|
86
|
+
}
|
87
|
+
set :redeploy_source, "src/main/resources"
|
88
|
+
set :redeploy_destination, "target/webapp/WEB-INF"
|
89
|
+
set :redeploy_children, ["."]
|
90
|
+
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
1. Fork it
|
95
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
96
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
97
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
98
|
+
5. Create new Pull Request
|
99
|
+
|
100
|
+
## Author
|
101
|
+
|
102
|
+
- YAMASHITA Yuu (https://github.com/yyuu)
|
103
|
+
- Geisha Tokyo Entertainment Inc. (http://www.geishatokyo.com/)
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
MIT
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano-redeploy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capistrano-redeploy"
|
8
|
+
spec.version = Capistrano::ReDeploy::VERSION
|
9
|
+
spec.authors = ["Yamashita Yuu"]
|
10
|
+
spec.email = ["yamashita@geishatokyo.com"]
|
11
|
+
spec.description = %q{A dangerous recipe that overwrites your running application.}
|
12
|
+
spec.summary = %q{A dangerous recipe that overwrites your running application.}
|
13
|
+
spec.homepage = "https://github.com/yyuu/capistrano-redeploy"
|
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 "capistrano"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require "capistrano-redeploy/version"
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module ReDeploy
|
5
|
+
def self.extended(configuration)
|
6
|
+
configuration.load {
|
7
|
+
namespace(:redeploy) {
|
8
|
+
desc("Redeploy current running application.")
|
9
|
+
task(:default, :except => { :no_release => true }) {
|
10
|
+
update
|
11
|
+
}
|
12
|
+
|
13
|
+
task(:update, :except => { :no_release => true }) {
|
14
|
+
transaction do
|
15
|
+
update_code
|
16
|
+
finalize_update
|
17
|
+
end
|
18
|
+
}
|
19
|
+
|
20
|
+
_cset(:redeploy_path) { current_release }
|
21
|
+
task(:update_code, :except => { :no_release => true }) {
|
22
|
+
begin
|
23
|
+
tmpdir = capture("mktemp -d /tmp/redeploy.XXXXXXXXXX").strip
|
24
|
+
run("rm -rf #{tmpdir.dump} && mkdir -p #{tmpdir}")
|
25
|
+
deploy!(tmpdir)
|
26
|
+
redeploy!(tmpdir, redeploy_path)
|
27
|
+
ensure
|
28
|
+
run("rm -rf #{tmpdir.dump}")
|
29
|
+
end
|
30
|
+
}
|
31
|
+
on(:load) {
|
32
|
+
if fetch(:redeploy_use_assets, false)
|
33
|
+
before "redeploy:finalize_update", "deploy:assets:symlink"
|
34
|
+
after "redeploy:update_code", "deploy:assets:precompile"
|
35
|
+
before "redeploy:assets:precompile", "deploy:assets:update_asset_mtimes"
|
36
|
+
end
|
37
|
+
}
|
38
|
+
|
39
|
+
# Return a copy of given object
|
40
|
+
# Unlike Object#dup, this also duplicates instance variables.
|
41
|
+
def _middle_copy(object)
|
42
|
+
o = object.clone
|
43
|
+
object.instance_variables.each do |k|
|
44
|
+
v = object.instance_variable_get(k)
|
45
|
+
o.instance_variable_set(k, v ? v.clone : v)
|
46
|
+
end
|
47
|
+
o
|
48
|
+
end
|
49
|
+
|
50
|
+
_cset(:redeploy_variables, {})
|
51
|
+
def deploy!(destination, options={})
|
52
|
+
begin
|
53
|
+
releases_path = capture("mktemp -d /tmp/releases.XXXXXXXXXX", options).strip
|
54
|
+
release_path = File.join(releases_path, release_name)
|
55
|
+
run("rm -rf #{releases_path.dump} && mkdir -p #{releases_path.dump}", options)
|
56
|
+
c = _middle_copy(top)
|
57
|
+
c.instance_eval do
|
58
|
+
set(:deploy_to, File.dirname(releases_path))
|
59
|
+
set(:releases_path, releases_path)
|
60
|
+
set(:release_path, release_path)
|
61
|
+
set(:revision) { source.head }
|
62
|
+
set(:source) { ::Capistrano::Deploy::SCM.new(scm, self) }
|
63
|
+
set(:real_revision) { source.local.query_revision(revision) { |cmd| with_env("LC_ALL", "C") { run_locally(cmd) } } }
|
64
|
+
set(:strategy) { ::Capistrano::Deploy::Strategy.new(deploy_via, self) }
|
65
|
+
# merge variables
|
66
|
+
redeploy_variables.each do |key, val|
|
67
|
+
set(key, val)
|
68
|
+
end
|
69
|
+
strategy.deploy!
|
70
|
+
end
|
71
|
+
run("rsync -lrpt #{(release_path + "/").dump} #{destination.dump}", options)
|
72
|
+
ensure
|
73
|
+
run("rm -rf #{releases_path.dump}", options)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
_cset(:redeploy_children, %w(public))
|
78
|
+
_cset(:redeploy_exclusions, %w(assets system))
|
79
|
+
_cset(:redeploy_path_map) {
|
80
|
+
s = fetch(:redeploy_source, ".").to_s
|
81
|
+
d = fetch(:redeploy_destination, ".").to_s
|
82
|
+
Hash[redeploy_children.map { |c| [File.join(s, c), File.join(d, c)] }]
|
83
|
+
}
|
84
|
+
def absolute_path_map(source, destination)
|
85
|
+
map = redeploy_path_map.map { |s_subdir, d_subdir|
|
86
|
+
[ File.expand_path(File.join(source, s_subdir)), File.expand_path(File.join(destination, d_subdir)) ]
|
87
|
+
}
|
88
|
+
Hash[map]
|
89
|
+
end
|
90
|
+
|
91
|
+
def redeploy!(source, destination, options={})
|
92
|
+
exclusions = redeploy_exclusions.map { |e| "--exclude=#{e.dump}" }.join(" ")
|
93
|
+
absolute_path_map(source, destination).each do |s, d|
|
94
|
+
logger.info("redeploy: #{s} -> #{d}")
|
95
|
+
run("mkdir -p #{s.dump} #{d.dump}", options)
|
96
|
+
run("rsync -lrpt #{exclusions} #{(s + "/").dump} #{d.dump}", options)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
task(:finalize_update, :except => { :no_release => true }) {
|
101
|
+
escaped_release = redeploy_path.to_s.shellescape
|
102
|
+
commands = []
|
103
|
+
commands << "chmod -R -- g+w #{escaped_release}" if fetch(:group_writable, true)
|
104
|
+
|
105
|
+
# mkdir -p is making sure that the directories are there for some SCM's that don't
|
106
|
+
# save empty folders
|
107
|
+
shared_children.map do |dir|
|
108
|
+
d = dir.shellescape
|
109
|
+
if (dir.rindex('/')) then
|
110
|
+
commands += ["rm -rf -- #{escaped_release}/#{d}",
|
111
|
+
"mkdir -p -- #{escaped_release}/#{dir.slice(0..(dir.rindex('/'))).shellescape}"]
|
112
|
+
else
|
113
|
+
commands << "rm -rf -- #{escaped_release}/#{d}"
|
114
|
+
end
|
115
|
+
commands << "ln -s -- #{shared_path}/#{dir.split('/').last.shellescape} #{escaped_release}/#{d}"
|
116
|
+
end
|
117
|
+
|
118
|
+
run commands.join(' && ') if commands.any?
|
119
|
+
|
120
|
+
if fetch(:normalize_asset_timestamps, true)
|
121
|
+
stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
|
122
|
+
asset_paths = fetch(:public_children, %w(images stylesheets javascripts)).map { |p| "#{escaped_release}/public/#{p}" }
|
123
|
+
run("find #{asset_paths.join(" ")} -exec touch -t #{stamp} -- {} ';'; true",
|
124
|
+
:env => { "TZ" => "UTC" }) if asset_paths.any?
|
125
|
+
end
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
if Capistrano::Configuration.instance
|
134
|
+
Capistrano::Configuration.instance.extend(Capistrano::ReDeploy)
|
135
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-redeploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yamashita Yuu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-29 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: '0'
|
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: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: A dangerous recipe that overwrites your running application.
|
63
|
+
email:
|
64
|
+
- yamashita@geishatokyo.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- capistrano-redeploy.gemspec
|
75
|
+
- lib/capistrano-redeploy.rb
|
76
|
+
- lib/capistrano-redeploy/version.rb
|
77
|
+
homepage: https://github.com/yyuu/capistrano-redeploy
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.23
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: A dangerous recipe that overwrites your running application.
|
102
|
+
test_files: []
|