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
|
# File 'lib/broadside/ecs/ecs_deploy.rb', line 75
def run_commands(commands, options = {})
return if commands.nil? || commands.empty?
update_task_revision
begin
commands.each do |command|
command_name = "'#{command.join(' ')}'"
task_arn = EcsManager.run_task(cluster, family, command, options).tasks[0].task_arn
info "Launched #{command_name} task #{task_arn}, waiting for completion..."
EcsManager.ecs.wait_until(:tasks_stopped, cluster: cluster, tasks: [task_arn]) do |w|
w.max_attempts = nil
w.delay = Broadside.config.aws.ecs_poll_frequency
w.before_attempt do |attempt|
info "Attempt #{attempt}: waiting for #{command_name} to complete..."
end
end
exit_status = EcsManager.get_task_exit_status(cluster, task_arn, family)
raise EcsError, "#{command_name} failed to start:\n'#{exit_status[:reason]}'" if exit_status[:exit_code].nil?
raise EcsError, "#{command_name} nonzero exit code: #{exit_status[:exit_code]}!" unless exit_status[:exit_code].zero?
info "#{command_name} task container logs:\n#{get_container_logs(task_arn)}"
info "#{command_name} task #{task_arn} complete"
end
ensure
EcsManager.deregister_last_n_tasks_definitions(family, 1)
end
end
|