class Gitlab::QA::Docker::Shellout

Constants

StatusError

Public Class Methods

new(command) click to toggle source
# File lib/gitlab/qa/docker/shellout.rb, line 9
def initialize(command)
  @command = command
  @output = []

  puts "Docker shell command: `#{@command.mask_secrets}`"
end

Public Instance Methods

execute!() { |line, wait| ... } click to toggle source
# File lib/gitlab/qa/docker/shellout.rb, line 16
def execute!
  raise StatusError, 'Command already executed' if @output.any?

  Open3.popen2e(@command.to_s) do |_in, out, wait|
    out.each do |line|
      @output.push(line)

      if block_given?
        yield line, wait
      else
        puts line
      end
    end

    if wait.value.exited? && wait.value.exitstatus.nonzero? # rubocop:disable Style/IfUnlessModifier
      raise StatusError, "Docker command `#{@command.mask_secrets}` failed!"
    end
  end

  @output.join.chomp
end