Sha256: 9274171cceb6c31948f6dda1e09a01e1717d0e0d7e3490da172c59f7a8e3ab7b

Contents?: true

Size: 1.52 KB

Versions: 36

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Gitlab
  module QA
    module Docker
      class Command
        attr_reader :args

        # Shell command
        #
        # @param [<String, Array>] cmd
        # @param [<String, Array>] mask_secrets
        # @param [Boolean] stream_output stream command output to stdout directly instead of logger
        def initialize(cmd = nil, mask_secrets: nil, stream_output: false)
          @args = Array(cmd)
          @mask_secrets = mask_secrets
          @stream_output = stream_output
        end

        def <<(*args)
          tap { @args.concat(args) }
        end

        def volume(from, to, opt = :z)
          tap { @args.push("--volume #{from}:#{to}:#{opt}") }
        end

        def name(identity)
          tap { @args.push("--name #{identity}") }
        end

        def env(name, value)
          tap { @args.push(%(--env #{name}="#{value}")) }
        end

        def port(mapping)
          tap { @args.push("-p #{mapping}") }
        end

        def to_s
          "docker #{@args.join(' ')}"
        end

        def ==(other)
          to_s == other.to_s
        end

        def execute!(&block)
          Support::ShellCommand.new(to_s, mask_secrets: @mask_secrets, stream_output: @stream_output).execute!(&block)
        rescue Support::ShellCommand::StatusError => e
          e.set_backtrace([])

          raise e
        end

        def self.execute(cmd, mask_secrets: nil, &block)
          new(cmd, mask_secrets: mask_secrets).execute!(&block)
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
gitlab-qa-15.2.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-15.1.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-15.0.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.21.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.20.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.19.2 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.19.1 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.19.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.18.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.17.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.16.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.15.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.14.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.13.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.12.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.11.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.9.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.8.1 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.8.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-14.7.0 lib/gitlab/qa/docker/command.rb