Class: Conjure::Docker::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/conjure/docker/host.rb

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Host

Returns a new instance of Host.



4
5
6
# File 'lib/conjure/docker/host.rb', line 4

def initialize(server)
  @server = server
end

Instance Method Details

#build(image_source_files) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/conjure/docker/host.rb', line 21

def build(image_source_files)
  Dir.mktmpdir do |dir|
    image_source_files.each { |filename, data| File.write "#{dir}/#{filename}", data }
    result = with_directory(dir) { |remote_dir| @server.run "docker build #{remote_dir}" }
    match = result.match(/Successfully built ([0-9a-z]+)/)
    raise "Failed to build Docker image, output was #{result}" unless match
    match[1]
  end
end

#running?(container_name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/conjure/docker/host.rb', line 31

def running?(container_name)
  running_container_names.include? container_name
end

#start(image_name, daemon_command, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/conjure/docker/host.rb', line 8

def start(image_name, daemon_command, options = {})
  container_name = options[:name]
  all_options = "#{start_options options} #{image_name} #{daemon_command}"
  if running? container_name
    puts "Detected #{container_name} container running."
  else
    puts "Starting #{container_name} container..."
    @server.run("docker run #{all_options}").strip
    sleep 2
    raise "Container failed to start" unless running? container_name
  end
end