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.



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

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)


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

def local_cache_exists?
  File.exist?(local_cache_path)
end

#local_cache_pathObject



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

def local_cache_path
  File.expand_path(local_cache)
end

#local_cache_valid?Boolean

Returns:

  • (Boolean)


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

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



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

def remove_cache_if_repository_url_changed
  remove_local_cache if repository_url_changed?
end

#remove_local_cacheObject



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

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



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

def repository_cache_path
  File.join(shared_path, repository_cache)
end

#repository_urlObject



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

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

#repository_url_changed?Boolean

Returns:

  • (Boolean)


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

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)}' #{local_cache_path}/ #{rsync_host(server)}:#{repository_cache_path}/"
end

#rsync_host(server) ⇒ Object



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

def rsync_host(server)
  configuration[:user] ? "#{configuration[:user]}@#{server.host}" : server.host
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) or raise "Dynport fixed it!"
  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