capistrano_rsync_with_remote_cache 2.3.3 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc 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 has only been tested with Subversion and Git. It is unlikely to be supported for other SCM systems.
10
+
11
+ This gem requires <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 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 <tt>deploy.rb</tt> 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 <tt>local_cache</tt> variable in the configuration. If not specified, it will default to <tt>.rsync_cache</tt> 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 <tt>repository_cache</tt> variable in the configuration (this name comes from the <tt>remote_cache</tt> strategy that ships with Capistrano, and has been maintained for compatibility.) If not specified, it will default to <tt>shared/cached-copy</tt> (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 <tt>:repository</tt> variable, it is updated to the revision to be deployed.
32
+ * If the local cache exists and does not match the <tt>:repository</tt> 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.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 2
3
3
  :minor: 3
4
- :patch: 3
4
+ :patch: 4
@@ -6,7 +6,8 @@ module Capistrano
6
6
  module Strategy
7
7
  class RsyncWithRemoteCache < Remote
8
8
 
9
- # The deployment method itself, in three major steps.
9
+ # The deployment method itself, in three major steps: update the local cache, update the remote
10
+ # cache, and copy the remote cache into place.
10
11
  def deploy!
11
12
 
12
13
  # Step 1: Update the local cache.
@@ -61,27 +62,32 @@ module Capistrano
61
62
  server.host
62
63
  end
63
64
  end
64
-
65
+
65
66
  # Command to get source from SCM on the local side. If the local_cache directory exists,
66
67
  # we check to see if it's an SCM checkout that matches the currently configured repository.
67
68
  # If it matches, we update it. If it doesn't match (either it's for another repository or
68
69
  # not a checkout at all), we remove the directory and recreate it with a fresh SCM checkout.
69
70
  # If the directory doesn't exist, we create it with a fresh SCM checkout.
70
- #
71
- # FIXME: The above logic only takes place if the SCM is Subversion. At some point, similar logic
72
- # will probably be necessary for Git and other SCMs we might use.
73
- #
74
71
  # TODO: punt in some sensible way if local_cache exists but is a regular file.
75
72
  def command
76
- if configuration[:scm] == :subversion
77
- svn_info = IO.popen("svn info #{local_cache} | sed -n 's/URL: //p'")
78
- svn_url = svn_info.gets
79
- svn_info.close
80
- if svn_url && svn_url.chomp != configuration[:repository]
81
- logger.trace "repository has changed; removing old local cache"
82
- FileUtils.rm_rf local_cache
83
- end
73
+ case configuration[:scm].to_s
74
+ when 'subversion'
75
+ info_command = "svn info #{local_cache} | sed -n 's/URL: //p'"
76
+ when 'git'
77
+ info_command = "cd #{local_cache} && git config remote.origin.url"
78
+ else
79
+ # an effective no-op
80
+ info_command = "echo #{configuration[:repository]}"
84
81
  end
82
+ cache_info = IO.popen(info_command)
83
+
84
+ cached_repository = cache_info.gets
85
+ cache_info.close
86
+ if cached_repository && cached_repository.chomp != configuration[:repository]
87
+ logger.trace "repository has changed; removing old local cache"
88
+ FileUtils.rm_rf local_cache
89
+ end
90
+
85
91
  if File.exists?(local_cache) && File.directory?(local_cache)
86
92
  logger.trace "updating local cache to revision #{revision}"
87
93
  cmd = source.sync(revision, local_cache)
@@ -17,7 +17,14 @@ class CapistranoRsyncWithRemoteCacheTest < Test::Unit::TestCase
17
17
  source_stub.expects(:checkout)
18
18
  @rwrc.expects(:source).returns(source_stub)
19
19
  end
20
-
20
+
21
+ def stub_detection_of_changed_local_cache(command, returns)
22
+ cache_info_stub = stub()
23
+ cache_info_stub.expects(:gets).returns(returns)
24
+ cache_info_stub.expects(:close)
25
+ IO.expects(:popen).with(command).returns(cache_info_stub)
26
+ end
27
+
21
28
  context 'RsyncWithRemoteCache' do
22
29
  setup do
23
30
  @rwrc = Capistrano::Deploy::Strategy::RsyncWithRemoteCache.new
@@ -117,42 +124,37 @@ class CapistranoRsyncWithRemoteCacheTest < Test::Unit::TestCase
117
124
  end
118
125
 
119
126
  context 'command' do
120
- should 'purge and recreate local cache if it detects subversion info has changed' do
127
+ should 'purge local cache if it detects subversion info has changed' do
121
128
  stub_configuration(:scm => :subversion, :repository => 'repository')
129
+ stub_detection_of_changed_local_cache("svn info .rsync_cache | sed -n 's/URL: //p'", "URL: url\n")
130
+ FileUtils.expects(:rm_rf).with('.rsync_cache')
131
+ stub_creation_of_new_local_cache
122
132
 
123
- svn_info_stub = stub()
124
- svn_info_stub.expects(:gets).returns("URL: url\n")
125
- svn_info_stub.expects(:close)
126
- IO.expects(:popen).with("svn info .rsync_cache | sed -n 's/URL: //p'").returns(svn_info_stub)
133
+ @rwrc.send(:command)
134
+ end
127
135
 
136
+ should 'purge local cache if it detects git info has changed' do
137
+ stub_configuration(:scm => :git, :repository => 'repository')
138
+ stub_detection_of_changed_local_cache("cd .rsync_cache && git config remote.origin.url", "beep\n")
128
139
  FileUtils.expects(:rm_rf).with('.rsync_cache')
129
-
130
140
  stub_creation_of_new_local_cache
131
141
 
132
142
  @rwrc.send(:command)
133
143
  end
134
144
 
135
- should 'not attempt to purge and recreate local cache that does not exist' do
145
+ should 'not attempt to purge local cache that does not exist' do
136
146
  stub_configuration(:scm => :subversion, :repository => 'repository')
137
-
138
- svn_info_stub = stub()
139
- svn_info_stub.expects(:gets).returns(nil)
140
- svn_info_stub.expects(:close)
141
- IO.expects(:popen).with("svn info .rsync_cache | sed -n 's/URL: //p'").returns(svn_info_stub)
142
-
147
+ stub_detection_of_changed_local_cache("svn info .rsync_cache | sed -n 's/URL: //p'", nil)
143
148
  FileUtils.expects(:rm_rf).with('.rsync_cache').never
144
-
145
149
  stub_creation_of_new_local_cache
146
150
 
147
151
  @rwrc.send(:command)
148
152
  end
149
153
 
150
- should 'not attempt to purge and recreate local cache if the scm is not subversion' do
151
- stub_configuration(:scm => :git, :repository => 'repository')
152
-
153
- IO.expects(:popen).with("svn info .rsync_cache | sed -n 's/URL: //p'").never
154
+ should 'not attempt to purge local cache if the scm is not supported by this gem' do
155
+ stub_configuration(:scm => :bzr, :repository => 'repository')
156
+ stub_detection_of_changed_local_cache("echo repository", "repository\n")
154
157
  FileUtils.expects(:rm_rf).with('.rsync_cache').never
155
-
156
158
  stub_creation_of_new_local_cache
157
159
 
158
160
  @rwrc.send(:command)
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: 2.3.3
4
+ version: 2.3.4
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: 2009-05-18 00:00:00 -04:00
12
+ date: 2009-05-19 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,10 +30,10 @@ extensions: []
30
30
 
31
31
  extra_rdoc_files:
32
32
  - LICENSE
33
- - README.md
33
+ - README.rdoc
34
34
  files:
35
35
  - LICENSE
36
- - README.md
36
+ - README.rdoc
37
37
  - Rakefile
38
38
  - VERSION.yml
39
39
  - lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb
data/README.md DELETED
@@ -1,32 +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 `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.