Class: Capistrano::Deploy::Strategy::RsyncWithRemoteCache

Inherits:
Remote
  • Object
show all
Defined in:
lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb

Defined Under Namespace

Classes: InvalidCacheError

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



11
12
13
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 11

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.



106
107
108
109
110
111
112
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 106

def check!
  super.check do |check|
    check.local.command(source.command)
    check.local.command('rsync')
    check.remote.command('rsync')
  end
end

#copy_remote_cacheObject



42
43
44
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 42

def copy_remote_cache
  run("rsync -a --delete #{repository_cache_path}/ #{configuration[:release_path]}/")
end

#deploy!Object



26
27
28
29
30
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 26

def deploy!
  update_local_cache
  update_remote_cache
  copy_remote_cache
end

#local_cache_exists?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 95

def local_cache_exists?
  File.exist?(local_cache_path)
end

#local_cache_pathObject



66
67
68
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 66

def local_cache_path
  File.expand_path(local_cache)
end

#local_cache_valid?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 99

def local_cache_valid?
  local_cache_exists? && File.directory?(local_cache_path)
end

#mark_local_cacheObject



50
51
52
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 50

def mark_local_cache
  File.open(File.join(local_cache_path, 'REVISION'), 'w') {|f| f << revision }
end

#remove_cache_if_repository_url_changedObject



87
88
89
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 87

def remove_cache_if_repository_url_changed
  remove_local_cache if repository_url_changed?
end

#remove_local_cacheObject



82
83
84
85
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 82

def remove_local_cache
  logger.trace "repository has changed; removing old local cache from #{local_cache_path}"
  FileUtils.rm_rf(local_cache_path)
end

#repository_cache_pathObject



70
71
72
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 70

def repository_cache_path
  File.join(shared_path, repository_cache)
end

#repository_urlObject



74
75
76
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 74

def repository_url
  `cd #{local_cache_path} && #{INFO_COMMANDS[configuration[:scm]]}`.strip
end

#repository_url_changed?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 78

def repository_url_changed?
  repository_url != configuration[:repository]
end

#rsync_command_for(server) ⇒ Object



46
47
48
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 46

def rsync_command_for(server)
  "rsync #{rsync_options} --rsh='ssh -p #{ssh_port(server)} #{ssh_key} #{ssh_config_file}' '#{local_cache_path}/' #{rsync_host(server)}:#{repository_cache_path}/"
end

#rsync_host(server) ⇒ Object



91
92
93
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 91

def rsync_host(server)
  configuration[:user] ? "#{configuration[:user]}@#{server.host}" : server.host
end

#ssh_config_fileObject



62
63
64
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 62

def ssh_config_file
  ssh_options[:config] ? "-F #{ssh_options[:config]}" : ""
end

#ssh_keyObject



58
59
60
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 58

def ssh_key
  ssh_options[:keys] ? "-i #{ssh_options[:keys]}" : ""
end

#ssh_port(server) ⇒ Object



54
55
56
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 54

def ssh_port(server)
  server.port || ssh_options[:port] || 22
end

#update_local_cacheObject



32
33
34
35
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 32

def update_local_cache
  system(command)
  mark_local_cache
end

#update_remote_cacheObject



37
38
39
40
# File 'lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb', line 37

def update_remote_cache
  finder_options = {:except => { :no_release => true }}
  find_servers(finder_options).each {|s| system(rsync_command_for(s)) }
end