Class: Gitlab::QA::Docker::Engine
- Inherits:
-
Object
- Object
- Gitlab::QA::Docker::Engine
- Defined in:
- lib/gitlab/qa/docker/engine.rb
Constant Summary collapse
- DOCKER_HOST =
ENV['DOCKER_HOST'] || 'http://localhost'
- PRIVILEGED_COMMANDS =
[/^iptables.*/].freeze
Instance Method Summary collapse
- #attach(name, &block) ⇒ Object
- #exec(name, command) ⇒ Object
- #hostname ⇒ Object
- #login(username:, password:, registry:) ⇒ Object
- #network_create(name) ⇒ Object
- #network_exists?(name) ⇒ Boolean
- #port(name, port) ⇒ Object
- #privileged_command?(command) ⇒ Boolean
- #ps(name = nil) ⇒ Object
- #pull(image, tag) ⇒ Object
- #read_file(image, tag, path, &block) ⇒ Object
- #remove(name) ⇒ Object
- #restart(name) ⇒ Object
- #run(image, tag, *args) ⇒ Object
- #running?(name) ⇒ Boolean
- #stop(name) ⇒ Object
Instance Method Details
#attach(name, &block) ⇒ Object
50 51 52 |
# File 'lib/gitlab/qa/docker/engine.rb', line 50 def attach(name, &block) Docker::Command.execute("attach --sig-proxy=false #{name}", &block) end |
#exec(name, command) ⇒ Object
39 40 41 42 43 |
# File 'lib/gitlab/qa/docker/engine.rb', line 39 def exec(name, command) cmd = ['exec'] cmd << '--privileged' if privileged_command?(command) Docker::Command.execute("#{cmd.join(' ')} #{name} bash -c '#{command}'") end |
#hostname ⇒ Object
8 9 10 |
# File 'lib/gitlab/qa/docker/engine.rb', line 8 def hostname URI(DOCKER_HOST).host end |
#login(username:, password:, registry:) ⇒ Object
12 13 14 |
# File 'lib/gitlab/qa/docker/engine.rb', line 12 def login(username:, password:, registry:) Docker::Command.execute(%(login --username "#{username}" --password "#{password}" #{registry}), mask_secrets: password) end |
#network_create(name) ⇒ Object
74 75 76 |
# File 'lib/gitlab/qa/docker/engine.rb', line 74 def network_create(name) Docker::Command.execute("network create #{name}") end |
#network_exists?(name) ⇒ Boolean
66 67 68 69 70 71 72 |
# File 'lib/gitlab/qa/docker/engine.rb', line 66 def network_exists?(name) Docker::Command.execute("network inspect #{name}") rescue Docker::Shellout::StatusError false else true end |
#port(name, port) ⇒ Object
78 79 80 |
# File 'lib/gitlab/qa/docker/engine.rb', line 78 def port(name, port) Docker::Command.execute("port #{name} #{port}/tcp") end |
#privileged_command?(command) ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/gitlab/qa/docker/engine.rb', line 31 def privileged_command?(command) PRIVILEGED_COMMANDS.each do |privileged_regex| return true if command.match(privileged_regex) end false end |
#ps(name = nil) ⇒ Object
86 87 88 |
# File 'lib/gitlab/qa/docker/engine.rb', line 86 def ps(name = nil) Docker::Command.execute(['ps', name].compact.join(' ')) end |
#pull(image, tag) ⇒ Object
16 17 18 |
# File 'lib/gitlab/qa/docker/engine.rb', line 16 def pull(image, tag) Docker::Command.execute("pull #{image}:#{tag}") end |
#read_file(image, tag, path, &block) ⇒ Object
45 46 47 48 |
# File 'lib/gitlab/qa/docker/engine.rb', line 45 def read_file(image, tag, path, &block) cat_file = "run --rm --entrypoint /bin/cat #{image}:#{tag} #{path}" Docker::Command.execute(cat_file, &block) end |
#remove(name) ⇒ Object
62 63 64 |
# File 'lib/gitlab/qa/docker/engine.rb', line 62 def remove(name) Docker::Command.execute("rm -f #{name}") end |
#restart(name) ⇒ Object
54 55 56 |
# File 'lib/gitlab/qa/docker/engine.rb', line 54 def restart(name) Docker::Command.execute("restart #{name}") end |
#run(image, tag, *args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gitlab/qa/docker/engine.rb', line 20 def run(image, tag, *args) Docker::Command.new('run').tap do |command| yield command if block_given? command << "#{image}:#{tag}" command << args if args.any? command.execute! end end |