Method: Ufo::CLI::Exec#run

Defined in:
lib/ufo/cli/exec.rb

#runObject



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
# File 'lib/ufo/cli/exec.rb', line 3

def run
  check_install!
  stack = info.stack
  unless stack
    logger.error "Stack not found: #{@stack_name}".color(:red)
    exit 1
  end

  service = info.service
  unless service # brand new deploy
    logger.error "ECS Service not yet available".color(:red)
    logger.info "Try again in a little bit"
    exit 1
  end

  running = service_tasks.select do |task|
    task.last_status == "RUNNING"
  end
  if running.empty?
    logger.info "No running tasks found to exec into"
    return
  end

  tasks = running.sort_by { |t| t.started_at }
  task = tasks.last # most recent

  task_name = task.task_arn.split('/').last
  execute_command(
    cluster: @cluster,
    task: task_name,
    container: container(task), # only required if multiple containers in a task
    interactive: true,
    command: command
  )
end