Class: Gitlab::QA::Docker::Engine

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

Constant Summary collapse

DOCKER_HOST =
ENV['DOCKER_HOST'] || 'http://localhost'

Instance Method Summary collapse

Instance Method Details

#attach(name, &block) ⇒ Object



35
36
37
# File 'lib/gitlab/qa/docker/engine.rb', line 35

def attach(name, &block)
  Docker::Command.execute("attach --sig-proxy=false #{name}", &block)
end

#exec(name, command) ⇒ Object



26
27
28
# File 'lib/gitlab/qa/docker/engine.rb', line 26

def exec(name, command)
  Docker::Command.execute("exec #{name} bash -c '#{command}'")
end

#hostnameObject



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

def hostname
  URI(DOCKER_HOST).host
end

#network_create(name) ⇒ Object



59
60
61
# File 'lib/gitlab/qa/docker/engine.rb', line 59

def network_create(name)
  Docker::Command.execute("network create #{name}")
end

#network_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/gitlab/qa/docker/engine.rb', line 51

def network_exists?(name)
  Docker::Command.execute("network inspect #{name}")
rescue Docker::Shellout::StatusError
  false
else
  true
end

#port(name, port) ⇒ Object



63
64
65
# File 'lib/gitlab/qa/docker/engine.rb', line 63

def port(name, port)
  Docker::Command.execute("port #{name} #{port}/tcp")
end

#pull(image, tag) ⇒ Object



11
12
13
# File 'lib/gitlab/qa/docker/engine.rb', line 11

def pull(image, tag)
  Docker::Command.execute("pull #{image}:#{tag}")
end

#read_file(image, tag, path, &block) ⇒ Object



30
31
32
33
# File 'lib/gitlab/qa/docker/engine.rb', line 30

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



47
48
49
# File 'lib/gitlab/qa/docker/engine.rb', line 47

def remove(name)
  Docker::Command.execute("rm -f #{name}")
end

#restart(name) ⇒ Object



39
40
41
# File 'lib/gitlab/qa/docker/engine.rb', line 39

def restart(name)
  Docker::Command.execute("restart #{name}")
end

#run(image, tag, *args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/qa/docker/engine.rb', line 15

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

#stop(name) ⇒ Object



43
44
45
# File 'lib/gitlab/qa/docker/engine.rb', line 43

def stop(name)
  Docker::Command.execute("stop #{name}")
end