Sha256: 3fb6bdb1493f287bfaf7bb1152acf0da8ffeac8f1183eb1e89557cea84cc59f8

Contents?: true

Size: 1.09 KB

Versions: 23

Compression:

Stored size: 1.09 KB

Contents

require 'open3'
require 'rainbow/refinement'

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

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

          Rainbow.enabled = Runtime::Env.colorized_logs?
          Runtime::Logger.info("Docker shell command: `#{@command.mask_secrets}`".cyan)
        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

23 entries across 23 versions & 1 rubygems

Version Path
gitlab-qa-7.27.2 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.27.1 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.27.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.26.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.25.1 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.25.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.24.6 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.24.5 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.24.4 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.24.3 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.24.2 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.24.1 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.24.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.23.1 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.23.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.22.1 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.22.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.21.1 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.21.0 lib/gitlab/qa/docker/shellout.rb
gitlab-qa-7.20.0 lib/gitlab/qa/docker/shellout.rb