class Vx::ContainerConnector::Docker
Attributes
image[R]
init[R]
memory[R]
memory_swap[R]
password[R]
remote_dir[R]
user[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/vx/container_connector/docker.rb, line 20 def initialize(options = {}) @user = options[:user] || "vexor" @password = options[:password] || "vexor" @init = options[:init] || %w{ /sbin/my_init } @image = options[:image] || "ubuntu" @remote_dir = options[:remote_dir] || "/home/#{user}" @memory = options[:memory].to_i @memory_swap = options[:memory_swap].to_i end
Public Instance Methods
create_container_options()
click to toggle source
# File lib/vx/container_connector/docker.rb, line 36 def create_container_options Default.create_container_options.merge( 'Cmd' => init, 'Image' => image, 'Memory' => memory, 'MemorySwap' => memory_swap ) end
start(&block)
click to toggle source
# File lib/vx/container_connector/docker.rb, line 30 def start(&block) start_container do |container| open_ssh_session(container, &block) end end
start_container_options()
click to toggle source
# File lib/vx/container_connector/docker.rb, line 45 def start_container_options Default.start_container_options end
Private Instance Methods
open_ssh_session(container) { |spawner| ... }
click to toggle source
# File lib/vx/container_connector/docker.rb, line 51 def open_ssh_session(container) host = Default.ssh_host || container.json['NetworkSettings']['IPAddress'] ssh_options = { password: password, port: Default.ssh_port, paranoid: false, forward_agent: false } instrumentation = { container_type: "docker", container: container.json, ssh_host: host } with_retries ::Net::SSH::AuthenticationFailed, Errno::ECONNREFUSED, Errno::ETIMEDOUT, limit: 20, sleep: 1 do instrument("starting_ssh_session", instrumentation) open_ssh(host, user, ssh_options) do |ssh| yield Spawner.new(container, ssh, remote_dir) end end end
start_container() { |container| ... }
click to toggle source
# File lib/vx/container_connector/docker.rb, line 75 def start_container(&block) container = instrument("create_container", container_type: "docker", container_options: create_container_options) do ::Docker::Container.create create_container_options end instrumentation = { container_type: "docker", container: container.json, container_options: start_container_options, } instrument("start_container", instrumentation) do container.start start_container_options end begin yield container ensure instrument("kill_container", instrumentation) do container.kill container.remove end end end