capistrano_rsync_with_remote_cache 2.3.7 → 2.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,90 @@
1
+ = Capistrano rsync_with_remote_cache Deployment Strategy
2
+
3
+ == Description
4
+
5
+ This gem provides a deployment strategy for Capistrano which combines the
6
+ <tt>rsync</tt> command with a remote cache, allowing fast deployments from SCM
7
+ repositories behind firewalls.
8
+
9
+ == Requirements
10
+
11
+ This gem supports Subversion, Git, Mercurial and Bazaar. Only Subversion and
12
+ Git have been extensively tested. This gem is unlikely to be supported for
13
+ other SCM systems.
14
+
15
+ This gem requires the <tt>rsync</tt> command-line utilities on the local and
16
+ remote hosts. It also requires either <tt>svn</tt>, <tt>git</tt>, <tt>hg</tt>
17
+ or <tt>bzr</tt> on the local host, but not the remote host.
18
+
19
+ This gem is tested on Mac OS X and Linux. Windows is neither tested nor supported.
20
+
21
+ == Installation
22
+
23
+ gem install capistrano_rsync_with_remote_cache
24
+
25
+ == Usage
26
+
27
+ To use this deployment strategy, add this line to your <tt>deploy.rb</tt> file:
28
+
29
+ set :deploy_via, :rsync_with_remote_cache
30
+
31
+ == Under the Hood
32
+
33
+ This strategy maintains two cache directories:
34
+
35
+ * The local cache directory is a checkout from the SCM repository. The local
36
+ cache directory is specified with the <tt>:local_cache</tt> variable in the
37
+ configuration. If not specified, it will default to <tt>.rsync_cache</tt>
38
+ in the same directory as the Capfile.
39
+
40
+ * The remote cache directory is an <tt>rsync</tt> copy of the local cache directory.
41
+ The remote cache directory is specified with the <tt>:repository_cache</tt> variable
42
+ in the configuration (this name comes from the <tt>:remote_cache</tt> strategy that
43
+ ships with Capistrano, and has been maintained for compatibility.) If not
44
+ specified, it will default to <tt>shared/cached-copy</tt> (again, for compatibility
45
+ with remote_cache.)
46
+
47
+ Deployment happens in three major steps. First, the local cache directory is
48
+ processed. There are three possibilities:
49
+
50
+ * If the local cache does not exist, it is created with a checkout of the
51
+ revision to be deployed.
52
+ * If the local cache exists and matches the <tt>:repository</tt> variable, it is
53
+ updated to the revision to be deployed.
54
+ * If the local cache exists and does not match the <p>:repository</p> variable,
55
+ the local cache is purged and recreated with a checkout of the revision
56
+ to be deployed.
57
+ * If the local cache exists but is not a directory, an exception is raised
58
+
59
+ Second, <tt>rsync</tt> runs on the local side to sync the remote cache to the local
60
+ cache. When the <tt>rsync</tt> is complete, the remote cache should be an exact
61
+ replica of the local cache.
62
+
63
+ Finally, a copy of the remote cache is made in the appropriate release
64
+ directory. The end result is the same as if the code had been checked out
65
+ directly on the remote server, as in the default strategy.
66
+
67
+ == License
68
+
69
+ Copyright (c) 2007 - 2010 Patrick Reagan (patrick.reagan@viget.com) & Mark Cornick
70
+
71
+ Permission is hereby granted, free of charge, to any person
72
+ obtaining a copy of this software and associated documentation
73
+ files (the "Software"), to deal in the Software without
74
+ restriction, including without limitation the rights to use,
75
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
76
+ copies of the Software, and to permit persons to whom the
77
+ Software is furnished to do so, subject to the following
78
+ conditions:
79
+
80
+ The above copyright notice and this permission notice shall be
81
+ included in all copies or substantial portions of the Software.
82
+
83
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
84
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
85
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
86
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
87
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
88
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
89
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
90
+ OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,86 +1,30 @@
1
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
-
2
+ require 'rake/gempackagetask'
27
3
  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
4
 
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
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = 'capistrano_rsync_with_remote_cache'
7
+ s.version = '2.3.8'
8
+ s.has_rdoc = true
9
+ s.extra_rdoc_files = %w(README.rdoc)
10
+ s.rdoc_options = %w(--main README.rdoc)
11
+ s.summary = "A deployment strategy for Capistrano 2.0 which combines rsync with a remote cache, allowing fast deployments from SCM servers behind firewalls."
12
+ s.authors = ['Patrick Reagan', 'Mark Cornick']
13
+ s.email = 'patrick.reagan@viget.com'
14
+ s.homepage = 'http://www.viget.com/extend/'
15
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
16
+
17
+ s.add_dependency('capistrano', '>=2.1.0')
46
18
  end
47
19
 
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
20
+ Rake::GemPackageTask.new(spec) do |pkg|
21
+ pkg.gem_spec = spec
61
22
  end
62
23
 
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
24
+ Rake::TestTask.new do |t|
25
+ t.libs << 'test'
26
+ t.test_files = FileList["test/**/*_test.rb"]
27
+ t.verbose = true
73
28
  end
74
29
 
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
30
+ task :default => :test
@@ -5,6 +5,12 @@ module Capistrano
5
5
  module Deploy
6
6
  module Strategy
7
7
  class RsyncWithRemoteCache < Remote
8
+
9
+ class InvalidCacheError < Exception; end
10
+
11
+ def self.default_attribute(attribute, default_value)
12
+ define_method(attribute) { configuration[attribute] || default_value }
13
+ end
8
14
 
9
15
  INFO_COMMANDS = {
10
16
  :subversion => "svn info . | sed -n \'s/URL: //p\'",
@@ -12,23 +18,78 @@ module Capistrano
12
18
  :mercurial => "hg showconfig paths.default",
13
19
  :bzr => "bzr info | grep parent | sed \'s/^.*parent branch: //\'"
14
20
  }
21
+
22
+ default_attribute :rsync_options, '-az --delete'
23
+ default_attribute :local_cache, '.rsync_cache'
24
+ default_attribute :repository_cache, 'cached-copy'
15
25
 
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
26
  def deploy!
19
-
20
- # Step 1: Update the local cache.
27
+ update_local_cache
28
+ update_remote_cache
29
+ copy_remote_cache
30
+ end
31
+
32
+ def update_local_cache
21
33
  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
34
+ mark_local_cache
35
+ end
36
+
37
+ def update_remote_cache
38
+ finder_options = {:except => { :no_release => true }}
39
+ find_servers(finder_options).each {|s| system(rsync_command_for(s)) }
40
+ end
41
+
42
+ def copy_remote_cache
43
+ run("rsync -a --delete #{repository_cache_path}/ #{configuration[:release_path]}/")
44
+ end
45
+
46
+ def rsync_command_for(server)
47
+ "rsync #{rsync_options} --rsh='ssh -p #{ssh_port}' #{local_cache_path}/ #{rsync_host(server)}:#{repository_cache_path}/"
48
+ end
49
+
50
+ def mark_local_cache
51
+ File.open(File.join(local_cache_path, 'REVISION'), 'w') {|f| f << revision }
52
+ end
53
+
54
+ def ssh_port
55
+ ssh_options[:port] || 22
56
+ end
57
+
58
+ def local_cache_path
59
+ File.expand_path(local_cache)
60
+ end
61
+
62
+ def repository_cache_path
63
+ File.join(shared_path, repository_cache)
64
+ end
65
+
66
+ def repository_url
67
+ `cd #{local_cache_path} && #{INFO_COMMANDS[configuration[:scm]]}`.strip
68
+ end
69
+
70
+ def repository_url_changed?
71
+ repository_url != configuration[:repository]
72
+ end
73
+
74
+ def remove_local_cache
75
+ logger.trace "repository has changed; removing old local cache from #{local_cache_path}"
76
+ FileUtils.rm_rf(local_cache_path)
77
+ end
29
78
 
30
- # Step 3: Copy the remote cache into place.
31
- run("rsync -a --delete #{repository_cache}/ #{configuration[:release_path]}/ && #{mark}")
79
+ def remove_cache_if_repository_url_changed
80
+ remove_local_cache if repository_url_changed?
81
+ end
82
+
83
+ def rsync_host(server)
84
+ configuration[:user] ? "#{configuration[:user]}@#{server.host}" : server.host
85
+ end
86
+
87
+ def local_cache_exists?
88
+ File.exist?(local_cache_path)
89
+ end
90
+
91
+ def local_cache_valid?
92
+ local_cache_exists? && File.directory?(local_cache_path)
32
93
  end
33
94
 
34
95
  # Defines commands that should be checked for by deploy:check. These include the SCM command
@@ -44,75 +105,17 @@ module Capistrano
44
105
 
45
106
  private
46
107
 
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 #{File.expand_path(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
108
  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)
109
+ if local_cache_valid?
110
+ source.sync(revision, local_cache_path)
111
+ elsif !local_cache_exists?
112
+ "mkdir -p #{local_cache_path} && #{source.checkout(revision, local_cache_path)}"
108
113
  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)
114
+ raise InvalidCacheError, "The local cache exists but is not valid (#{local_cache_path})"
113
115
  end
114
116
  end
115
117
  end
118
+
116
119
  end
117
120
  end
118
121
  end
@@ -1,174 +1,280 @@
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.
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+ require 'shoulda'
5
+ require 'matchy'
6
+ require 'tmpdir'
4
7
 
5
- require 'test_helper'
8
+ require 'capistrano/recipes/deploy/strategy/rsync_with_remote_cache'
6
9
 
7
10
  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
11
+
12
+ context "An instance of the CapistranoRsyncWithRemoteCache class" do
13
+ setup { @strategy = Capistrano::Deploy::Strategy::RsyncWithRemoteCache.new }
15
14
 
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)
15
+ should "know the default rsync options" do
16
+ @strategy.rsync_options.should == '-az --delete'
22
17
  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 --delete shared/cached-copy/ release_path/ && mark")
44
-
45
- @rwrc.deploy!
18
+
19
+ should "allow overriding of the rsync options" do
20
+ @strategy.stubs(:configuration).with().returns(:rsync_options => 'new_opts')
21
+ @strategy.rsync_options.should == 'new_opts'
46
22
  end
47
23
 
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!
24
+ should "know the default local cache name" do
25
+ @strategy.local_cache.should == '.rsync_cache'
57
26
  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
27
+
28
+ should "know the local cache name if it has been configured" do
29
+ @strategy.stubs(:configuration).with().returns(:local_cache => 'cache')
30
+ @strategy.local_cache.should == 'cache'
73
31
  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
32
+
33
+ should "know the cache path" do
34
+ @strategy.stubs(:local_cache).with().returns('cache_dir')
35
+ File.expects(:expand_path).with('cache_dir').returns('local_cache_path')
36
+
37
+ @strategy.local_cache_path.should == 'local_cache_path'
85
38
  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
39
+
40
+ should "know the repository URL for a subversion repository" do
41
+ @strategy.stubs(:local_cache_path).with().returns('cache_path')
42
+ @strategy.stubs(:configuration).with().returns(:scm => :subversion)
43
+ @strategy.expects(:`).with("cd cache_path && svn info . | sed -n \'s/URL: //p\'").returns("svn_url\n")
44
+ @strategy.repository_url.should == 'svn_url'
97
45
  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
46
+
47
+ should "know the repository URL for a git repository" do
48
+ @strategy.stubs(:local_cache_path).with().returns('cache_path')
49
+ @strategy.stubs(:configuration).with().returns(:scm => :git)
50
+ @strategy.expects(:`).with("cd cache_path && git config remote.origin.url").returns("git_url\n")
51
+ @strategy.repository_url.should == 'git_url'
109
52
  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
53
+
54
+ should "know the repository URL for a mercurial repository" do
55
+ @strategy.stubs(:local_cache_path).with().returns('cache_path')
56
+ @strategy.stubs(:configuration).with().returns(:scm => :mercurial)
57
+ @strategy.expects(:`).with("cd cache_path && hg showconfig paths.default").returns("hg_url\n")
58
+ @strategy.repository_url.should == 'hg_url'
125
59
  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
60
+
61
+ should "know the repository URL for a bzr repository" do
62
+ @strategy.stubs(:local_cache_path).with().returns('cache_path')
63
+ @strategy.stubs(:configuration).with().returns(:scm => :bzr)
64
+ @strategy.expects(:`).with("cd cache_path && bzr info | grep parent | sed \'s/^.*parent branch: //\'").returns("bzr_url\n")
65
+ @strategy.repository_url.should == 'bzr_url'
66
+ end
67
+
68
+ should "know that the repository URL has not changed" do
69
+ @strategy.stubs(:repository_url).with().returns('repo_url')
70
+ @strategy.stubs(:configuration).with().returns(:repository => 'repo_url')
71
+
72
+ @strategy.repository_url_changed?.should be(false)
73
+ end
74
+
75
+ should "know that the repository URL has changed" do
76
+ @strategy.stubs(:repository_url).with().returns('new_repo_url')
77
+ @strategy.stubs(:configuration).with().returns(:repository => 'old_repo_url')
78
+
79
+ @strategy.repository_url_changed?.should be(true)
80
+ end
81
+
82
+ should "be able to remove the local cache" do
83
+ @strategy.stubs(:logger).with().returns(stub(:trace))
84
+ @strategy.stubs(:local_cache_path).with().returns('local_cache_path')
85
+ FileUtils.expects(:rm_rf).with('local_cache_path')
86
+
87
+ @strategy.remove_local_cache
88
+ end
89
+
90
+ should "remove the local cache if the repository URL has changed" do
91
+ @strategy.stubs(:repository_url_changed?).with().returns(true)
92
+ @strategy.expects(:remove_local_cache).with()
93
+
94
+ @strategy.remove_cache_if_repository_url_changed
95
+ end
96
+
97
+ should "not remove the local cache if the repository URL has not changed" do
98
+ @strategy.stubs(:repository_url_changed?).with().returns(false)
99
+ @strategy.expects(:remove_local_cache).with().never
100
+
101
+ @strategy.remove_cache_if_repository_url_changed
102
+ end
103
+
104
+ should "know the default SSH port" do
105
+ @strategy.stubs(:ssh_options).with().returns({})
106
+ @strategy.ssh_port.should == 22
107
+ end
108
+
109
+ should "be able to override the default SSH port" do
110
+ @strategy.stubs(:ssh_options).with().returns({:port => 95})
111
+ @strategy.ssh_port.should == 95
151
112
  end
152
113
 
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
114
+ should "know the default repository cache" do
115
+ @strategy.repository_cache.should == 'cached-copy'
116
+ end
117
+
118
+ should "be able to override the default repository cache" do
119
+ @strategy.stubs(:configuration).with().returns(:repository_cache => 'other_cache')
120
+ @strategy.repository_cache.should == 'other_cache'
121
+ end
122
+
123
+ should "know the repository cache path" do
124
+ @strategy.stubs(:shared_path).with().returns('shared_path')
125
+ @strategy.stubs(:repository_cache).with().returns('cache_path')
126
+
127
+ File.expects(:join).with('shared_path', 'cache_path').returns('path')
128
+ @strategy.repository_cache_path.should == 'path'
129
+ end
130
+
131
+ should "be able to determine the hostname for the rsync command" do
132
+ server = stub(:host => 'host.com')
133
+ @strategy.rsync_host(server).should == 'host.com'
134
+ end
135
+
136
+ should "be able to determine the hostname for the rsync command when a user is configured" do
137
+ @strategy.stubs(:configuration).with().returns(:user => 'foobar')
138
+ server = stub(:host => 'host.com')
139
+
140
+ @strategy.rsync_host(server).should == 'foobar@host.com'
141
+ end
142
+
143
+ should "know that the local cache exists" do
144
+ @strategy.stubs(:local_cache_path).with().returns('path')
145
+ File.stubs(:exist?).with('path').returns(true)
146
+
147
+ @strategy.local_cache_exists?.should be(true)
148
+ end
149
+
150
+ should "know that the local cache does not exist" do
151
+ @strategy.stubs(:local_cache_path).with().returns('path')
152
+ File.stubs(:exist?).with('path').returns(false)
153
+
154
+ @strategy.local_cache_exists?.should be(false)
155
+ end
156
+
157
+ should "know that the local cache is not valid if it does not exist" do
158
+ @strategy.stubs(:local_cache_exists?).with().returns(false)
159
+ @strategy.local_cache_valid?.should be(false)
160
+ end
161
+
162
+ should "know that the local cache is not valid if it's not a directory" do
163
+ @strategy.stubs(:local_cache_path).with().returns('path')
164
+ @strategy.stubs(:local_cache_exists?).with().returns(true)
165
+
166
+ File.stubs(:directory?).with('path').returns(false)
167
+ @strategy.local_cache_valid?.should be(false)
168
+ end
169
+
170
+ should "know that the local cache is valid" do
171
+ @strategy.stubs(:local_cache_path).with().returns('path')
172
+ @strategy.stubs(:local_cache_exists?).with().returns(true)
173
+
174
+ File.stubs(:directory?).with('path').returns(true)
175
+ @strategy.local_cache_valid?.should be(true)
176
+ end
177
+
178
+ should "know the SCM command when the local cache is valid" do
179
+ source = mock() {|s| s.expects(:sync).with('revision', 'path').returns('scm_command') }
180
+
181
+ @strategy.stubs(:local_cache_valid?).with().returns(true)
182
+ @strategy.stubs(:local_cache_path).with().returns('path')
183
+ @strategy.stubs(:revision).with().returns('revision')
184
+ @strategy.stubs(:source).with().returns(source)
185
+
186
+ @strategy.send(:command).should == 'scm_command'
187
+ end
188
+
189
+ should "know the SCM command when the local cache does not exist" do
190
+ source = mock() {|s| s.expects(:checkout).with('revision', 'path').returns('scm_command') }
191
+
192
+ @strategy.stubs(:local_cache_valid?).with().returns(false)
193
+ @strategy.stubs(:local_cache_exists?).with().returns(false)
194
+ @strategy.stubs(:local_cache_path).with().returns('path')
195
+ @strategy.stubs(:revision).with().returns('revision')
196
+ @strategy.stubs(:source).with().returns(source)
197
+
198
+ @strategy.send(:command).should == 'mkdir -p path && scm_command'
199
+ end
200
+
201
+ should "raise an exception when the local cache is invalid" do
202
+ @strategy.stubs(:local_cache_valid?).with().returns(false)
203
+ @strategy.stubs(:local_cache_exists?).with().returns(true)
204
+
205
+ lambda {
206
+ @strategy.send(:command)
207
+ }.should raise_error(Capistrano::Deploy::Strategy::RsyncWithRemoteCache::InvalidCacheError)
208
+ end
209
+
210
+ should "be able to tag the local cache" do
211
+ local_cache_path = Dir.tmpdir
212
+ @strategy.stubs(:revision).with().returns('1')
213
+ @strategy.stubs(:local_cache_path).with().returns(local_cache_path)
214
+
215
+ @strategy.mark_local_cache
216
+
217
+ File.read(File.join(local_cache_path, 'REVISION')).should == '1'
218
+ end
219
+
220
+ should "be able to update the local cache" do
221
+ @strategy.stubs(:command).with().returns('scm_command')
222
+ @strategy.expects(:system).with('scm_command')
223
+ @strategy.expects(:mark_local_cache).with()
224
+
225
+ @strategy.update_local_cache
226
+ end
227
+
228
+ should "be able to run the rsync command on a server" do
229
+ server = stub()
230
+
231
+ @strategy.stubs(:rsync_host).with(server).returns('rsync_host')
232
+
233
+ @strategy.stubs(
234
+ :rsync_options => 'rsync_options',
235
+ :ssh_port => 'ssh_port',
236
+ :local_cache_path => 'local_cache_path',
237
+ :repository_cache_path => 'repository_cache_path'
238
+ )
239
+
240
+ expected = "rsync rsync_options --rsh='ssh -p ssh_port' local_cache_path/ rsync_host:repository_cache_path/"
241
+
242
+ @strategy.rsync_command_for(server).should == expected
243
+ end
244
+
245
+ should "be able to update the remote cache" do
246
+ server_1, server_2 = [stub(), stub()]
247
+ @strategy.stubs(:find_servers).with(:except => {:no_release => true}).returns([server_1, server_2])
248
+
249
+ @strategy.stubs(:rsync_command_for).with(server_1).returns('server_1_rsync_command')
250
+ @strategy.stubs(:rsync_command_for).with(server_2).returns('server_2_rsync_command')
251
+
252
+ @strategy.expects(:system).with('server_1_rsync_command')
253
+ @strategy.expects(:system).with('server_2_rsync_command')
254
+
255
+ @strategy.update_remote_cache
256
+ end
257
+
258
+ should "be able copy the remote cache into place" do
259
+ @strategy.stubs(
260
+ :repository_cache_path => 'repository_cache_path',
261
+ :configuration => {:release_path => 'release_path'}
262
+ )
263
+
264
+ command = "rsync -a --delete repository_cache_path/ release_path/"
265
+ @strategy.expects(:run).with(command)
266
+
267
+ @strategy.copy_remote_cache
268
+ end
269
+
270
+ should "be able to deploy" do
271
+ @strategy.expects(:update_local_cache).with()
272
+ @strategy.expects(:update_remote_cache).with()
273
+ @strategy.expects(:copy_remote_cache).with()
274
+
275
+ @strategy.deploy!
172
276
  end
277
+
173
278
  end
279
+
174
280
  end
metadata CHANGED
@@ -5,16 +5,17 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 3
8
- - 7
9
- version: 2.3.7
8
+ - 8
9
+ version: 2.3.8
10
10
  platform: ruby
11
11
  authors:
12
+ - Patrick Reagan
12
13
  - Mark Cornick
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-03-12 00:00:00 -05:00
18
+ date: 2010-04-08 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -26,62 +27,32 @@ dependencies:
26
27
  - !ruby/object:Gem::Version
27
28
  segments:
28
29
  - 2
30
+ - 1
29
31
  - 0
30
- version: "2.0"
32
+ version: 2.1.0
31
33
  type: :runtime
32
34
  version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: thoughtbot-shoulda
35
- prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
- version: "0"
43
- type: :development
44
- version_requirements: *id002
45
- - !ruby/object:Gem::Dependency
46
- name: yard
47
- prerelease: false
48
- requirement: &id003 !ruby/object:Gem::Requirement
49
- requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- segments:
53
- - 0
54
- version: "0"
55
- type: :development
56
- version_requirements: *id003
57
- description: A deployment strategy for Capistrano 2.0 which combines rsync with a remote cache, allowing fast deployments from SCM servers behind firewalls.
58
- email: mark@viget.com
35
+ description:
36
+ email: patrick.reagan@viget.com
59
37
  executables: []
60
38
 
61
39
  extensions: []
62
40
 
63
41
  extra_rdoc_files:
64
- - LICENSE
65
- - README.md
42
+ - README.rdoc
66
43
  files:
67
- - .document
68
- - .gitignore
69
- - LICENSE
70
- - README.md
44
+ - README.rdoc
71
45
  - Rakefile
72
- - VERSION
73
- - capistrano_rsync_with_remote_cache.gemspec
74
- - lib/capistrano/recipes/deploy/strategy/exceptions.reek
75
46
  - lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb
76
47
  - test/capistrano_rsync_with_remote_cache_test.rb
77
- - test/test_helper.rb
78
48
  has_rdoc: true
79
- homepage: http://github.com/vigetlabs/capistrano_rsync_with_remote_cache
49
+ homepage: http://www.viget.com/extend/
80
50
  licenses: []
81
51
 
82
52
  post_install_message:
83
53
  rdoc_options:
84
- - --charset=UTF-8
54
+ - --main
55
+ - README.rdoc
85
56
  require_paths:
86
57
  - lib
87
58
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -100,11 +71,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
71
  version: "0"
101
72
  requirements: []
102
73
 
103
- rubyforge_project: viget
74
+ rubyforge_project:
104
75
  rubygems_version: 1.3.6
105
76
  signing_key:
106
77
  specification_version: 3
107
- summary: rsync_with_remote_cache strategy for Capistrano
108
- test_files:
109
- - test/capistrano_rsync_with_remote_cache_test.rb
110
- - test/test_helper.rb
78
+ summary: A deployment strategy for Capistrano 2.0 which combines rsync with a remote cache, allowing fast deployments from SCM servers behind firewalls.
79
+ test_files: []
80
+
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.md
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- /pkg/
2
- /doc/
3
- /coverage/
4
- *.gem
5
- .yardoc
data/LICENSE DELETED
@@ -1,20 +0,0 @@
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 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 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 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/VERSION DELETED
@@ -1 +0,0 @@
1
- 2.3.7
@@ -1,62 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{capistrano_rsync_with_remote_cache}
8
- s.version = "2.3.7"
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{2010-03-12}
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.6}
37
- s.summary = %q{rsync_with_remote_cache strategy for Capistrano}
38
- s.test_files = [
39
- "test/capistrano_rsync_with_remote_cache_test.rb",
40
- "test/test_helper.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
62
-
@@ -1,15 +0,0 @@
1
- ---
2
- Duplication:
3
- exclude:
4
- - check!
5
- - command
6
- - deploy!
7
- - rsync_host
8
- - remove_cache_if_repo_changed
9
-
10
- FeatureEnvy:
11
- exclude:
12
- - check!
13
-
14
- LongMethod:
15
- max_statements: 10
data/test/test_helper.rb DELETED
@@ -1,11 +0,0 @@
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