capistrano_rsync_with_remote_cache 2.3 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +32 -0
- data/Rakefile +85 -0
- data/VERSION.yml +4 -0
- data/test/capistrano_rsync_with_remote_cache_test.rb +159 -0
- data/test/test_helper.rb +11 -0
- metadata +22 -13
- data/README +0 -36
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007, 2008 Mark Cornick of Viget Labs (http://www.viget.com/)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Capistrano rsync_with_remote_cache
|
2
|
+
|
3
|
+
This gem provides a deployment strategy for Capistrano which combines rsync with a remote cache, allowing fast deployments from Subversion repositories behind firewalls.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
This gem requires Capistrano 2.0.0 and higher. Git support requires Capistrano 2.1.0 or higher.
|
8
|
+
|
9
|
+
This gem has only been tested with Subversion and Git. It is unlikely to be supported for other SCM systems unless we adopt them at Viget Labs, or get outside help.
|
10
|
+
|
11
|
+
This gem requires and `rsync` command line utilities on the local and remote hosts. It also requires either `svn` or `git` on the local host, but not the remote host.
|
12
|
+
|
13
|
+
This gem is tested on Mac OS X and Linux. Windows is not tested or supported.
|
14
|
+
|
15
|
+
## Using the strategy
|
16
|
+
|
17
|
+
To use this deployment strategy, add this line to your `deploy.rb` file:
|
18
|
+
|
19
|
+
set :deploy_via, :rsync_with_remote_cache
|
20
|
+
|
21
|
+
## How it works
|
22
|
+
|
23
|
+
This strategy maintains two cache directories:
|
24
|
+
|
25
|
+
* The local cache directory is a checkout from the SCM repository. The local cache directory is specified with the `local_cache` variable in the configuration. If not specified, it will default to `.rsync_cache` in the same directory as the Capfile.
|
26
|
+
* The remote cache directory is an rsync copy of the local cache directory. The remote cache directory is specified with the `repository_cache` variable in the configuration (this name comes from the `remote_cache` strategy that ships with Capistrano, and has been maintained for compatibility.) If not specified, it will default to `shared/cached-copy` (again, for compatibility with remote_cache.)
|
27
|
+
|
28
|
+
Deployment happens in three major steps. First, the local cache directory is processed. If it does not exist, it is created with a checkout of the revision to be deployed. If it exists, it is updated to the revision to be deployed.
|
29
|
+
|
30
|
+
Second, rsync runs on the local side to sync the remote cache to the local cache. When the rsync is complete, the remote cache should be an exact replica of the local cache.
|
31
|
+
|
32
|
+
Finally, a copy of the remote cache is made in the appropriate release directory. The end result is the same as if the code had been checked out directly on the remote server, as in the default strategy.
|
data/Rakefile
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "capistrano_rsync_with_remote_cache"
|
8
|
+
gem.summary = "rsync_with_remote_cache strategy for Capistrano"
|
9
|
+
gem.description = 'A deployment strategy for Capistrano 2.0 which combines rsync with a remote cache, allowing fast deployments from SCM servers behind firewalls.'
|
10
|
+
gem.email = "mark@viget.com"
|
11
|
+
gem.homepage = "http://github.com/vigetlabs/capistrano_rsync_with_remote_cache"
|
12
|
+
gem.authors = ["Mark Cornick"]
|
13
|
+
gem.rubyforge_project = "viget"
|
14
|
+
gem.add_dependency 'capistrano', '>= 2.0'
|
15
|
+
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/*_test.rb'
|
26
|
+
test.verbose = false
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/*_test.rb'
|
34
|
+
test.verbose = true
|
35
|
+
test.rcov_opts << '-x gems'
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
if File.exist?('VERSION.yml')
|
49
|
+
config = YAML.load(File.read('VERSION.yml'))
|
50
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
51
|
+
else
|
52
|
+
version = ""
|
53
|
+
end
|
54
|
+
|
55
|
+
rdoc.rdoc_dir = 'rdoc'
|
56
|
+
rdoc.title = "capistrano_rsync_with_remote_cache #{version}"
|
57
|
+
rdoc.rdoc_files.include('README*')
|
58
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
|
+
end
|
60
|
+
|
61
|
+
begin
|
62
|
+
require 'rake/contrib/sshpublisher'
|
63
|
+
namespace :rubyforge do
|
64
|
+
|
65
|
+
desc "Release gem and RDoc documentation to RubyForge"
|
66
|
+
task :release => ["rubyforge:release:gem"]
|
67
|
+
|
68
|
+
namespace :release do
|
69
|
+
desc "Publish RDoc to RubyForge."
|
70
|
+
task :docs => [:rdoc] do
|
71
|
+
config = YAML.load(
|
72
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
73
|
+
)
|
74
|
+
|
75
|
+
host = "#{config['username']}@rubyforge.org"
|
76
|
+
remote_dir = "/var/www/gforge-projects/capistrano_rsync_with_remote_cache/"
|
77
|
+
local_dir = 'rdoc'
|
78
|
+
|
79
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
rescue LoadError
|
84
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
85
|
+
end
|
data/VERSION.yml
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
# This test suite was written way after the code, back when the author didn't do TDD consistently.
|
2
|
+
# Also, the code does a lot of things with external servers and services, so there's a lot of mocking.
|
3
|
+
# Therefore, this suite is nearly impossible to follow in places. Sorry.
|
4
|
+
|
5
|
+
require 'test_helper'
|
6
|
+
|
7
|
+
class CapistranoRsyncWithRemoteCacheTest < Test::Unit::TestCase
|
8
|
+
def stub_configuration(hash)
|
9
|
+
@rwrc.expects(:configuration).at_least_once.returns(hash)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'RsyncWithRemoteCache' do
|
13
|
+
setup do
|
14
|
+
@rwrc = Capistrano::Deploy::Strategy::RsyncWithRemoteCache.new
|
15
|
+
|
16
|
+
logger_stub = stub()
|
17
|
+
logger_stub.stubs(:trace)
|
18
|
+
@rwrc.stubs(:logger).returns(logger_stub)
|
19
|
+
|
20
|
+
# FIXME: this is lame
|
21
|
+
class << @rwrc
|
22
|
+
def `(cmd)
|
23
|
+
'\n'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'deploy!' do
|
29
|
+
stub_configuration(:deploy_to => 'deploy_to', :release_path => 'release_path', :scm => :subversion)
|
30
|
+
@rwrc.stubs(:shared_path).returns('shared')
|
31
|
+
|
32
|
+
# Step 1: Update the local cache.
|
33
|
+
@rwrc.expects(:command).returns('command')
|
34
|
+
@rwrc.expects(:system).with('command')
|
35
|
+
revision_file_stub = stub()
|
36
|
+
revision_file_stub.expects(:puts)
|
37
|
+
File.expects(:open).with(File.join('.rsync_cache', 'REVISION'), 'w').yields(revision_file_stub)
|
38
|
+
|
39
|
+
# Step 2: Update the remote cache.
|
40
|
+
server_stub = stub(:host => 'host')
|
41
|
+
@rwrc.expects(:system).with("rsync -az --delete .rsync_cache/ host:shared/cached-copy/")
|
42
|
+
@rwrc.expects(:find_servers).returns([server_stub])
|
43
|
+
|
44
|
+
# Step 3: Copy the remote cache into place.
|
45
|
+
@rwrc.expects(:mark).returns('mark')
|
46
|
+
@rwrc.expects(:run).with("rsync -a --delete shared/cached-copy/ release_path/ && mark")
|
47
|
+
|
48
|
+
@rwrc.deploy!
|
49
|
+
end
|
50
|
+
|
51
|
+
should 'check!' do
|
52
|
+
configuration = {:releases_path => 'releases_path', :deploy_to => 'deploy_to'}
|
53
|
+
configuration.stubs(:invoke_command)
|
54
|
+
@rwrc.expects(:configuration).at_least_once.returns(configuration)
|
55
|
+
|
56
|
+
source_stub = stub(:command => 'command')
|
57
|
+
@rwrc.stubs(:source).returns(source_stub)
|
58
|
+
|
59
|
+
@rwrc.check!
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'repository_cache' do
|
63
|
+
setup do
|
64
|
+
@rwrc.expects(:shared_path).returns('shared')
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'return specified cache if present in configuration' do
|
68
|
+
stub_configuration(:repository_cache => 'cache')
|
69
|
+
assert_equal 'shared/cache', @rwrc.send(:repository_cache)
|
70
|
+
end
|
71
|
+
|
72
|
+
should 'return default cache if not present in configuration' do
|
73
|
+
stub_configuration(:repository_cache => nil)
|
74
|
+
assert_equal 'shared/cached-copy', @rwrc.send(:repository_cache)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'local_cache' do
|
79
|
+
should 'return specified cache if present in configuration' do
|
80
|
+
stub_configuration(:local_cache => 'cache')
|
81
|
+
assert_equal 'cache', @rwrc.send(:local_cache)
|
82
|
+
end
|
83
|
+
|
84
|
+
should 'return default cache if not present in configuration' do
|
85
|
+
stub_configuration(:local_cache => nil)
|
86
|
+
assert_equal '.rsync_cache', @rwrc.send(:local_cache)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'rsync_options' do
|
91
|
+
should 'return specified options if present in configuration' do
|
92
|
+
stub_configuration(:rsync_options => 'options')
|
93
|
+
assert_equal 'options', @rwrc.send(:rsync_options)
|
94
|
+
end
|
95
|
+
|
96
|
+
should 'return default options if not present in configuration' do
|
97
|
+
stub_configuration(:rsync_options => nil)
|
98
|
+
assert_equal '-az --delete', @rwrc.send(:rsync_options)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'rsync_host' do
|
103
|
+
setup do
|
104
|
+
@server_stub = stub(:host => 'host')
|
105
|
+
end
|
106
|
+
|
107
|
+
should 'prefix user if present in configuration' do
|
108
|
+
stub_configuration(:user => 'user')
|
109
|
+
assert_equal 'user@host', @rwrc.send(:rsync_host, @server_stub)
|
110
|
+
end
|
111
|
+
|
112
|
+
should 'not prefix user if not present in configuration' do
|
113
|
+
stub_configuration(:user => nil)
|
114
|
+
assert_equal 'host', @rwrc.send(:rsync_host, @server_stub)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'command' do
|
119
|
+
should 'remove local cache dir if it detects subversion info has changed' do
|
120
|
+
stub_configuration(:scm => :subversion)
|
121
|
+
|
122
|
+
@rwrc.expects(:`).returns('something else')
|
123
|
+
@rwrc.expects(:system).with("rm -rf .rsync_cache")
|
124
|
+
|
125
|
+
File.expects(:exists?).with('.rsync_cache').times(2).returns(false)
|
126
|
+
File.expects(:directory?).with(File.dirname('.rsync_cache')).returns(false)
|
127
|
+
Dir.expects(:mkdir).with(File.dirname('.rsync_cache'))
|
128
|
+
|
129
|
+
source_stub = stub()
|
130
|
+
source_stub.expects(:checkout)
|
131
|
+
@rwrc.expects(:source).returns(source_stub)
|
132
|
+
|
133
|
+
@rwrc.send(:command)
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
should 'update local cache if it exists' do
|
138
|
+
File.expects(:exists?).with('.rsync_cache').returns(true)
|
139
|
+
File.expects(:directory?).with('.rsync_cache').returns(true)
|
140
|
+
source_stub = stub()
|
141
|
+
source_stub.expects(:sync)
|
142
|
+
@rwrc.expects(:source).returns(source_stub)
|
143
|
+
|
144
|
+
@rwrc.send(:command)
|
145
|
+
end
|
146
|
+
|
147
|
+
should 'update local cache if it does not exist' do
|
148
|
+
File.expects(:exists?).with('.rsync_cache').times(2).returns(false)
|
149
|
+
File.expects(:directory?).with(File.dirname('.rsync_cache')).returns(false)
|
150
|
+
Dir.expects(:mkdir).with(File.dirname('.rsync_cache'))
|
151
|
+
source_stub = stub()
|
152
|
+
source_stub.expects(:checkout)
|
153
|
+
@rwrc.expects(:source).returns(source_stub)
|
154
|
+
|
155
|
+
@rwrc.send(:command)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
require 'capistrano/recipes/deploy/strategy/rsync_with_remote_cache'
|
9
|
+
|
10
|
+
class Test::Unit::TestCase
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano_rsync_with_remote_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Cornick
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-05-14 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,22 +22,30 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "2.0"
|
24
24
|
version:
|
25
|
-
description:
|
25
|
+
description: A deployment strategy for Capistrano 2.0 which combines rsync with a remote cache, allowing fast deployments from SCM servers behind firewalls.
|
26
26
|
email: mark@viget.com
|
27
27
|
executables: []
|
28
28
|
|
29
29
|
extensions: []
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
32
|
-
-
|
32
|
+
- LICENSE
|
33
|
+
- README.md
|
33
34
|
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- VERSION.yml
|
34
39
|
- lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb
|
35
|
-
-
|
40
|
+
- test/capistrano_rsync_with_remote_cache_test.rb
|
41
|
+
- test/test_helper.rb
|
36
42
|
has_rdoc: true
|
37
43
|
homepage: http://github.com/vigetlabs/capistrano_rsync_with_remote_cache
|
38
|
-
|
39
|
-
rdoc_options: []
|
44
|
+
licenses: []
|
40
45
|
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
41
49
|
require_paths:
|
42
50
|
- lib
|
43
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -54,10 +62,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
62
|
version:
|
55
63
|
requirements: []
|
56
64
|
|
57
|
-
rubyforge_project:
|
58
|
-
rubygems_version: 1.3.
|
65
|
+
rubyforge_project: viget
|
66
|
+
rubygems_version: 1.3.2
|
59
67
|
signing_key:
|
60
|
-
specification_version:
|
61
|
-
summary:
|
62
|
-
test_files:
|
63
|
-
|
68
|
+
specification_version: 3
|
69
|
+
summary: rsync_with_remote_cache strategy for Capistrano
|
70
|
+
test_files:
|
71
|
+
- test/capistrano_rsync_with_remote_cache_test.rb
|
72
|
+
- test/test_helper.rb
|
data/README
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
= Capistrano rsync_with_remote_cache
|
2
|
-
|
3
|
-
This gem provides a deployment strategy for Capistrano which combines rsync with a remote cache, allowing fast deployments from Subversion repositories behind firewalls.
|
4
|
-
|
5
|
-
== Requirements
|
6
|
-
|
7
|
-
This gem requires Capistrano 2.0.0 and higher. Git support requires Capistrano 2.1.0 or higher.
|
8
|
-
|
9
|
-
This gem has only been tested with Subversion and Git. It is unlikely to be supported for other SCM systems unless we adopt them at Viget Labs, or get outside help.
|
10
|
-
|
11
|
-
This gem requires and <tt>rsync</tt> command line utilities on the local and remote hosts. It also requires either <tt>svn</tt> or <tt>git</tt> on the local host, but not the remote host.
|
12
|
-
|
13
|
-
This gem is tested primarily on Mac OS X and Linux. It may work with a Windows local host, but is not tested or supported. Like Capistrano itself, it will not work with a Windows remote host.
|
14
|
-
|
15
|
-
== Gem preliminaries
|
16
|
-
|
17
|
-
To create the gem, run <tt>gem build capistrano_rsync_with_remote_cache.gemspec</tt> in this directory.
|
18
|
-
|
19
|
-
To use this deployment strategy, add this line to your configuration:
|
20
|
-
|
21
|
-
<tt>set :deploy_via, :rsync_with_remote_cache</tt>
|
22
|
-
|
23
|
-
== How it works
|
24
|
-
|
25
|
-
This strategy maintains two cache directories:
|
26
|
-
|
27
|
-
* The local cache directory is a checkout from the SCM repository. The local cache directory is specified with the <tt>local_cache</tt> variable in the configuration. If not specified, it will default to ".rsync_cache" in the same directory as the Capfile.
|
28
|
-
* The remote cache directory is an rsync copy of the local cache directory. The remote cache directory is specified with the <tt>repository_cache</tt> variable in the configuration (this name comes from the remote_cache strategy that ships with Capistrano, and has been maintained for compatibility.) If not specified, it will default to "shared/cached-copy" (again, for compatibility with remote_cache.)
|
29
|
-
|
30
|
-
Deployment happens in three major steps. First, the local cache directory is processed. If it does not exist, it is created with a checkout of the revision to be deployed. If it exists, it is updated to the revision to be deployed.
|
31
|
-
|
32
|
-
Second, rsync runs on the local side to sync the remote cache to the local cache. When the rsync is complete, the remote cache should be an exact replica of the local cache.
|
33
|
-
|
34
|
-
Finally, a copy of the remote cache is made in the appropriate release directory. The end result is the same as if the code had been checked out directly on the remote server, as in the default strategy.
|
35
|
-
|
36
|
-
Copyright (c) 2007, 2008 Mark Cornick of Viget Labs, released under the MIT license
|