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
|
# File 'lib/fast_git_deploy/recipes/fast_git_deploy/rollback.rb', line 3
def self.load_into(configuration)
configuration.load do
namespace :deploy do
namespace :rollback do
desc "Rolls the app back one revision"
task :code, :except => { :no_release => true } do
current_revision = capture("cat #{version_file}").gsub(/\r?\n?/, "")
previous_revision = nil
revision_log_data = capture("cat #{revision_log}").split(/\r?\n/)
revisions = revision_log_data.map do |entry|
entry.split(" ").last
end
revisions.reverse!
revisions.each_with_index do |revision, index|
if current_revision == revision
previous_revision = revisions[index..revision_log_data.length-1].detect do |rev|
rev != current_revision
end
end
end
if previous_revision
run [
"cd #{current_path}",
"#{scm_command} reset --hard #{previous_revision}"
].join(" && ")
else
raise(Capistrano::Error, "Couldn't find a revision previous to #{current_revision}")
end
end
desc "Rolls back the app one revision, restarts mongrel, and writes the revision to the VERSION file (but not revisions.log)"
task :default do
transaction do
rollback.code
deploy.restart
deploy.set_version_file
end
end
end
end
end
end
|