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
|
# File 'lib/shiprails/ship/task.rb', line 23
def run_command
command_string = args.join ' '
cluster_name = "#{project_name}_#{options['environment']}"
task_name = "#{project_name}_#{options['service']}_#{options['environment']}"
ecs = Aws::ECS::Client.new(region: options['region'])
task_definition_response = ecs.describe_task_definition({task_definition: task_name})
task_definition_arn = task_definition_response.task_definition.task_definition_arn
say "Running `#{command_string}` in #{options['environment']} #{options['service']} (#{options['region']})..."
task_response = ecs.run_task({
cluster: cluster_name,
task_definition: task_definition_arn,
overrides: {
container_overrides: [{
name: options['service'],
command: command_string.split(' ')
}]
}
})
task_arn = task_response.tasks.first.task_arn
resp = ecs.describe_tasks({ cluster: cluster_name, tasks: [task_arn] })
while resp.tasks.first.containers.first.exit_code.nil?
sleep 1
resp = ecs.describe_tasks({ cluster: cluster_name, tasks: [task_arn] })
say "."
end
if resp.tasks.first.containers.first.exit_code > 0
say "Task exited other than 0: #{resp.tasks.first.containers.first.exit_code} (#{task_arn})", :red
else
say "Ran `#{command_string}` in #{options['environment']} #{options['service']} (#{options['region']}).", :green
end
end
|