mattscilipoti-capistrano_rsync_with_remote_cache 2.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.md +36 -0
- data/Rakefile +86 -0
- data/VERSION +1 -0
- data/capistrano_rsync_with_remote_cache.gemspec +61 -0
- data/lib/capistrano/recipes/deploy/strategy/exceptions.reek +15 -0
- data/lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb +118 -0
- data/test/capistrano_rsync_with_remote_cache_test.rb +174 -0
- data/test/test_helper.rb +11 -0
- metadata +96 -0
data/.document
ADDED
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,36 @@
|
|
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 or higher. Git support requires Capistrano 2.1.0 or higher.
|
8
|
+
|
9
|
+
This gem supports Subversion, Git, Mercurial and Bazaar. Only Subversion and Git have been extensively tested. This gem is unlikely to be supported for other SCM systems.
|
10
|
+
|
11
|
+
This gem requires `rsync` command line utilities on the local and remote hosts. It also requires either `svn`, `git`, `hg` or `bzr` 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. There are three possibilities:
|
29
|
+
|
30
|
+
* If the local cache does not exist, it is created with a checkout of the revision to be deployed.
|
31
|
+
* If the local cache exists and matches the `:repository` variable, it is updated to the revision to be deployed.
|
32
|
+
* If the local cache exists and does not match the `:repository` variable, the local cache is purged and recreated with a checkout of the revision to be deployed.
|
33
|
+
|
34
|
+
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.
|
35
|
+
|
36
|
+
Finally, a copy of the remote cache (excluding scm directories) 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. Refer to rsync --cvs_ignore to customize excluded dirs/files.
|
data/Rakefile
ADDED
@@ -0,0 +1,86 @@
|
|
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
|
+
gem.add_development_dependency "thoughtbot-shoulda"
|
16
|
+
gem.add_development_dependency "yard"
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
21
|
+
rubyforge.doc_task = "yardoc"
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/*_test.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '-x gems'
|
41
|
+
end
|
42
|
+
rescue LoadError
|
43
|
+
task :rcov do
|
44
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install relevance-rcov"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
task :test => :check_dependencies
|
49
|
+
|
50
|
+
begin
|
51
|
+
require 'reek/rake_task'
|
52
|
+
Reek::RakeTask.new do |t|
|
53
|
+
t.fail_on_error = true
|
54
|
+
t.verbose = false
|
55
|
+
t.source_files = 'lib/**/*.rb'
|
56
|
+
end
|
57
|
+
rescue LoadError
|
58
|
+
task :reek do
|
59
|
+
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
begin
|
64
|
+
require 'roodi'
|
65
|
+
require 'roodi_task'
|
66
|
+
RoodiTask.new do |t|
|
67
|
+
t.verbose = false
|
68
|
+
end
|
69
|
+
rescue LoadError
|
70
|
+
task :roodi do
|
71
|
+
abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
task :default => :test
|
76
|
+
|
77
|
+
begin
|
78
|
+
require 'yard'
|
79
|
+
YARD::Rake::YardocTask.new do |t|
|
80
|
+
t.options = ['--private']
|
81
|
+
end
|
82
|
+
rescue LoadError
|
83
|
+
task :yardoc do
|
84
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
85
|
+
end
|
86
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.6
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mattscilipoti-capistrano_rsync_with_remote_cache}
|
8
|
+
s.version = "2.3.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mark Cornick"]
|
12
|
+
s.date = %q{2009-11-13}
|
13
|
+
s.description = %q{A deployment strategy for Capistrano 2.0 which combines rsync with a remote cache, allowing fast deployments from SCM servers behind firewalls.}
|
14
|
+
s.email = %q{mark@viget.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"capistrano_rsync_with_remote_cache.gemspec",
|
27
|
+
"lib/capistrano/recipes/deploy/strategy/exceptions.reek",
|
28
|
+
"lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb",
|
29
|
+
"test/capistrano_rsync_with_remote_cache_test.rb",
|
30
|
+
"test/test_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/vigetlabs/capistrano_rsync_with_remote_cache}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubyforge_project = %q{viget}
|
36
|
+
s.rubygems_version = %q{1.3.5}
|
37
|
+
s.summary = %q{rsync_with_remote_cache strategy for Capistrano}
|
38
|
+
s.test_files = [
|
39
|
+
"test/test_helper.rb",
|
40
|
+
"test/capistrano_rsync_with_remote_cache_test.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<capistrano>, [">= 2.0"])
|
49
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<capistrano>, [">= 2.0"])
|
53
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<capistrano>, [">= 2.0"])
|
58
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
59
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/strategy/remote'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Capistrano
|
5
|
+
module Deploy
|
6
|
+
module Strategy
|
7
|
+
class RsyncWithRemoteCache < Remote
|
8
|
+
|
9
|
+
INFO_COMMANDS = {
|
10
|
+
:subversion => "svn info . | sed -n \'s/URL: //p\'",
|
11
|
+
:git => "git config remote.origin.url",
|
12
|
+
:mercurial => "hg showconfig paths.default",
|
13
|
+
:bzr => "bzr info | grep parent | sed \'s/^.*parent branch: //\'"
|
14
|
+
}
|
15
|
+
|
16
|
+
# The deployment method itself, in three major steps: update the local cache, update the remote
|
17
|
+
# cache, and copy the remote cache into place.
|
18
|
+
def deploy!
|
19
|
+
|
20
|
+
# Step 1: Update the local cache.
|
21
|
+
system(command)
|
22
|
+
File.open(File.join(local_cache, "REVISION"), "w") { |file| file.puts(revision) }
|
23
|
+
|
24
|
+
# Step 2: Update the remote cache.
|
25
|
+
logger.trace "copying local cache to remote"
|
26
|
+
find_servers(:except => { :no_release => true }).each do |server|
|
27
|
+
system("rsync #{rsync_options} --rsh='ssh -p #{ssh_port}' #{local_cache}/ #{rsync_host(server)}:#{repository_cache}/")
|
28
|
+
end
|
29
|
+
|
30
|
+
# Step 3: Copy the remote cache into place, excluding scm directories (for svn, git, cvs, bzr and more).
|
31
|
+
run("rsync -a --cvs-exclude --delete #{repository_cache}/ #{configuration[:release_path]}/ && #{mark}")
|
32
|
+
end
|
33
|
+
|
34
|
+
# Defines commands that should be checked for by deploy:check. These include the SCM command
|
35
|
+
# on the local end, and rsync on both ends. Note that the SCM command is not needed on the
|
36
|
+
# remote end.
|
37
|
+
def check!
|
38
|
+
super.check do |check|
|
39
|
+
check.local.command(source.command)
|
40
|
+
check.local.command('rsync')
|
41
|
+
check.remote.command('rsync')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# Path to the remote cache. We use a variable name and default that are compatible with
|
48
|
+
# the stock remote_cache strategy, for easy migration.
|
49
|
+
# @return [String] the path to the remote cache
|
50
|
+
def repository_cache
|
51
|
+
File.join(shared_path, configuration[:repository_cache] || "cached-copy")
|
52
|
+
end
|
53
|
+
|
54
|
+
# Path to the local cache. If not specified in the Capfile, we use an arbitrary default.
|
55
|
+
# @return [String] the path to the local cache
|
56
|
+
def local_cache
|
57
|
+
configuration[:local_cache] || ".rsync_cache"
|
58
|
+
end
|
59
|
+
|
60
|
+
# Options to use for rsync in step 2. If not specified in the Capfile, we use the default
|
61
|
+
# from prior versions.
|
62
|
+
# @return [String] the options to be passed to rsync
|
63
|
+
def rsync_options
|
64
|
+
configuration[:rsync_options] || "-az --delete"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Port to use for rsync in step 2. If not specified with (ssh_options) in the Capfile, we
|
68
|
+
# use the default well-known port 22.
|
69
|
+
# @return [Fixnum] the port to connect to with rsync
|
70
|
+
def ssh_port
|
71
|
+
ssh_options[:port] || 22
|
72
|
+
end
|
73
|
+
|
74
|
+
# Get a hostname to be used in the rsync command.
|
75
|
+
# @param [Capistrano::ServerDefinition, #host] the host which rsync will connect to
|
76
|
+
# @return [String] the hostname, prefixed with user@ if necessary
|
77
|
+
def rsync_host(server)
|
78
|
+
if configuration[:user]
|
79
|
+
"#{configuration[:user]}@#{server.host}"
|
80
|
+
else
|
81
|
+
server.host
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Remove the local cache (so it can be recreated) if the repository URL has changed
|
86
|
+
# since the last deployment.
|
87
|
+
# TODO: punt in some sensible way if local_cache exists but is a regular file.
|
88
|
+
def remove_cache_if_repo_changed
|
89
|
+
if INFO_COMMANDS[configuration[:scm]] && File.directory?(local_cache)
|
90
|
+
info_command = "cd #{local_cache} && #{INFO_COMMANDS[configuration[:scm]]}"
|
91
|
+
cached_repo_url = IO.popen(info_command){|pipe| pipe.readline}.chomp
|
92
|
+
if cached_repo_url != configuration[:repository]
|
93
|
+
logger.trace "repository has changed; removing old local cache"
|
94
|
+
FileUtils.rm_rf(local_cache)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Command to get source from SCM on the local side. The local cache is either created,
|
100
|
+
# updated, or destroyed and recreated depending on whether it exists and is a cache of
|
101
|
+
# the right repository.
|
102
|
+
# @return [String] command to either checkout or update the local cache
|
103
|
+
def command
|
104
|
+
remove_cache_if_repo_changed
|
105
|
+
if File.exists?(local_cache) && File.directory?(local_cache)
|
106
|
+
logger.trace "updating local cache to revision #{revision}"
|
107
|
+
return source.sync(revision, local_cache)
|
108
|
+
else
|
109
|
+
logger.trace "creating local cache with revision #{revision}"
|
110
|
+
File.delete(local_cache) if File.exists?(local_cache)
|
111
|
+
Dir.mkdir(File.dirname(local_cache)) unless File.directory?(File.dirname(local_cache))
|
112
|
+
return source.checkout(revision, local_cache)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,174 @@
|
|
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
|
+
def stub_ssh_options(hash)
|
13
|
+
@rwrc.expects(:ssh_options).at_least_once.returns(hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'RsyncWithRemoteCache' do
|
17
|
+
setup do
|
18
|
+
@rwrc = Capistrano::Deploy::Strategy::RsyncWithRemoteCache.new
|
19
|
+
logger_stub = stub()
|
20
|
+
logger_stub.stubs(:trace)
|
21
|
+
@rwrc.stubs(:logger).returns(logger_stub)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'deploy!' do
|
25
|
+
stub_configuration(:deploy_to => 'deploy_to', :release_path => 'release_path', :scm => :subversion)
|
26
|
+
stub_ssh_options(:port => nil)
|
27
|
+
@rwrc.stubs(:shared_path).returns('shared')
|
28
|
+
|
29
|
+
# Step 1: Update the local cache.
|
30
|
+
@rwrc.expects(:command).returns('command')
|
31
|
+
@rwrc.expects(:system).with('command')
|
32
|
+
revision_file_stub = stub()
|
33
|
+
revision_file_stub.expects(:puts)
|
34
|
+
File.expects(:open).with(File.join('.rsync_cache', 'REVISION'), 'w').yields(revision_file_stub)
|
35
|
+
|
36
|
+
# Step 2: Update the remote cache.
|
37
|
+
server_stub = stub(:host => 'host')
|
38
|
+
@rwrc.expects(:system).with("rsync -az --delete --rsh='ssh -p 22' .rsync_cache/ host:shared/cached-copy/")
|
39
|
+
@rwrc.expects(:find_servers).returns([server_stub])
|
40
|
+
|
41
|
+
# Step 3: Copy the remote cache into place.
|
42
|
+
@rwrc.expects(:mark).returns('mark')
|
43
|
+
@rwrc.expects(:run).with("rsync -a --cvs-exclude --delete shared/cached-copy/ release_path/ && mark")
|
44
|
+
|
45
|
+
@rwrc.deploy!
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'check!' do
|
49
|
+
configuration = {:releases_path => 'releases_path', :deploy_to => 'deploy_to'}
|
50
|
+
configuration.stubs(:invoke_command)
|
51
|
+
@rwrc.expects(:configuration).at_least_once.returns(configuration)
|
52
|
+
|
53
|
+
source_stub = stub(:command => 'command')
|
54
|
+
@rwrc.stubs(:source).returns(source_stub)
|
55
|
+
|
56
|
+
@rwrc.check!
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'repository_cache' do
|
60
|
+
setup do
|
61
|
+
@rwrc.expects(:shared_path).returns('shared')
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'return specified cache if present in configuration' do
|
65
|
+
stub_configuration(:repository_cache => 'cache')
|
66
|
+
assert_equal 'shared/cache', @rwrc.send(:repository_cache)
|
67
|
+
end
|
68
|
+
|
69
|
+
should 'return default cache if not present in configuration' do
|
70
|
+
stub_configuration(:repository_cache => nil)
|
71
|
+
assert_equal 'shared/cached-copy', @rwrc.send(:repository_cache)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'local_cache' do
|
76
|
+
should 'return specified cache if present in configuration' do
|
77
|
+
stub_configuration(:local_cache => 'cache')
|
78
|
+
assert_equal 'cache', @rwrc.send(:local_cache)
|
79
|
+
end
|
80
|
+
|
81
|
+
should 'return default cache if not present in configuration' do
|
82
|
+
stub_configuration(:local_cache => nil)
|
83
|
+
assert_equal '.rsync_cache', @rwrc.send(:local_cache)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'rsync_options' do
|
88
|
+
should 'return specified options if present in configuration' do
|
89
|
+
stub_configuration(:rsync_options => 'options')
|
90
|
+
assert_equal 'options', @rwrc.send(:rsync_options)
|
91
|
+
end
|
92
|
+
|
93
|
+
should 'return default options if not present in configuration' do
|
94
|
+
stub_configuration(:rsync_options => nil)
|
95
|
+
assert_equal '-az --delete', @rwrc.send(:rsync_options)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'ssh_port' do
|
100
|
+
should 'return specified port if present in configuration' do
|
101
|
+
stub_ssh_options(:port => 2222)
|
102
|
+
assert_equal 2222, @rwrc.send(:ssh_port)
|
103
|
+
end
|
104
|
+
|
105
|
+
should 'return default port if not present in configuration' do
|
106
|
+
stub_ssh_options(:port => nil)
|
107
|
+
assert_equal 22, @rwrc.send(:ssh_port)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'rsync_host' do
|
112
|
+
setup do
|
113
|
+
@server_stub = stub(:host => 'host')
|
114
|
+
end
|
115
|
+
|
116
|
+
should 'prefix user if present in configuration' do
|
117
|
+
stub_configuration(:user => 'user')
|
118
|
+
assert_equal 'user@host', @rwrc.send(:rsync_host, @server_stub)
|
119
|
+
end
|
120
|
+
|
121
|
+
should 'not prefix user if not present in configuration' do
|
122
|
+
stub_configuration(:user => nil)
|
123
|
+
assert_equal 'host', @rwrc.send(:rsync_host, @server_stub)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'remove_cache_if_repo_changed' do
|
128
|
+
[:subversion, :git, :mercurial, :bzr].each do |scm|
|
129
|
+
should "purge local cache if it detects #{scm} info has changed" do
|
130
|
+
stub_configuration(:scm => scm, :repository => 'repository')
|
131
|
+
info_command = Capistrano::Deploy::Strategy::RsyncWithRemoteCache::INFO_COMMANDS[scm]
|
132
|
+
File.expects(:directory?).with('.rsync_cache').returns(true)
|
133
|
+
IO.expects(:popen).with("cd .rsync_cache && #{info_command}").returns('abc')
|
134
|
+
FileUtils.expects(:rm_rf).with('.rsync_cache')
|
135
|
+
@rwrc.send(:remove_cache_if_repo_changed)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
should 'not attempt to purge local cache if it does not exist' do
|
140
|
+
stub_configuration(:scm => :subversion, :repository => 'repository')
|
141
|
+
File.expects(:directory?).with('.rsync_cache').returns(false)
|
142
|
+
FileUtils.expects(:rm_rf).with('.rsync_cache').never
|
143
|
+
@rwrc.send(:remove_cache_if_repo_changed)
|
144
|
+
end
|
145
|
+
|
146
|
+
should 'not attempt to purge local cache if the scm is not supported by this gem' do
|
147
|
+
stub_configuration(:scm => :cvs, :repository => 'repository')
|
148
|
+
FileUtils.expects(:rm_rf).with('.rsync_cache').never
|
149
|
+
@rwrc.send(:remove_cache_if_repo_changed)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'command' do
|
154
|
+
should 'update local cache if it exists' do
|
155
|
+
File.expects(:exists?).with('.rsync_cache').returns(true)
|
156
|
+
File.expects(:directory?).with('.rsync_cache').returns(true)
|
157
|
+
source_stub = stub()
|
158
|
+
source_stub.expects(:sync)
|
159
|
+
@rwrc.expects(:source).returns(source_stub)
|
160
|
+
@rwrc.send(:command)
|
161
|
+
end
|
162
|
+
|
163
|
+
should 'create local cache if it does not exist' do
|
164
|
+
File.expects(:exists?).with('.rsync_cache').times(2).returns(false)
|
165
|
+
File.expects(:directory?).with(File.dirname('.rsync_cache')).returns(false)
|
166
|
+
Dir.expects(:mkdir).with(File.dirname('.rsync_cache'))
|
167
|
+
source_stub = stub()
|
168
|
+
source_stub.expects(:checkout)
|
169
|
+
@rwrc.expects(:source).returns(source_stub)
|
170
|
+
@rwrc.send(:command)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
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
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mattscilipoti-capistrano_rsync_with_remote_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.3.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Cornick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-13 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: capistrano
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "2.0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: thoughtbot-shoulda
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: yard
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: A deployment strategy for Capistrano 2.0 which combines rsync with a remote cache, allowing fast deployments from SCM servers behind firewalls.
|
46
|
+
email: mark@viget.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- capistrano_rsync_with_remote_cache.gemspec
|
62
|
+
- lib/capistrano/recipes/deploy/strategy/exceptions.reek
|
63
|
+
- lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb
|
64
|
+
- test/capistrano_rsync_with_remote_cache_test.rb
|
65
|
+
- test/test_helper.rb
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://github.com/vigetlabs/capistrano_rsync_with_remote_cache
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- --charset=UTF-8
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project: viget
|
90
|
+
rubygems_version: 1.3.5
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: rsync_with_remote_cache strategy for Capistrano
|
94
|
+
test_files:
|
95
|
+
- test/test_helper.rb
|
96
|
+
- test/capistrano_rsync_with_remote_cache_test.rb
|