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
|
# File 'lib/antismoker/deployment.rb', line 5
def self.define_task(context, task_method = :task, opts = {})
if defined?(Capistrano) && context.is_a?(Capistrano::Configuration)
context_name = "capistrano"
role_default = "{:except => {:no_release => true}}"
error_type = ::Capistrano::CommandError
else
context_name = "vlad"
role_default = "[:app]"
error_type = ::Rake::CommandFailedError
end
roles = context.fetch(:antismoker_roles, [:app])
opts[:roles] = roles if roles
context.send :namespace, :antismoker do
send :desc, "Run smoke test."
send task_method, :invoke, opts do
rake_cmd = context.fetch(:rake, "rake")
antismoker_task = context.fetch(:antismoker_task, "antismoker:invoke")
rails_env = context.fetch(:rails_env, "production")
app_path = context.fetch(:latest_release)
if app_path.to_s.empty?
raise error_type.new("Cannot detect current release path - make sure you have deployed at least once.")
end
args = []
args += context.fetch(:antismoker_flags, [])
args << "RAILS_ENV=#{rails_env}"
run_opts = context.fetch(:antismoker_run_options, {})
begin
run "cd #{app_path} && #{rake_cmd} #{args.join(' ')} #{antismoker_task}", run_opts
antismoker_success
rescue
antismoker_failure
abort
ensure
finalize_antismoker
end
end
send task_method, :antismoker_success, opts do
logger.info("It works!")
end
send task_method, :antismoker_failure, opts do
if context.fetch(:antismoker_use_rollback, false)
logger.info("Rolling back application.")
rollback_task = context.fetch(:antismoker_rollback_task, "deploy:rollback")
find_and_execute_task(rollback_task)
end
end
send task_method, :finalize_antismoker, opts do
end
end
end
|