class Kitchen::Transport::DockerCli::Connection

Public Instance Methods

docker_base() click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 119
def docker_base
  @options[:docker_base]
end
docker_exec_command(container_id, cmd, opt = {}) click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 103
def docker_exec_command(container_id, cmd, opt = {})
  exec_cmd = "exec"
  exec_cmd << " -t" if opt[:tty]
  exec_cmd << " -i" if opt[:interactive]
  exec_cmd << " #{container_id} #{wrap_command(cmd)}"
end
docker_login_command() click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 53
def docker_login_command
  args = []
  args << 'exec'
  args << '-t'
  args << '-i'
  args << @options[:container_id]
  args << '/bin/bash'
  LoginCommand.new(docker_base, args)
end
execute(cmd) click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 70
def execute(cmd)
  if cmd
    if @options[:lxc_driver]
      run_lxc(lxc_exec_command(@options[:container_id], cmd))
    else
      run_docker(docker_exec_command(@options[:container_id], cmd, :tty => false))
    end
  end
end
login_command() click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 45
def login_command
  if @options[:lxc_driver]
    lxc_login_command
  else
    docker_login_command
  end
end
lxc_attach_base() click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 123
def lxc_attach_base
  @options[:lxc_attach_base]
end
lxc_exec_command(container_id, cmd) click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 110
def lxc_exec_command(container_id, cmd)
  exec_cmd = " -n \"$(#{docker_base} inspect --format '{{.Id}}' #{@options[:container_id]})\""
  exec_cmd << " -- #{wrap_command(cmd)}"
end
lxc_login_command() click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 63
def lxc_login_command
  args = []
  args << 'in'
  args << "\"$(#{docker_base} inspect --format '{{.Id}}' #{@options[:container_id]})\""
  LoginCommand.new(@options[:lxc_console_base], args)
end
run_docker(cmd, options={}) click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 84
def run_docker(cmd, options={})
  run_command("#{docker_base} #{cmd}", options)
end
run_lxc(cmd, options={}) click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 80
def run_lxc(cmd, options={})
  run_command("#{lxc_attach_base} #{cmd}", options)
end
upload(locals, remote) click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 88
def upload(locals, remote)
  cmd = "mkdir -p #{remote}"
  execute(cmd)
  Array(locals).each do |local|
    remote_cmd = "tar x -C #{remote}"
    if @options[:lxc_driver]
      remote_cmd = "#{lxc_attach_base} #{lxc_exec_command(@options[:container_id], remote_cmd)}"
    else
      remote_cmd = "#{docker_base} cp - #{@options[:container_id]}:#{remote}"
    end
    local_cmd  = "cd #{File.dirname(local)} && tar cf - ./#{File.basename(local)}"
    run_command("#{local_cmd} | #{remote_cmd}")
  end
end
wrap_command(cmd) click to toggle source
# File lib/kitchen/transport/docker_cli.rb, line 115
def wrap_command(cmd)
  cmd.match(/\Ash\s\-c/) ? cmd : Util.wrap_command(cmd.gsub('\'', "'\\\\''"))
end