Class: Capistrano::Deploy::Strategy::RsyncRemoteCache
- Inherits:
-
Remote
- Object
- Remote
- Capistrano::Deploy::Strategy::RsyncRemoteCache
show all
- Defined in:
- lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb
Defined Under Namespace
Classes: InvalidCacheError, LocalCacheUpdateFailedError, RsyncFailedError
Constant Summary
collapse
- INFO_COMMANDS =
{
:subversion => "svn info . | sed -n \'s/URL: //p\'",
:git => "git config remote.origin.url",
:mercurial => "hg showconfig paths.default",
:bzr => "bzr info | grep parent | sed \'s/^.*parent branch: //\'"
}
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.default_attribute(attribute, default_value) ⇒ Object
14
15
16
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 14
def self.default_attribute(attribute, default_value)
define_method(attribute) { configuration[attribute] || default_value }
end
|
Instance Method Details
#check! ⇒ Object
Defines commands that should be checked for by deploy:check. These include the SCM command on the local end, and rsync on both ends. Note that the SCM command is not needed on the remote end.
114
115
116
117
118
119
120
121
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 114
def check!
super.check do |check|
check.local.command(source.command)
check.local.command('rsync')
check.local.command('sshpass')
check.remote.command('rsync')
end
end
|
#copy_remote_cache ⇒ Object
58
59
60
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 58
def copy_remote_cache
run("rsync -azx #{repository_cache_path}/ #{configuration[:release_path]}/")
end
|
#deploy! ⇒ Object
32
33
34
35
36
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 32
def deploy!
update_local_cache
update_remote_cache
copy_remote_cache
end
|
#local_cache_exists? ⇒ Boolean
103
104
105
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 103
def local_cache_exists?
File.exist?(local_cache_path)
end
|
#local_cache_path ⇒ Object
74
75
76
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 74
def local_cache_path
File.expand_path(local_cache)
end
|
#local_cache_valid? ⇒ Boolean
107
108
109
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 107
def local_cache_valid?
local_cache_exists? && File.directory?(local_cache_path)
end
|
#mark_local_cache ⇒ Object
66
67
68
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 66
def mark_local_cache
File.open(File.join(local_cache_path, 'REVISION'), 'w') {|f| f << revision }
end
|
#remove_local_cache ⇒ Object
90
91
92
93
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 90
def remove_local_cache
logger.trace "repository has changed; removing old local cache from #{local_cache_path}"
FileUtils.rm_rf(local_cache_path)
end
|
#remove_local_cache_if_repository_url_changed ⇒ Object
95
96
97
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 95
def remove_local_cache_if_repository_url_changed
remove_local_cache if repository_url_changed?
end
|
#repository_cache_path ⇒ Object
78
79
80
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 78
def repository_cache_path
File.join(shared_path, repository_cache)
end
|
#repository_url ⇒ Object
82
83
84
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 82
def repository_url
`cd #{local_cache_path} && #{INFO_COMMANDS[configuration[:scm]]}`.strip
end
|
#repository_url_changed? ⇒ Boolean
86
87
88
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 86
def repository_url_changed?
repository_url != configuration[:repository]
end
|
#rsync_command_for(server) ⇒ Object
62
63
64
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 62
def rsync_command_for(server)
"sshpass -p '#{password}' rsync #{rsync_options} --rsh='ssh -p #{ssh_port(server)} #{rsync_ssh_options}' '#{local_cache_path}/' #{rsync_host(server)}:#{repository_cache_path}/"
end
|
#rsync_host(server) ⇒ Object
99
100
101
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 99
def rsync_host(server)
configuration[:user] ? "#{configuration[:user]}@#{server.host}" : server.host
end
|
#ssh_port(server) ⇒ Object
70
71
72
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 70
def ssh_port(server)
server.port || ssh_options[:port] || 22
end
|
#system!(command) ⇒ Object
38
39
40
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 38
def system!(command)
system(command) or raise RuntimeError.new("Command exit with non zero status: #{command}")
end
|
#update_local_cache ⇒ Object
42
43
44
45
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 42
def update_local_cache
system!(command)
mark_local_cache
end
|
#update_remote_cache ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/capistrano/recipes/deploy/strategy/rsync_remote_cache.rb', line 47
def update_remote_cache
finder_options = {:except => { :no_release => true }}
if rsync_in_parallel
Parallel.map(find_servers(finder_options), :in_processes => rsync_concurrency) do |s|
system!(rsync_command_for(s))
end.all?
else
find_servers(finder_options).each {|s| system(rsync_command_for(s)) }
end
end
|