Class: Broadside::EcsDeploy

Inherits:
Deploy
  • Object
show all
Defined in:
lib/broadside/deploy/ecs.rb

Instance Attribute Summary

Attributes inherited from Deploy

#deploy_config

Instance Method Summary collapse

Methods inherited from Deploy

#full, #short

Methods included from Utils

#config, #debug, #error, #exception, #info, #warn

Constructor Details

#initialize(opts) ⇒ EcsDeploy

Returns a new instance of EcsDeploy.



9
10
11
12
13
# File 'lib/broadside/deploy/ecs.rb', line 9

def initialize(opts)
  super(opts)
  config.ecs.verify(:cluster, :poll_frequency)
  check_service_existence
end

Instance Method Details

#bashObject



114
115
116
117
118
119
120
121
122
123
# File 'lib/broadside/deploy/ecs.rb', line 114

def bash
  super do
    ip = get_running_instance_ip_at_index!(@deploy_config.instance)
    debug "Running bash for running container at ip #{ip}..."
    search_pattern = Shellwords.shellescape(family)
    cmd = "docker exec -i -t `docker ps -n 1 --quiet --filter name=#{search_pattern}` bash"
    bash_cmd = gen_ssh_cmd(ip, tty: true) + " '#{cmd}'"
    exec bash_cmd
  end
end

#deployObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/broadside/deploy/ecs.rb', line 15

def deploy
  super do
    update_task

    begin
      update_service
    rescue SignalException::Interrupt
      error 'Caught interrupt signal, rolling back...'
      rollback(1)
      error 'Deployment did not finish successfully.'
      abort
    rescue StandardError => e
      error e.inspect, "\n", e.backtrace.join("\n")
      error 'Deploy failed! Rolling back...'
      rollback(1)
      error 'Deployment did not finish successfully.'
      abort
    end
  end
end

#logtailObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/broadside/deploy/ecs.rb', line 95

def logtail
  super do
    ip = get_running_instance_ip_at_index!(@deploy_config.instance)
    debug "Tailing logs for running container at ip #{ip}..."
    search_pattern = Shellwords.shellescape(family)
    cmd = "docker logs -f --tail=10 `docker ps -n 1 --quiet --filter name=#{search_pattern}`"
    tail_cmd = gen_ssh_cmd(ip) + " '#{cmd}'"
    exec tail_cmd
  end
end

#rollback(count = @deploy_config.rollback) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/broadside/deploy/ecs.rb', line 36

def rollback(count = @deploy_config.rollback)
  super do
    begin
      deregister_tasks(count)
      update_service
    rescue StandardError => e
      error 'Rollback failed to complete!'
      raise e
    end
  end
end

#runObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/broadside/deploy/ecs.rb', line 54

def run
  super do
    update_task

    begin
      run_command(@deploy_config.command)
    ensure
      deregister_tasks(1)
    end
  end
end

#run_predeployObject

runs before deploy commands using the latest task definition



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/broadside/deploy/ecs.rb', line 67

def run_predeploy
  super do
    update_task

    begin
      @deploy_config.predeploy_commands.each do |command|
        run_command(command)
      end
    ensure
      deregister_tasks(1)
    end
  end
end

#scaleObject



48
49
50
51
52
# File 'lib/broadside/deploy/ecs.rb', line 48

def scale
  super do
    update_service
  end
end

#sshObject



106
107
108
109
110
111
112
# File 'lib/broadside/deploy/ecs.rb', line 106

def ssh
  super do
    ip = get_running_instance_ip_at_index!(@deploy_config.instance)
    debug "Establishing an SSH connection to ip #{ip}..."
    exec gen_ssh_cmd(ip)
  end
end

#statusObject



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/broadside/deploy/ecs.rb', line 81

def status
  super do
    td = get_latest_task_def
    ips = get_running_instance_ips
    info "\n---------------",
      "\nDeployed task definition information:\n",
      Rainbow(PP.pp(td, '')).blue,
      "\nPrivate ips of instances running containers:\n",
      Rainbow(ips.join(' ')).blue,
      "\n\nssh command:\n#{Rainbow(gen_ssh_cmd(ips.first)).cyan}",
      "\n---------------\n"
  end
end