Class: ElasticGraph::Local::DockerRunner
- Inherits:
-
Object
- Object
- ElasticGraph::Local::DockerRunner
- Defined in:
- lib/elastic_graph/local/docker_runner.rb
Instance Method Summary collapse
-
#boot ⇒ Object
:nocov: – difficult to test ‘exec` behavior (replaces current process).
- #boot_as_daemon(halt_command:) ⇒ Object
-
#halt ⇒ Object
:nocov:.
-
#initialize(variant, port:, ui_port:, version:, env:, ready_log_line:, daemon_timeout:, output:) ⇒ DockerRunner
constructor
A new instance of DockerRunner.
Constructor Details
#initialize(variant, port:, ui_port:, version:, env:, ready_log_line:, daemon_timeout:, output:) ⇒ DockerRunner
Returns a new instance of DockerRunner.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/elastic_graph/local/docker_runner.rb', line 15 def initialize(variant, port:, ui_port:, version:, env:, ready_log_line:, daemon_timeout:, output:) @variant = variant @port = port @ui_port = ui_port @version = version @env = env @ready_log_line = ready_log_line @daemon_timeout = daemon_timeout @output = output end |
Instance Method Details
#boot ⇒ Object
:nocov: – difficult to test ‘exec` behavior (replaces current process)
27 28 29 30 31 32 33 |
# File 'lib/elastic_graph/local/docker_runner.rb', line 27 def boot halt prepare_docker_compose_run "up" do |command| exec(command) # we use `exec` so that our process is replaced with that one. end end |
#boot_as_daemon(halt_command:) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/elastic_graph/local/docker_runner.rb', line 42 def boot_as_daemon(halt_command:) halt @output.puts "Booting #{@variant}; monitoring logs for readiness..." pid = spawn_docker_compose_up do |read_io| ::Timeout.timeout( @daemon_timeout, ::Timeout::Error, <<~EOS Timed out after #{@daemon_timeout} seconds. The expected "ready" log line[1] was not found in the logs. [1] #{@ready_log_line.inspect} EOS ) do loop do sleep 0.01 line = read_io.gets @output.puts line break if @ready_log_line.match?(line.to_s) end end end # Detach so the process continues running after this Ruby process exits. ::Process.detach(pid) @output.puts @output.puts @output.puts <<~EOS Success! #{@variant} #{@version} (pid: #{pid}) has been booted for the #{@env} environment on port #{@port}. It will continue to run in the background as a daemon. To halt it, run: #{halt_command} EOS end |
#halt ⇒ Object
:nocov:
36 37 38 39 40 |
# File 'lib/elastic_graph/local/docker_runner.rb', line 36 def halt prepare_docker_compose_run "down --volumes" do |command| system(command) end end |