Class: Specinfra::Backend::Docker

Inherits:
Exec
  • Object
show all
Defined in:
lib/specinfra/backend/docker.rb

Instance Method Summary collapse

Methods inherited from Exec

#send_directory

Methods inherited from Base

#set_example

Constructor Details

#initializeDocker

Returns a new instance of Docker.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/specinfra/backend/docker.rb', line 3

def initialize
  begin
    require 'docker' unless defined?(::Docker)
  rescue LoadError
    fail "Docker client library is not available. Try installing `docker-api' gem."
  end

  ::Docker.url = Specinfra.configuration.docker_url

  if image = Specinfra.configuration.docker_image
    @images = []
    @base_image = ::Docker::Image.get(image)

    create_and_start_container
    ObjectSpace.define_finalizer(self, proc { cleanup_container })
  elsif container = Specinfra.configuration.docker_container
    @container = ::Docker::Container.get(container)
  else
    fail 'Please specify docker_image or docker_container.'
  end
end

Instance Method Details

#add_pre_command(cmd) ⇒ Object



35
36
37
# File 'lib/specinfra/backend/docker.rb', line 35

def add_pre_command(cmd)
  cmd
end

#build_command(cmd) ⇒ Object



31
32
33
# File 'lib/specinfra/backend/docker.rb', line 31

def build_command(cmd)
  cmd
end

#run_command(cmd, opts = {}) ⇒ Object



25
26
27
28
29
# File 'lib/specinfra/backend/docker.rb', line 25

def run_command(cmd, opts={})
  cmd = build_command(cmd)
  cmd = add_pre_command(cmd)
  docker_run!(cmd)
end

#send_file(from, to) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/specinfra/backend/docker.rb', line 39

def send_file(from, to)
  if @base_image.nil?
    fail 'Cannot call send_file without docker_image.'
  end

  @images << current_image.insert_local('localPath' => from, 'outputPath' => to)
  cleanup_container
  create_and_start_container
end