Class: Gitlab::QA::Docker::Shellout

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/qa/docker/shellout.rb

Constant Summary collapse

StatusError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Shellout

Returns a new instance of Shellout.



14
15
16
17
18
# File 'lib/gitlab/qa/docker/shellout.rb', line 14

def initialize(command)
  @command = command
  @output = []
  @logger = Runtime::Logger.logger
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



20
21
22
# File 'lib/gitlab/qa/docker/shellout.rb', line 20

def command
  @command
end

#outputObject (readonly)

Returns the value of attribute output.



20
21
22
# File 'lib/gitlab/qa/docker/shellout.rb', line 20

def output
  @output
end

Instance Method Details

#execute!Object

rubocop:disable Metrics/AbcSize

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gitlab/qa/docker/shellout.rb', line 22

def execute! # rubocop:disable Metrics/AbcSize
  raise StatusError, 'Command already executed' if output.any?

  logger.info("Docker shell command: `#{command.mask_secrets.cyan}`")

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

      if stream_progress
        print "."
      elsif command.stream_output
        puts line
      end

      yield line, wait if block_given?
    end
    puts if stream_progress && !output.empty?

    fail! if wait.value.exited? && wait.value.exitstatus.nonzero?

    logger.debug("Docker shell command output:\n#{string_output}") unless command.stream_output || output.empty?
  end

  string_output
end