Class: Gitlab::QA::Docker::Command

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd = nil, mask_secrets: nil, stream_output: false) ⇒ Command

Shell command

Parameters:

  • cmd (<String, Array>) (defaults to: nil)
  • mask_secrets (<String, Array>) (defaults to: nil)
  • stream_output (Boolean) (defaults to: false)

    stream command output to stdout directly instead of logger



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

def initialize(cmd = nil, mask_secrets: nil, stream_output: false)
  @args = Array(cmd)
  @mask_secrets = mask_secrets
  @stream_output = stream_output
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



7
8
9
# File 'lib/gitlab/qa/docker/command.rb', line 7

def args
  @args
end

Class Method Details

.execute(cmd, mask_secrets: nil, &block) ⇒ Object



56
57
58
# File 'lib/gitlab/qa/docker/command.rb', line 56

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

Instance Method Details

#<<(*args) ⇒ Object



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

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

#==(other) ⇒ Object



44
45
46
# File 'lib/gitlab/qa/docker/command.rb', line 44

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

#env(name, value) ⇒ Object



32
33
34
# File 'lib/gitlab/qa/docker/command.rb', line 32

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

#execute!(&block) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/gitlab/qa/docker/command.rb', line 48

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

#name(identity) ⇒ Object



28
29
30
# File 'lib/gitlab/qa/docker/command.rb', line 28

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

#port(mapping) ⇒ Object



36
37
38
# File 'lib/gitlab/qa/docker/command.rb', line 36

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

#to_sObject



40
41
42
# File 'lib/gitlab/qa/docker/command.rb', line 40

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

#volume(from, to, opt = :z) ⇒ Object



24
25
26
# File 'lib/gitlab/qa/docker/command.rb', line 24

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