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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/capistrano/rsync.rb', line 17
def define_tasks
namespace :rsync do
desc " Copy application source code from (remote) cache to release path.\n\n If a :rsync_deploy_build_path is set, only that relative path will \\\n be copied to the release path.\n DESC\n task create_release: :update_remote_cache do\n on release_roles :all do\n execute :rsync, '--archive', \"\#{fetch(:deploy_to)}/\#{fetch(:rsync_remote_cache)}/\#{fetch(:rsync_deploy_build_path)}\", \"\#{release_path}/\"\n end\n end\n\n desc <<-DESC\n Update remote cache of application source code.\n\n This will be rsynced to :rsync_remote_cache, using rsync options set in \\\n :rsync_options\n DESC\n task update_remote_cache: :update_local_cache do\n on release_roles :all do |role|\n host_spec = role.hostname\n host_spec = \"\#{role.user}@\#{host_spec}\" if role.user\n run_locally do\n execute :rsync, *fetch(:rsync_options), \"\#{fetch(:rsync_local_cache)}/\", \"\#{host_spec}:\#{fetch(:deploy_to)}/\#{fetch(:rsync_remote_cache)}/\"\n end\n end\n end\n\n desc <<-DESC\n Update local cache of application source code.\n\n This will be checked out to :rsync_local_cache.\n DESC\n task :update_local_cache do\n run_locally do\n unless File.exist?(\"\#{fetch(:rsync_local_cache)}/.git\")\n FileUtils.mkdir_p(fetch(:rsync_local_cache))\n execute :git, :clone, '--quiet', repo_url, fetch(:rsync_local_cache)\n end\n within fetch(:rsync_local_cache) do\n execute :git, :fetch, '--quiet', '--all', '--prune'\n execute :git, :checkout, fetch(:branch)\n execute :git, :reset, '--quiet', '--hard', \"origin/\#{fetch(:branch)}\"\n end\n end\n end\n\n desc <<-DESC\n Determine version of code that rsync will deploy.\n\n By default, this is the latest version of the code on branch :branch.\n DESC\n task :set_current_revision do\n run_locally do\n within fetch(:rsync_local_cache) do\n set :current_revision, capture(:git, \"rev-list --max-count=1 \#{fetch(:branch)}\")\n end\n end\n end\n end\nend\n"
|