Class: Rascal::Docker::Interface
- Inherits:
-
Object
- Object
- Rascal::Docker::Interface
- Defined in:
- lib/rascal/docker/interface.rb
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #run(*command, output: :ignore, stdout: nil, allow_failure: false) ⇒ Object
- #run_and_attach(*command, stdout: nil, stderr: nil, stdin: nil, env: {}, network: nil, volumes: [], working_dir: nil, redirect_io: {}, allow_failure: false) ⇒ Object
Instance Method Details
#run(*command, output: :ignore, stdout: nil, allow_failure: false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rascal/docker/interface.rb', line 9 def run(*command, output: :ignore, stdout: nil, allow_failure: false) save_stdout = '' save_stderr = '' exit_status = nil popen3('docker', *stringify_command(command)) do |docker_stdin, docker_stdout, docker_stderr, wait_thr| docker_stdin.close output_threads = [ read_lines(docker_stdout, save_stdout, stdout), read_lines(docker_stderr, save_stderr), ] exit_status = wait_thr.value output_threads.each(&:join) end unless allow_failure || exit_status.success? raise Error, "docker command '#{command.join(' ')}' failed with error:\n#{save_stderr}" end parse_output(output, save_stdout, save_stderr, command: command.join(' ')) end |
#run_and_attach(*command, stdout: nil, stderr: nil, stdin: nil, env: {}, network: nil, volumes: [], working_dir: nil, redirect_io: {}, allow_failure: false) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/rascal/docker/interface.rb', line 28 def run_and_attach(*command, stdout: nil, stderr: nil, stdin: nil, env: {}, network: nil, volumes: [], working_dir: nil, redirect_io: {}, allow_failure: false) exit_status = spawn(env, 'docker', *stringify_command(command), redirect_io) unless allow_failure || exit_status.success? raise Error, "docker container run failed" end end |