Module: LaunchSupport
- Included in:
- DockerRunner
- Defined in:
- lib/support/launch_support.rb
Instance Method Summary collapse
- #host ⇒ Object
- #is_port_open?(ip, port) ⇒ Boolean
- #wait_for_port(ip, port) ⇒ Object
- #wait_for_short_lived_image_to_complete(image_run_name) ⇒ Object
Instance Method Details
#host ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/support/launch_support.rb', line 50 def host output = `boot2docker ip` if (output.strip.length == 0) || (output.include?("command not found")) || (output.include?("is not running")) docker_machine_active = `docker-machine active` docker_machine_active = docker_machine_active[0..(docker_machine_active.length - 2)] output = `docker-machine url #{docker_machine_active}` address = output.split("//")[1].split(":").first return address else return output.strip end end |
#is_port_open?(ip, port) ⇒ Boolean
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/support/launch_support.rb', line 3 def is_port_open?(ip, port) begin Timeout::timeout(1) do begin puts "Connecting to #{ip}: #{port}" s = TCPSocket.new(ip, port) s.close return true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH return false end end rescue Timeout::Error end return false end |
#wait_for_port(ip, port) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/support/launch_support.rb', line 42 def wait_for_port(ip, port) while (!is_port_open?(ip, port)) puts "Port not ready: #{ip}:#{port}" sleep 3 end end |
#wait_for_short_lived_image_to_complete(image_run_name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/support/launch_support.rb', line 21 def wait_for_short_lived_image_to_complete(image_run_name) done = false while (!done) #puts "Inspecting image: #{image_run_name}" output = `docker inspect #{image_run_name}` #puts "Output: #{output}" json = JSON.parse(output) state = json.first['State'] is_running = state['Running'] exit_code = state['ExitCode'] puts "Waiting for short-lived container to complete: \"#{image_run_name}\"" if (exit_code == 0) && (is_running == false) done = true elsif (exit_code != 0) raise "Container failed: #{image_run_name} - Run: docker logs -f #{image_run_name}" else sleep 3 end end end |