Class: Beaker::Docker
- Inherits:
-
Hypervisor
- Object
- Hypervisor
- Beaker::Docker
- Defined in:
- lib/beaker/hypervisor/docker.rb
Constant Summary
Constants inherited from Hypervisor
Constants included from HostPrebuiltSteps
HostPrebuiltSteps::APT_CFG, HostPrebuiltSteps::DEBIAN_PACKAGES, HostPrebuiltSteps::ETC_HOSTS_PATH, HostPrebuiltSteps::ETC_HOSTS_PATH_SOLARIS, HostPrebuiltSteps::IPS_PKG_REPO, HostPrebuiltSteps::NTPSERVER, HostPrebuiltSteps::ROOT_KEYS_SCRIPT, HostPrebuiltSteps::ROOT_KEYS_SYNC_CMD, HostPrebuiltSteps::SLEEPWAIT, HostPrebuiltSteps::SLES_PACKAGES, HostPrebuiltSteps::TRIES, HostPrebuiltSteps::UNIX_PACKAGES, HostPrebuiltSteps::WINDOWS_PACKAGES
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize(hosts, options) ⇒ Docker
constructor
A new instance of Docker.
- #provision ⇒ Object
Methods inherited from Hypervisor
#configure, create, #generate_host_name, #validate
Methods included from HostPrebuiltSteps
#add_el_extras, #apt_get_update, #copy_file_to_remote, #copy_ssh_to_root, #disable_iptables, #disable_se_linux, #enable_root_login, #epel_info_for!, #get_domain_name, #get_ip, #hack_etc_hosts, #package_proxy, #proxy_config, #set_etc_hosts, #sync_root_keys, #timesync, #validate_host
Methods included from Beaker::DSL::Patterns
Constructor Details
#initialize(hosts, options) ⇒ Docker
Returns a new instance of Docker.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/beaker/hypervisor/docker.rb', line 4 def initialize(hosts, ) require 'docker' @options = @logger = [:logger] @hosts = hosts # increase the http timeouts as provisioning images can be slow ::Docker. = { :write_timeout => 300, :read_timeout => 300 } # assert that the docker-api gem can talk to your docker # enpoint. Will raise if there is a version mismatch ::Docker.validate_version! # Pass on all the logging from docker-api to the beaker logger instance ::Docker.logger = @logger end |
Instance Method Details
#cleanup ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/beaker/hypervisor/docker.rb', line 60 def cleanup @logger.notify "Cleaning up docker" @hosts.each do |host| if container = host['docker_container'] @logger.debug("stop container #{container.id}") begin container.stop rescue Excon::Errors::ClientError => e @logger.warn("stop of container #{container.id} failed: #{e.response.body}") end @logger.debug("delete container #{container.id}") begin container.delete rescue Excon::Errors::ClientError => e @logger.warn("deletion of container #{container.id} failed: #{e.response.body}") end end # Do not remove the image if docker_reserve_image is set to true, otherwise remove it if image = (host['docker_preserve_image'] ? nil : host['docker_image']) @logger.debug("delete image #{image.id}") begin image.delete rescue Excon::Errors::ClientError => e @logger.warn("deletion of image #{image.id} failed: #{e.response.body}") end end end end |
#provision ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/beaker/hypervisor/docker.rb', line 19 def provision @logger.notify "Provisioning docker" @hosts.each do |host| @logger.notify "provisioning #{host.name}" @logger.debug("Creating image") image = ::Docker::Image.build(dockerfile_for(host), { :rm => true }) @logger.debug("Creating container from image #{image.id}") container = ::Docker::Container.create({ 'Image' => image.id, 'Hostname' => host.name, }) @logger.debug("Starting container #{container.id}") container.start({"PublishAllPorts" => true, "Privileged" => true}) # Find out where the ssh port is from the container if ENV['DOCKER_HOST'] ip = URI.parse(ENV['DOCKER_HOST']).host @logger.info("Using docker server at #{ip}") else ip = container.json["NetworkSettings"]["Ports"]["22/tcp"][0]["HostIp"] end port = container.json["NetworkSettings"]["Ports"]["22/tcp"][0]["HostPort"] # Update host metadata host['ip'] = ip host['port'] = port host['ssh'] = { :password => root_password, :port => port, } @logger.debug("node available as ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@#{ip} -p #{port}") host['docker_container'] = container host['docker_image'] = image end end |