HeSYINUvSBZfxqA-capistrano 2.5.21
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/CHANGELOG +866 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +31 -0
- data/HeSYINUvSBZfxqA-capistrano.gemspec +49 -0
- data/README.mdown +65 -0
- data/Rakefile +11 -0
- data/VERSION +1 -0
- data/bin/cap +4 -0
- data/bin/capify +86 -0
- data/lib/capistrano.rb +2 -0
- data/lib/capistrano/callback.rb +45 -0
- data/lib/capistrano/cli.rb +47 -0
- data/lib/capistrano/cli/execute.rb +85 -0
- data/lib/capistrano/cli/help.rb +125 -0
- data/lib/capistrano/cli/help.txt +78 -0
- data/lib/capistrano/cli/options.rb +243 -0
- data/lib/capistrano/cli/ui.rb +40 -0
- data/lib/capistrano/command.rb +286 -0
- data/lib/capistrano/configuration.rb +44 -0
- data/lib/capistrano/configuration/actions/file_transfer.rb +47 -0
- data/lib/capistrano/configuration/actions/inspect.rb +46 -0
- data/lib/capistrano/configuration/actions/invocation.rb +295 -0
- data/lib/capistrano/configuration/callbacks.rb +148 -0
- data/lib/capistrano/configuration/connections.rb +204 -0
- data/lib/capistrano/configuration/execution.rb +143 -0
- data/lib/capistrano/configuration/loading.rb +197 -0
- data/lib/capistrano/configuration/namespaces.rb +197 -0
- data/lib/capistrano/configuration/roles.rb +73 -0
- data/lib/capistrano/configuration/servers.rb +98 -0
- data/lib/capistrano/configuration/variables.rb +127 -0
- data/lib/capistrano/errors.rb +19 -0
- data/lib/capistrano/extensions.rb +57 -0
- data/lib/capistrano/logger.rb +59 -0
- data/lib/capistrano/processable.rb +53 -0
- data/lib/capistrano/recipes/compat.rb +32 -0
- data/lib/capistrano/recipes/deploy.rb +597 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
- data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +111 -0
- data/lib/capistrano/recipes/deploy/scm.rb +19 -0
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +196 -0
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +153 -0
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +96 -0
- data/lib/capistrano/recipes/deploy/scm/git.rb +274 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
- data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +138 -0
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
- data/lib/capistrano/recipes/deploy/strategy/base.rb +88 -0
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +223 -0
- data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +57 -0
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/standard.rb +37 -0
- data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/role.rb +102 -0
- data/lib/capistrano/server_definition.rb +56 -0
- data/lib/capistrano/shell.rb +260 -0
- data/lib/capistrano/ssh.rb +101 -0
- data/lib/capistrano/task_definition.rb +75 -0
- data/lib/capistrano/transfer.rb +216 -0
- data/lib/capistrano/version.rb +18 -0
- data/rvmrc.sample +1 -0
- data/test/cli/execute_test.rb +132 -0
- data/test/cli/help_test.rb +165 -0
- data/test/cli/options_test.rb +329 -0
- data/test/cli/ui_test.rb +28 -0
- data/test/cli_test.rb +17 -0
- data/test/command_test.rb +286 -0
- data/test/configuration/actions/file_transfer_test.rb +61 -0
- data/test/configuration/actions/inspect_test.rb +65 -0
- data/test/configuration/actions/invocation_test.rb +225 -0
- data/test/configuration/callbacks_test.rb +220 -0
- data/test/configuration/connections_test.rb +349 -0
- data/test/configuration/execution_test.rb +175 -0
- data/test/configuration/loading_test.rb +132 -0
- data/test/configuration/namespace_dsl_test.rb +311 -0
- data/test/configuration/roles_test.rb +144 -0
- data/test/configuration/servers_test.rb +158 -0
- data/test/configuration/variables_test.rb +190 -0
- data/test/configuration_test.rb +88 -0
- data/test/deploy/local_dependency_test.rb +76 -0
- data/test/deploy/remote_dependency_test.rb +135 -0
- data/test/deploy/scm/accurev_test.rb +23 -0
- data/test/deploy/scm/base_test.rb +55 -0
- data/test/deploy/scm/bzr_test.rb +51 -0
- data/test/deploy/scm/darcs_test.rb +37 -0
- data/test/deploy/scm/git_test.rb +184 -0
- data/test/deploy/scm/mercurial_test.rb +134 -0
- data/test/deploy/scm/none_test.rb +35 -0
- data/test/deploy/scm/subversion_test.rb +32 -0
- data/test/deploy/strategy/copy_test.rb +302 -0
- data/test/extensions_test.rb +69 -0
- data/test/fixtures/cli_integration.rb +5 -0
- data/test/fixtures/config.rb +5 -0
- data/test/fixtures/custom.rb +3 -0
- data/test/logger_test.rb +123 -0
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +121 -0
- data/test/shell_test.rb +90 -0
- data/test/ssh_test.rb +113 -0
- data/test/task_definition_test.rb +116 -0
- data/test/transfer_test.rb +160 -0
- data/test/utils.rb +39 -0
- metadata +271 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'capistrano/recipes/deploy/dependencies'
|
3
|
+
|
4
|
+
module Capistrano
|
5
|
+
module Deploy
|
6
|
+
module Strategy
|
7
|
+
|
8
|
+
# This class defines the abstract interface for all Capistrano
|
9
|
+
# deployment strategies. Subclasses must implement at least the
|
10
|
+
# #deploy! method.
|
11
|
+
class Base
|
12
|
+
attr_reader :configuration
|
13
|
+
|
14
|
+
# Instantiates a strategy with a reference to the given configuration.
|
15
|
+
def initialize(config={})
|
16
|
+
@configuration = config
|
17
|
+
end
|
18
|
+
|
19
|
+
# Executes the necessary commands to deploy the revision of the source
|
20
|
+
# code identified by the +revision+ variable. Additionally, this
|
21
|
+
# should write the value of the +revision+ variable to a file called
|
22
|
+
# REVISION, in the base of the deployed revision. This file is used by
|
23
|
+
# other tasks, to perform diffs and such.
|
24
|
+
def deploy!
|
25
|
+
raise NotImplementedError, "`deploy!' is not implemented by #{self.class.name}"
|
26
|
+
end
|
27
|
+
|
28
|
+
# Performs a check on the remote hosts to determine whether everything
|
29
|
+
# is setup such that a deploy could succeed.
|
30
|
+
def check!
|
31
|
+
Dependencies.new(configuration) do |d|
|
32
|
+
d.remote.directory(configuration[:releases_path]).or("`#{configuration[:releases_path]}' does not exist. Please run `cap deploy:setup'.")
|
33
|
+
d.remote.writable(configuration[:deploy_to]).or("You do not have permissions to write to `#{configuration[:deploy_to]}'.")
|
34
|
+
d.remote.writable(configuration[:releases_path]).or("You do not have permissions to write to `#{configuration[:releases_path]}'.")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
# This is to allow helper methods like "run" and "put" to be more
|
41
|
+
# easily accessible to strategy implementations.
|
42
|
+
def method_missing(sym, *args, &block)
|
43
|
+
if configuration.respond_to?(sym)
|
44
|
+
configuration.send(sym, *args, &block)
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# A wrapper for Kernel#system that logs the command being executed.
|
51
|
+
def system(*args)
|
52
|
+
cmd = args.join(' ')
|
53
|
+
result = nil
|
54
|
+
if RUBY_PLATFORM =~ /win32/
|
55
|
+
cmd = cmd.split(/\s+/).collect {|w| w.match(/^[\w+]+:\/\//) ? w : w.gsub('/', '\\') }.join(' ') # Split command by spaces, change / by \\ unless element is a some+thing://
|
56
|
+
cmd.gsub!(/^cd /,'cd /D ') # Replace cd with cd /D
|
57
|
+
cmd.gsub!(/&& cd /,'&& cd /D ') # Replace cd with cd /D
|
58
|
+
logger.trace "executing locally: #{cmd}"
|
59
|
+
elapsed = Benchmark.realtime do
|
60
|
+
result = super(cmd)
|
61
|
+
end
|
62
|
+
else
|
63
|
+
logger.trace "executing locally: #{cmd}"
|
64
|
+
elapsed = Benchmark.realtime do
|
65
|
+
result = super
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
logger.trace "command finished in #{(elapsed * 1000).round}ms"
|
70
|
+
result
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def logger
|
76
|
+
@logger ||= configuration[:logger] || Capistrano::Logger.new(:output => STDOUT)
|
77
|
+
end
|
78
|
+
|
79
|
+
# The revision to deploy. Must return a real revision identifier,
|
80
|
+
# and not a pseudo-id.
|
81
|
+
def revision
|
82
|
+
configuration[:real_revision]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/strategy/remote'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Deploy
|
5
|
+
module Strategy
|
6
|
+
|
7
|
+
# Implements the deployment strategy which does an SCM checkout on each
|
8
|
+
# target host. This is the default deployment strategy for Capistrano.
|
9
|
+
class Checkout < Remote
|
10
|
+
protected
|
11
|
+
|
12
|
+
# Returns the SCM's checkout command for the revision to deploy.
|
13
|
+
def command
|
14
|
+
@command ||= source.checkout(revision, configuration[:release_path])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/strategy/base'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'tempfile' # Dir.tmpdir
|
4
|
+
|
5
|
+
module Capistrano
|
6
|
+
module Deploy
|
7
|
+
module Strategy
|
8
|
+
|
9
|
+
# This class implements the strategy for deployments which work
|
10
|
+
# by preparing the source code locally, compressing it, copying the
|
11
|
+
# file to each target host, and uncompressing it to the deployment
|
12
|
+
# directory.
|
13
|
+
#
|
14
|
+
# By default, the SCM checkout command is used to obtain the local copy
|
15
|
+
# of the source code. If you would rather use the export operation,
|
16
|
+
# you can set the :copy_strategy variable to :export.
|
17
|
+
#
|
18
|
+
# set :copy_strategy, :export
|
19
|
+
#
|
20
|
+
# For even faster deployments, you can set the :copy_cache variable to
|
21
|
+
# true. This will cause deployments to do a new checkout of your
|
22
|
+
# repository to a new directory, and then copy that checkout. Subsequent
|
23
|
+
# deploys will just resync that copy, rather than doing an entirely new
|
24
|
+
# checkout. Additionally, you can specify file patterns to exclude from
|
25
|
+
# the copy when using :copy_cache; just set the :copy_exclude variable
|
26
|
+
# to a file glob (or an array of globs).
|
27
|
+
#
|
28
|
+
# set :copy_cache, true
|
29
|
+
# set :copy_exclude, ".git/*"
|
30
|
+
#
|
31
|
+
# Note that :copy_strategy is ignored when :copy_cache is set. Also, if
|
32
|
+
# you want the copy cache put somewhere specific, you can set the variable
|
33
|
+
# to the path you want, instead of merely 'true':
|
34
|
+
#
|
35
|
+
# set :copy_cache, "/tmp/caches/myapp"
|
36
|
+
#
|
37
|
+
# This deployment strategy also supports a special variable,
|
38
|
+
# :copy_compression, which must be one of :gzip, :bz2, or
|
39
|
+
# :zip, and which specifies how the source should be compressed for
|
40
|
+
# transmission to each host.
|
41
|
+
class Copy < Base
|
42
|
+
# Obtains a copy of the source code locally (via the #command method),
|
43
|
+
# compresses it to a single file, copies that file to all target
|
44
|
+
# servers, and uncompresses it on each of them into the deployment
|
45
|
+
# directory.
|
46
|
+
def deploy!
|
47
|
+
if copy_cache
|
48
|
+
if File.exists?(copy_cache)
|
49
|
+
logger.debug "refreshing local cache to revision #{revision} at #{copy_cache}"
|
50
|
+
system(source.sync(revision, copy_cache))
|
51
|
+
else
|
52
|
+
logger.debug "preparing local cache at #{copy_cache}"
|
53
|
+
system(source.checkout(revision, copy_cache))
|
54
|
+
end
|
55
|
+
|
56
|
+
# Check the return code of last system command and rollback if not 0
|
57
|
+
unless $? == 0
|
58
|
+
raise Capistrano::Error, "shell command failed with return code #{$?}"
|
59
|
+
end
|
60
|
+
|
61
|
+
logger.debug "copying cache to deployment staging area #{destination}"
|
62
|
+
Dir.chdir(copy_cache) do
|
63
|
+
FileUtils.mkdir_p(destination)
|
64
|
+
queue = Dir.glob("*", File::FNM_DOTMATCH)
|
65
|
+
while queue.any?
|
66
|
+
item = queue.shift
|
67
|
+
name = File.basename(item)
|
68
|
+
|
69
|
+
next if name == "." || name == ".."
|
70
|
+
next if copy_exclude.any? { |pattern| File.fnmatch(pattern, item) }
|
71
|
+
|
72
|
+
if File.symlink?(item)
|
73
|
+
FileUtils.ln_s(File.readlink(File.join(copy_cache, item)), File.join(destination, item))
|
74
|
+
elsif File.directory?(item)
|
75
|
+
queue += Dir.glob("#{item}/*", File::FNM_DOTMATCH)
|
76
|
+
FileUtils.mkdir(File.join(destination, item))
|
77
|
+
else
|
78
|
+
FileUtils.ln(File.join(copy_cache, item), File.join(destination, item))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
else
|
83
|
+
logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
|
84
|
+
system(command)
|
85
|
+
|
86
|
+
if copy_exclude.any?
|
87
|
+
logger.debug "processing exclusions..."
|
88
|
+
if copy_exclude.any?
|
89
|
+
copy_exclude.each do |pattern|
|
90
|
+
delete_list = Dir.glob(File.join(destination, pattern), File::FNM_DOTMATCH)
|
91
|
+
# avoid the /.. trap that deletes the parent directories
|
92
|
+
delete_list.delete_if { |dir| dir =~ /\/\.\.$/ }
|
93
|
+
FileUtils.rm_rf(delete_list.compact)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
File.open(File.join(destination, "REVISION"), "w") { |f| f.puts(revision) }
|
100
|
+
|
101
|
+
logger.trace "compressing #{destination} to #{filename}"
|
102
|
+
Dir.chdir(tmpdir) { system(compress(File.basename(destination), File.basename(filename)).join(" ")) }
|
103
|
+
|
104
|
+
distribute!
|
105
|
+
ensure
|
106
|
+
FileUtils.rm filename rescue nil
|
107
|
+
FileUtils.rm_rf destination rescue nil
|
108
|
+
end
|
109
|
+
|
110
|
+
def check!
|
111
|
+
super.check do |d|
|
112
|
+
d.local.command(source.local.command) if source.local.command
|
113
|
+
d.local.command(compress(nil, nil).first)
|
114
|
+
d.remote.command(decompress(nil).first)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns the location of the local copy cache, if the strategy should
|
119
|
+
# use a local cache + copy instead of a new checkout/export every
|
120
|
+
# time. Returns +nil+ unless :copy_cache has been set. If :copy_cache
|
121
|
+
# is +true+, a default cache location will be returned.
|
122
|
+
def copy_cache
|
123
|
+
@copy_cache ||= configuration[:copy_cache] == true ?
|
124
|
+
File.join(Dir.tmpdir, configuration[:application]) :
|
125
|
+
configuration[:copy_cache]
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
# Specify patterns to exclude from the copy. This is only valid
|
131
|
+
# when using a local cache.
|
132
|
+
def copy_exclude
|
133
|
+
@copy_exclude ||= Array(configuration.fetch(:copy_exclude, []))
|
134
|
+
end
|
135
|
+
|
136
|
+
# Returns the basename of the release_path, which will be used to
|
137
|
+
# name the local copy and archive file.
|
138
|
+
def destination
|
139
|
+
@destination ||= File.join(tmpdir, File.basename(configuration[:release_path]))
|
140
|
+
end
|
141
|
+
|
142
|
+
# Returns the value of the :copy_strategy variable, defaulting to
|
143
|
+
# :checkout if it has not been set.
|
144
|
+
def copy_strategy
|
145
|
+
@copy_strategy ||= configuration.fetch(:copy_strategy, :checkout)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Should return the command(s) necessary to obtain the source code
|
149
|
+
# locally.
|
150
|
+
def command
|
151
|
+
@command ||= case copy_strategy
|
152
|
+
when :checkout
|
153
|
+
source.checkout(revision, destination)
|
154
|
+
when :export
|
155
|
+
source.export(revision, destination)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Returns the name of the file that the source code will be
|
160
|
+
# compressed to.
|
161
|
+
def filename
|
162
|
+
@filename ||= File.join(tmpdir, "#{File.basename(destination)}.#{compression.extension}")
|
163
|
+
end
|
164
|
+
|
165
|
+
# The directory to which the copy should be checked out
|
166
|
+
def tmpdir
|
167
|
+
@tmpdir ||= configuration[:copy_dir] || Dir.tmpdir
|
168
|
+
end
|
169
|
+
|
170
|
+
# The directory on the remote server to which the archive should be
|
171
|
+
# copied
|
172
|
+
def remote_dir
|
173
|
+
@remote_dir ||= configuration[:copy_remote_dir] || "/tmp"
|
174
|
+
end
|
175
|
+
|
176
|
+
# The location on the remote server where the file should be
|
177
|
+
# temporarily stored.
|
178
|
+
def remote_filename
|
179
|
+
@remote_filename ||= File.join(remote_dir, File.basename(filename))
|
180
|
+
end
|
181
|
+
|
182
|
+
# A struct for representing the specifics of a compression type.
|
183
|
+
# Commands are arrays, where the first element is the utility to be
|
184
|
+
# used to perform the compression or decompression.
|
185
|
+
Compression = Struct.new(:extension, :compress_command, :decompress_command)
|
186
|
+
|
187
|
+
# The compression method to use, defaults to :gzip.
|
188
|
+
def compression
|
189
|
+
remote_tar = configuration[:copy_remote_tar] || 'tar'
|
190
|
+
local_tar = configuration[:copy_local_tar] || 'tar'
|
191
|
+
|
192
|
+
type = configuration[:copy_compression] || :gzip
|
193
|
+
case type
|
194
|
+
when :gzip, :gz then Compression.new("tar.gz", [local_tar, 'chzf'], [remote_tar, 'xzf'])
|
195
|
+
when :bzip2, :bz2 then Compression.new("tar.bz2", [local_tar, 'chjf'], [remote_tar, 'xjf'])
|
196
|
+
when :zip then Compression.new("zip", %w(zip -qr), %w(unzip -q))
|
197
|
+
else raise ArgumentError, "invalid compression type #{type.inspect}"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
# Returns the command necessary to compress the given directory
|
202
|
+
# into the given file.
|
203
|
+
def compress(directory, file)
|
204
|
+
compression.compress_command + [file, directory]
|
205
|
+
end
|
206
|
+
|
207
|
+
# Returns the command necessary to decompress the given file,
|
208
|
+
# relative to the current working directory. It must also
|
209
|
+
# preserve the directory structure in the file.
|
210
|
+
def decompress(file)
|
211
|
+
compression.decompress_command + [file]
|
212
|
+
end
|
213
|
+
|
214
|
+
# Distributes the file to the remote servers
|
215
|
+
def distribute!
|
216
|
+
upload(filename, remote_filename)
|
217
|
+
run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/strategy/remote'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Deploy
|
5
|
+
module Strategy
|
6
|
+
|
7
|
+
# Implements the deployment strategy which does an SCM export on each
|
8
|
+
# target host.
|
9
|
+
class Export < Remote
|
10
|
+
protected
|
11
|
+
|
12
|
+
# Returns the SCM's export command for the revision to deploy.
|
13
|
+
def command
|
14
|
+
@command ||= source.export(revision, configuration[:release_path])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/strategy/base'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Deploy
|
5
|
+
module Strategy
|
6
|
+
|
7
|
+
# An abstract superclass, which forms the base for all deployment
|
8
|
+
# strategies which work by grabbing the code from the repository directly
|
9
|
+
# from remote host. This includes deploying by checkout (the default),
|
10
|
+
# and deploying by export.
|
11
|
+
class Remote < Base
|
12
|
+
# Executes the SCM command for this strategy and writes the REVISION
|
13
|
+
# mark file to each host.
|
14
|
+
def deploy!
|
15
|
+
scm_run "#{command} && #{mark}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def check!
|
19
|
+
super.check do |d|
|
20
|
+
d.remote.command(source.command)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
# Runs the given command, filtering output back through the
|
27
|
+
# #handle_data filter of the SCM implementation.
|
28
|
+
def scm_run(command)
|
29
|
+
run(command) do |ch,stream,text|
|
30
|
+
ch[:state] ||= { :channel => ch }
|
31
|
+
output = source.handle_data(ch[:state], stream, text)
|
32
|
+
ch.send_data(output) if output
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# An abstract method which must be overridden in subclasses, to
|
37
|
+
# return the actual SCM command(s) which must be executed on each
|
38
|
+
# target host in order to perform the deployment.
|
39
|
+
def command
|
40
|
+
raise NotImplementedError, "`command' is not implemented by #{self.class.name}"
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns the command which will write the identifier of the
|
44
|
+
# revision being deployed to the REVISION file on each host.
|
45
|
+
def mark
|
46
|
+
"(echo #{revision} > #{configuration[:release_path]}/REVISION)"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/strategy/remote'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Deploy
|
5
|
+
module Strategy
|
6
|
+
|
7
|
+
# Implements the deployment strategy that keeps a cached checkout of
|
8
|
+
# the source code on each remote server. Each deploy simply updates the
|
9
|
+
# cached checkout, and then does a copy from the cached copy to the
|
10
|
+
# final deployment location.
|
11
|
+
class RemoteCache < Remote
|
12
|
+
# Executes the SCM command for this strategy and writes the REVISION
|
13
|
+
# mark file to each host.
|
14
|
+
def deploy!
|
15
|
+
update_repository_cache
|
16
|
+
copy_repository_cache
|
17
|
+
end
|
18
|
+
|
19
|
+
def check!
|
20
|
+
super.check do |d|
|
21
|
+
d.remote.command("rsync") unless copy_exclude.empty?
|
22
|
+
d.remote.writable(shared_path)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def repository_cache
|
29
|
+
File.join(shared_path, configuration[:repository_cache] || "cached-copy")
|
30
|
+
end
|
31
|
+
|
32
|
+
def update_repository_cache
|
33
|
+
logger.trace "updating the cached checkout on all servers"
|
34
|
+
command = "if [ -d #{repository_cache} ]; then " +
|
35
|
+
"#{source.sync(revision, repository_cache)}; " +
|
36
|
+
"else #{source.checkout(revision, repository_cache)}; fi"
|
37
|
+
scm_run(command)
|
38
|
+
end
|
39
|
+
|
40
|
+
def copy_repository_cache
|
41
|
+
logger.trace "copying the cached version to #{configuration[:release_path]}"
|
42
|
+
if copy_exclude.empty?
|
43
|
+
run "cp -RPp #{repository_cache} #{configuration[:release_path]} && #{mark}"
|
44
|
+
else
|
45
|
+
exclusions = copy_exclude.map { |e| "--exclude=\"#{e}\"" }.join(' ')
|
46
|
+
run "rsync -lrpt #{exclusions} #{repository_cache}/* #{configuration[:release_path]} && #{mark}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def copy_exclude
|
51
|
+
@copy_exclude ||= Array(configuration.fetch(:copy_exclude, []))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|