Class: Capistrano::BundleRsync::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/bundle_rsync/config.rb

Class Method Summary collapse

Class Method Details

.build_ssh_command(host) ⇒ Object

Build ssh command options for rsync

First, search available user and keys configurations for each role:

role :app, ['hostname'], {
  user: username,
  keys: File.expand_path('~/.ssh/id_rsa'),
  port: 22,
}

If not available, look :bundle_rsync_ssh_options:

set :bundle_rsync_ssh_options {
  user: username,
  keys: [File.expand_path('~/.ssh/id_rsa')],
  port: 22,
}

If :bundle_rsync_ssh_options are not available also, look :ssh_options finally:

set :ssh_options {
  user: username,
  keys: [File.expand_path('~/.ssh/id_rsa')],
  port: 22,
}

keys can be a string or an array. NOTE: :password is not supported.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/capistrano/bundle_rsync/config.rb', line 56

def self.build_ssh_command(host)
  user_opt, key_opt, port_opt = "", "", ""
  ssh_options = fetch(:bundle_rsync_ssh_options) || fetch(:ssh_options)
  if user = host.user || ssh_options[:user]
    user_opt = " -l #{user}"
  end
  if keys = (host.keys.empty? ? ssh_options[:keys] : host.keys)
    keys = keys.is_a?(Array) ? keys : [keys]
    key_opt = keys.map {|key| " -i #{key}" }.join("")
  end
  if port = host.port || ssh_options[:port]
    port_opt = " -p #{port}"
  end
  "ssh#{user_opt}#{key_opt}#{port_opt}"
end

.config_filesObject



23
24
25
26
# File 'lib/capistrano/bundle_rsync/config.rb', line 23

def self.config_files
  return nil unless config_files = fetch(:bundle_rsync_config_files)
  config_files.is_a?(Array) ? config_files : [config_files]
end

.local_base_pathObject



3
4
5
# File 'lib/capistrano/bundle_rsync/config.rb', line 3

def self.local_base_path
  @local_base_path ||= fetch(:bundle_rsync_local_base_path) || "#{Dir::pwd}/.local_repo"
end

.local_bin_pathObject



19
20
21
# File 'lib/capistrano/bundle_rsync/config.rb', line 19

def self.local_bin_path
  @local_bin_path ||= fetch(:bundle_rsync_local_bin_path) || "#{local_base_path}/bin"
end

.local_bundle_pathObject



15
16
17
# File 'lib/capistrano/bundle_rsync/config.rb', line 15

def self.local_bundle_path
  @local_bundle_path ||= fetch(:bundle_rsync_local_bundle_path) || "#{local_base_path}/bundle"
end

.local_release_pathObject



11
12
13
# File 'lib/capistrano/bundle_rsync/config.rb', line 11

def self.local_release_path
  @local_release_path ||= fetch(:bundle_rsync_local_release_path) || "#{local_base_path}/release_#{Time.now.to_i}"
end

.local_repo_pathObject



7
8
9
# File 'lib/capistrano/bundle_rsync/config.rb', line 7

def self.local_repo_path
  @local_repo_path ||= fetch(:bundle_rsync_local_repo_path) || "#{local_base_path}/repo"
end

.max_parallels(hosts) ⇒ Object

Fetch the :bundle_rsync_max_parallels, where the default is the number of hosts



74
75
76
# File 'lib/capistrano/bundle_rsync/config.rb', line 74

def self.max_parallels(hosts)
  fetch(:bundle_rsync_max_parallels) || hosts.size
end

.rsync_optionsObject



78
79
80
81
# File 'lib/capistrano/bundle_rsync/config.rb', line 78

def self.rsync_options
  bwlimit = fetch(:bundle_rsync_rsync_bwlimit) ? " --bwlimit #{fetch(:bundle_rsync_rsync_bwlimit)}" : ""
  fetch(:bundle_rsync_rsync_options) || "-az --delete#{bwlimit}"
end