Class: Vanagon::Engine::Docker

Inherits:
Base
  • Object
show all
Defined in:
lib/vanagon/engine/docker.rb

Instance Attribute Summary

Attributes inherited from Base

#remote_workdir, #target

Instance Method Summary collapse

Methods inherited from Base

#dispatch, #get_remote_workdir, #retrieve_built_artifact, #setup, #ship_workdir, #startup, #validate_platform

Constructor Details

#initialize(platform, target = nil, **opts) ⇒ Docker

Both the docker_image and the docker command itself are required for the docker engine to work



8
9
10
11
12
13
# File 'lib/vanagon/engine/docker.rb', line 8

def initialize(platform, target = nil, **opts)
  super

  @docker_cmd = Vanagon::Utilities.find_program_on_path('docker')
  @required_attributes << "docker_image"
end

Instance Method Details

#build_host_nameObject

Return the docker image name to build on



21
22
23
24
25
26
27
28
# File 'lib/vanagon/engine/docker.rb', line 21

def build_host_name
  if @build_host_name.nil?
    validate_platform
    @build_host_name = @platform.docker_image
  end

  @build_host_name
end

#nameObject

Get the engine name



16
17
18
# File 'lib/vanagon/engine/docker.rb', line 16

def name
  'docker'
end

#select_targetObject

This method is used to obtain a vm to build upon using a docker container.

Raises:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vanagon/engine/docker.rb', line 33

def select_target
  Vanagon::Utilities.ex("#{@docker_cmd} run -d --name #{build_host_name}-builder -p #{@platform.ssh_port}:22 #{build_host_name}")
  @target = 'localhost'

  # Wait for ssh to come up in the container
  Vanagon::Utilities.retry_with_timeout do
    Vanagon::Utilities.remote_ssh_command("#{@target_user}@#{@target}", 'exit', @platform.ssh_port)
  end
rescue StandardError => e
  raise Vanagon::Error.wrap(e, "Something went wrong getting a target vm to build on using docker. Ssh was not up in the container after 5 seconds.")
end

#teardownObject

This method is used to tell the vmpooler to delete the instance of the vm that was being used so the pool can be replenished.



47
48
49
50
51
52
# File 'lib/vanagon/engine/docker.rb', line 47

def teardown
  Vanagon::Utilities.ex("#{@docker_cmd} stop #{build_host_name}-builder")
  Vanagon::Utilities.ex("#{@docker_cmd} rm #{build_host_name}-builder")
rescue Vanagon::Error => e
  warn "There was a problem tearing down the docker container #{build_host_name}-builder (#{e.message})."
end