capistrano_rsync_with_remote_cache 2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README 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 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
@@ -0,0 +1,94 @@
1
+ require 'capistrano/recipes/deploy/strategy/remote'
2
+
3
+ module Capistrano
4
+ module Deploy
5
+ module Strategy
6
+ class RsyncWithRemoteCache < Remote
7
+
8
+ # The deployment method itself, in three major steps.
9
+ def deploy!
10
+
11
+ # Step 1: Update the local cache.
12
+ system(command)
13
+ File.open(File.join(local_cache, "REVISION"), "w") { |f| f.puts(revision) }
14
+
15
+ # Step 2: Update the remote cache.
16
+ logger.trace "copying local cache to remote"
17
+ find_servers(:roles => :app, :except => { :no_release => true }).each do |server|
18
+ system("rsync #{rsync_options} #{local_cache}/ #{rsync_host(server)}:#{repository_cache}/")
19
+ end
20
+
21
+ # Step 3: Copy the remote cache into place.
22
+ run("rsync -a --delete #{repository_cache}/ #{configuration[:release_path]}/ && #{mark}")
23
+ end
24
+
25
+ # Defines commands that should be checked for by deploy:check. These include the SCM command
26
+ # on the local end, and rsync on both ends. Note that the SCM command is not needed on the
27
+ # remote end.
28
+ def check!
29
+ super.check do |d|
30
+ d.local.command(source.command)
31
+ d.local.command('rsync')
32
+ d.remote.command('rsync')
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ # Path to the remote cache. We use a variable name and default that are compatible with
39
+ # the stock remote_cache strategy, for easy migration.
40
+ def repository_cache
41
+ File.join(shared_path, configuration[:repository_cache] || "cached-copy")
42
+ end
43
+
44
+ # Path to the local cache. If not specified in the Capfile, we use an arbitrary default.
45
+ def local_cache
46
+ configuration[:local_cache] || ".rsync_cache"
47
+ end
48
+
49
+ # Options to use for rsync in step 2. If not specified in the Capfile, we use the default
50
+ # from prior versions.
51
+ def rsync_options
52
+ configuration[:rsync_options] || "-az --delete"
53
+ end
54
+
55
+ # Returns the host used in the rsync command, prefixed with user@ if user is specified in Capfile.
56
+ def rsync_host(server)
57
+ if configuration[:user]
58
+ "#{configuration[:user]}@#{server.host}"
59
+ else
60
+ server.host
61
+ end
62
+ end
63
+
64
+ # Command to get source from SCM on the local side. If the local_cache directory exists,
65
+ # we check to see if it's an SCM checkout that matches the currently configured repository.
66
+ # If it matches, we update it. If it doesn't match (either it's for another repository or
67
+ # not a checkout at all), we remove the directory and recreate it with a fresh SCM checkout.
68
+ # If the directory doesn't exist, we create it with a fresh SCM checkout.
69
+ #
70
+ # FIXME: The above logic only takes place if the SCM is Subversion. At some point, similar logic
71
+ # will probably be necessary for Git and other SCMs we might use.
72
+ #
73
+ # TODO: punt in some sensible way if local_cache exists but is a regular file.
74
+ def command
75
+ if (configuration[:scm] == :subversion &&
76
+ `svn info #{local_cache} | sed -n 's/URL: //p'`.strip != configuration[:repository])
77
+ logger.trace "repository has changed; removing old local cache"
78
+ system("rm -rf #{local_cache}")
79
+ end
80
+ if File.exists?(local_cache) && File.directory?(local_cache)
81
+ logger.trace "updating local cache to revision #{revision}"
82
+ cmd = source.sync(revision, local_cache)
83
+ else
84
+ logger.trace "creating local cache with revision #{revision}"
85
+ File.delete(local_cache) if File.exists?(local_cache)
86
+ Dir.mkdir(File.dirname(local_cache)) unless File.directory?(File.dirname(local_cache))
87
+ cmd = source.checkout(revision, local_cache)
88
+ end
89
+ cmd
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano_rsync_with_remote_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: "2.2"
5
+ platform: ruby
6
+ authors:
7
+ - Mark Cornick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-26 00:00:00 -04: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
+ description:
26
+ email: mark@viget.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ files:
34
+ - lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb
35
+ - README
36
+ has_rdoc: true
37
+ homepage: http://github.com/vigetlabs/capistrano_rsync_with_remote_cache
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: A deployment strategy for Capistrano 2.0 which combines rsync with a remote cache, allowing fast deployments from SCM servers behind firewalls.
62
+ test_files: []
63
+