Module: EcsCmd::Exec

Defined in:
lib/ecs_cmd/exec.rb

Class Method Summary collapse

Class Method Details

.docker_ps_task(task_family) ⇒ Object

docker ps command to get container id



41
42
43
# File 'lib/ecs_cmd/exec.rb', line 41

def docker_ps_task(task_family)
  "docker ps -n 1 -q --filter name=#{Shellwords.shellescape(task_family)}"
end

.execute(task_family, ip, command, user = 'root') ⇒ Object

used to run arbitrary command inside a container



20
21
22
23
24
25
26
27
# File 'lib/ecs_cmd/exec.rb', line 20

def execute(task_family, ip, command, user = 'root')
  cmd = "docker exec -i -t -u #{user} `#{docker_ps_task(task_family)}` #{command}"
  Open3.popen2e(ssh_cmd(ip) + " '#{cmd}' ") do |stdin, stdout, stderr, status_thread|
    stdout.each_line do |line|
      puts line
    end
  end
end

.logs(task_family, ip, lines) ⇒ Object



35
36
37
38
# File 'lib/ecs_cmd/exec.rb', line 35

def logs(task_family, ip, lines)
  cmd = "docker logs -f --tail=#{lines} `#{docker_ps_task(task_family)}`"
  exec(ssh_cmd(ip) + " '#{cmd}' ")
end

.shell(task_family, ip, shell = 'bash', user = 'root') ⇒ Object

used to open a shell within a container?



30
31
32
33
# File 'lib/ecs_cmd/exec.rb', line 30

def shell(task_family, ip, shell = 'bash', user = 'root')
  cmd = "docker exec -i -t -u #{user} `#{docker_ps_task(task_family)}` #{shell}"
  exec(ssh_cmd(ip) + " '#{cmd}' ")
end

.ssh(ip) ⇒ Object



15
16
17
# File 'lib/ecs_cmd/exec.rb', line 15

def ssh(ip)
  exec(ssh_cmd(ip))
end

.ssh_cmd(ip) ⇒ Object

move this to a config



10
11
12
13
# File 'lib/ecs_cmd/exec.rb', line 10

def ssh_cmd(ip)
  cmd = 'ssh -tt -o StrictHostKeyChecking=no '
  cmd << ip.to_s
end