Class: Centurion::DockerViaCli

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/centurion/docker_via_cli.rb

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #info, #warn

Constructor Details

#initialize(hostname, port, docker_path, tls_args = {}) ⇒ DockerViaCli

Returns a new instance of DockerViaCli.



10
11
12
13
14
# File 'lib/centurion/docker_via_cli.rb', line 10

def initialize(hostname, port, docker_path, tls_args = {})
  @docker_host = "tcp://#{hostname}:#{port}"
  @docker_path = docker_path
  @tls_args = tls_args
end

Instance Method Details

#attach(container_id) ⇒ Object



26
27
28
# File 'lib/centurion/docker_via_cli.rb', line 26

def attach(container_id)
  Centurion::Shell.echo(build_command(:attach, container_id))
end

#exec(container_id, commandline) ⇒ Object



30
31
32
# File 'lib/centurion/docker_via_cli.rb', line 30

def exec(container_id, commandline)
  Centurion::Shell.echo(build_command(:exec, "#{container_id} #{commandline}"))
end

#exec_it(container_id, commandline) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/centurion/docker_via_cli.rb', line 34

def exec_it(container_id, commandline)
  # the "or true" on the command is to prevent an exception from Shell.validate_status
  # because docker exec returns the same exit code as the latest command executed on
  # the shell, which causes an exception to be raised if the latest comand executed
  # was unsuccessful when you exit the shell.
  Centurion::Shell.echo(build_command(:exec, "-it #{container_id} #{commandline} || true"))
end

#pull(image, tag = 'latest') ⇒ Object



16
17
18
19
# File 'lib/centurion/docker_via_cli.rb', line 16

def pull(image, tag='latest')
  info 'Using CLI to pull'
  Centurion::Shell.echo(build_command(:pull, "#{image}:#{tag}"))
end

#tail(container_id) ⇒ Object



21
22
23
24
# File 'lib/centurion/docker_via_cli.rb', line 21

def tail(container_id)
  info "Tailing the logs on #{container_id}"
  Centurion::Shell.echo(build_command(:logs, container_id))
end