-
Notifications
You must be signed in to change notification settings - Fork 1
/
Capfile
123 lines (101 loc) · 3.35 KB
/
Capfile
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
117
118
119
120
121
122
role :main, "[email protected]"
namespace :release do
set :app, "catabuzz"
set :app_dir, "~/Sites/#{app}_app"
set :source, "~/Sites/#{app}_app/source"
set :releases, "~/Sites/#{app}_app/releases"
set :deploy_configs, "~/Sites/#{app}_app/deploy_configs"
# skip the question of which tag to deploy. just use the latest instead
set :use_latest, false
def parse_branch_list(data)
# find something that looks like this:
#* master
re = /\*\s(.*)/
data.each_line do |l|
md = re.match(l)
return md[1] if md
end
return nil
end
def choose_tag_to_release
return available_tags[:latest] if use_latest
puts "1. " + available_tags[:latest]
puts "----------"
available_tags[:all].each_with_index { |tag, i| puts "#{i + 2}. #{tag}"}
answer = Capistrano::CLI.ui.ask("Which tag to release: ", Integer) do |question|
question.default = 1
question.above = 0
question.below = available_tags[:all].size + 2
end
return available_tags[:latest] if answer == 1
return available_tags[:all][answer - 2]
end
task :get_checkedout_branch do
run("cd #{source} && git branch") do |ssh, mode, data|
set :checkedout_branch, parse_branch_list(data) if mode == :out
end
end
task :checkout_deployment_branch do
run("cd #{source} && git checkout deployment")
end
task :pull_source do
get_checkedout_branch
checkout_deployment_branch if checkedout_branch != "deployment"
run("cd #{source} && git pull")
end
# Returns the latest and all release tags
task :get_available_tags do
# find latests tag
latest = ""
run("cd #{source} && git describe --tags --abbrev=0 HEAD") do |ssh, mode, data|
latest = data.strip if mode == :out
end
# find all tags
all = []
run("cd #{source} && git tag") do |ssh, mode, data|
data.each_line { |l| all << l.strip} if mode == :out
end
set :available_tags, {:latest => latest, :all => all}
end
set(:selected_tag) do
pull_source
get_available_tags
choose_tag_to_release
end
desc "Select a tag and create a folder containing the tagged release"
task :download do
tag = selected_tag
run "cd #{releases} && rm -rf #{tag} && mkdir -p #{tag}"
run "cd #{source} && git archive #{tag} | (cd #{releases}/#{tag} && tar -xf -)"
end
desc "Copy mailer and db confings. Add REVISION and VERSION files"
task :config do
tag = selected_tag
run "cp -f #{deploy_configs}/*.yml #{releases}/#{tag}/config"
run "echo #{tag} > #{releases}/#{tag}/REVISION"
version = tag
if md= /\d+(\.\d+)*\w*$/.match(tag)
version = md[0].inspect
end
run "echo #{version} > #{releases}/#{tag}/VERSION"
end
desc "Updated Rails passenger symlinks to point to the new release"
task :link do
tag = selected_tag
run "cd #{app_dir} && ln -vnsf releases/#{tag}/public catabuzz_public"
run "cd #{app_dir} && ln -vnsf releases/#{tag} current_release"
run "cd #{releases} && ln -vnsf #{tag} current"
end
desc "Restart the release"
task :restart do
tag = selected_tag
run "cd #{releases}/#{tag} && mkdir -p tmp && touch tmp/restart.txt"
end
desc "Do full deployment of the selected tag from git 'deployment' branch. Use use_latest=1 to skip the tag selection dialog."
task :default do
download
config
link
restart
end
end