lib/geordi/docker.rb in geordi-2.12.1 vs lib/geordi/docker.rb in geordi-2.12.2

- old
+ new

@@ -16,35 +16,63 @@ else fail('Build failed.') end end - def shell + def shell(options = {}) check_installation_and_config - command = [:exec, 'docker-compose', 'run', '--service-ports'] - command += ssh_agent_forward - command += ['main'] - execute(*command) + if options[:secondary] + attach_to_running_shell + else + run_shell + end end def vnc Cucumber.new.launch_vnc_viewer('::5967') end private + def attach_to_running_shell + running_containers = execute(:`, 'docker-compose ps').split("\n") + if (main_container_line = running_containers.grep(/_main_run/).first) + container_name = main_container_line.split(' ').first + execute(:system, 'docker', 'exec', '-it', container_name, 'bash') + else + fail('Could not find a running shell. Start without --secondary first.') + end + end + + def run_shell + command = [:system, 'docker-compose', 'run', '--service-ports'] + command += ssh_agent_forward + command += ['main'] + execute(*command) + execute(:system, 'docker-compose', 'stop') + end + def execute(kind, *args) if ENV['GEORDI_TESTING'] puts "Stubbed run #{args.join(' ')}" - mock_run(*args) + if kind == :` + mock_parse(*args) + else + mock_run(*args) + end else send(kind, *args) end end def mock_run(*args) # exists just to be stubbed in tests true + end + + def mock_parse(*args) + # exists just to be stubbed in tests + 'command output' end def check_installation_and_config unless command_exists?('docker') fail('You need to install docker first with `sudo apt install docker`. After installation please log out and back in to your system once.')