Sha256: c74eb6c48c6769d13767098445454dba2a23dd7a8a3726cdab1bde8376d895ae

Contents?: true

Size: 983 Bytes

Versions: 17

Compression:

Stored size: 983 Bytes

Contents

require 'open3'

module Gitlab
  module QA
    module Docker
      class Shellout
        StatusError = Class.new(StandardError)

        def initialize(command)
          @command = command
          @output = []

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

        def execute! # rubocop:disable Metrics/AbcSize
          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
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
gitlab-qa-7.17.1 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.17.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.16.1 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.16.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.15.1 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.15.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.14.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.13.3 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.13.2 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.13.1 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.13.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.12.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.11.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.10.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.9.3 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.9.2 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.9.1 lib/gitlab/qa/docker/shellout.rb