-
Notifications
You must be signed in to change notification settings - Fork 31
/
gitcopy.rake
116 lines (98 loc) · 3.07 KB
/
gitcopy.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
strategy = self
namespace :gitcopy do
set :git_environmental_variables, ->() {
{
git_askpass: "/bin/echo",
git_ssh: "#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh"
}
}
desc 'Generate the git wrapper script, this script guarantees that we can script git without getting an interactive prompt'
task :wrapper do
run_locally do
execute :mkdir, "-p", "#{fetch(:tmp_dir)}/#{fetch(:application)}/"
File.open("#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh", "w") do |file|
file.write ("#!/bin/sh -e\nexec /usr/bin/ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no \"$@\"\n")
end
execute :chmod, "+x", "#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh"
end
end
desc 'Check that the repository is reachable'
task :check => :'gitcopy:wrapper' do
run_locally do
with fetch(:git_environmental_variables) do
strategy.check
end
end
end
desc 'Clone the repo to the cache'
task :clone => :'gitcopy:wrapper' do
local_path = fetch(:local_path)
run_locally do
execute :mkdir, '-p', local_path
within local_path do
with fetch(:git_environmental_variables) do
strategy.clone
end
end
end
end
desc 'Update the repo mirror to reflect the origin state'
task :update => :'gitcopy:clone' do
local_path = fetch(:local_path)
run_locally do
within local_path do
with fetch(:git_environmental_variables) do
strategy.update
end
end
end
end
desc 'Create tarfile'
task :create_tarfile => [:'gitcopy:update', :'gitcopy:set_current_revision'] do
local_path = fetch(:local_path)
run_locally do
within local_path do
with fetch(:git_environmental_variables) do
strategy.release
end
end
end
end
desc 'Copy repo to releases'
task :create_release => :'gitcopy:create_tarfile' do
on release_roles :all do
within deploy_to do
execute :mkdir, '-p', release_path
extract_option = ["--extract"]
extract_option << '--verbose' if fetch(:gitcopy_verbose)
if (tree = fetch(:repo_tree))
tree = tree.slice %r#^/?(.*?)/?$#, 1
components = tree.split("/").size
extract_option.concat ["--strip-components", components]
extract_option.concat ["--file"]
else
extract_option.concat ["--file"]
end
upload! strategy.local_tarfile, strategy.remote_tarfile
execute :tar, *extract_option, strategy.remote_tarfile, '--directory', release_path
execute :rm, strategy.remote_tarfile
end
end
run_locally do
if File.exists? strategy.local_tarfile
execute :rm, strategy.local_tarfile
end
end
end
desc 'Determine the revision that will be deployed'
task :set_current_revision do
local_path = fetch(:local_path)
run_locally do
within local_path do
with fetch(:git_environmental_variables) do
set :current_revision, strategy.fetch_revision
end
end
end
end
end