Class: Conjure::Docker::Host
- Inherits:
-
Object
- Object
- Conjure::Docker::Host
- Defined in:
- lib/conjure/docker/host.rb
Instance Method Summary collapse
- #build(image_source_files) ⇒ Object
-
#initialize(server) ⇒ Host
constructor
A new instance of Host.
- #running?(container_name) ⇒ Boolean
- #start(image_name, daemon_command, options = {}) ⇒ Object
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
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, = {}) container_name = [:name] = "#{ } #{image_name} #{daemon_command}" if running? container_name puts "Detected #{container_name} container running." else puts "Starting #{container_name} container..." @server.run("docker run #{}").strip sleep 2 raise "Container failed to start" unless running? container_name end end |