Class: Vanagon::Engine::Docker
- Defined in:
- lib/vanagon/engine/docker.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#build_host_name ⇒ Object
Return the docker image name to build on.
-
#initialize(platform, target = nil, **opts) ⇒ Docker
constructor
Both the docker_image and the docker command itself are required for the docker engine to work.
-
#name ⇒ Object
Get the engine name.
-
#select_target ⇒ Object
This method is used to obtain a vm to build upon using a docker container.
-
#teardown ⇒ Object
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.
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_name ⇒ Object
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 |
#name ⇒ Object
Get the engine name
16 17 18 |
# File 'lib/vanagon/engine/docker.rb', line 16 def name 'docker' end |
#select_target ⇒ Object
This method is used to obtain a vm to build upon using a docker container.
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 |
#teardown ⇒ Object
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.})." end |