17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/hocho/drivers/ssh_base.rb', line 17
def deploy(deploy_dir: nil, shm_prefix: [])
@host_basedir = deploy_dir if deploy_dir
shm_prefix = [*shm_prefix]
ssh_cmd = ['ssh', *host.openssh_config.flat_map { |l| ['-o', "\"#{l}\""] }].join(' ')
shm_exclude = shm_prefix.map{ |_| "--exclude=#{_}" }
compress = host.compress? ? ['-z'] : []
rsync_cmd = [*%w(rsync -a --copy-links --copy-unsafe-links --delete --exclude=.git), *compress, *shm_exclude, '--rsh', ssh_cmd, '.', "#{host.hostname}:#{host_basedir}"]
puts "=> $ #{rsync_cmd.shelljoin}"
system(*rsync_cmd, chdir: base_dir) or raise 'failed to rsync'
unless shm_prefix.empty?
shm_include = shm_prefix.map{ |_| "--include=#{_.sub(%r{/\z},'')}/***" }
rsync_cmd = [*%w(rsync -a --copy-links --copy-unsafe-links --delete), *compress, *shm_include, '--exclude=*', '--rsh', ssh_cmd, '.', "#{host.hostname}:#{host_shm_basedir}"]
puts "=> $ #{rsync_cmd.shelljoin}"
system(*rsync_cmd, chdir: base_dir) or raise 'failed to rsync'
shm_prefix.each do |x|
mkdir = if %r{\A[^/].*\/.+\z} === x
%Q(mkdir -vp "$(basename #{x.shellescape})" &&)
else
nil
end
ssh_run(%Q(cd #{host_basedir} && #{mkdir} ln -sfv #{host_shm_basedir}/#{x.shellescape} ./#{x.sub(%r{/\z},'').shellescape}))
end
end
yield
ensure
if !deploy_dir || !keep_synced_files
cmd = "rm -rf #{host_basedir.shellescape}"
puts "=> #{host.name} $ #{cmd}"
ssh_run(cmd, error: false)
end
end
|