2013-11-26 21:48:51 +00:00
|
|
|
require_relative "docker_client"
|
|
|
|
require_relative "docker_installer"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Docker
|
2013-11-26 22:09:20 +00:00
|
|
|
class DockerError < Vagrant::Errors::VagrantError
|
|
|
|
error_namespace("vagrant.provisioners.docker")
|
|
|
|
end
|
|
|
|
|
2013-11-26 21:48:51 +00:00
|
|
|
# TODO: Improve handling of vagrant-lxc specifics (like checking for apparmor
|
|
|
|
# profile stuff + autocorrection)
|
|
|
|
class Provisioner < Vagrant.plugin("2", :provisioner)
|
|
|
|
def initialize(machine, config, installer = nil, client = nil)
|
|
|
|
super(machine, config)
|
2013-12-03 22:25:20 +00:00
|
|
|
|
2013-11-26 21:48:51 +00:00
|
|
|
# TODO: Rename to installer / client (drop docker suffix)
|
|
|
|
@installer = installer || DockerInstaller.new(@machine, config.version)
|
|
|
|
@client = client || DockerClient.new(@machine)
|
|
|
|
end
|
|
|
|
|
|
|
|
def provision
|
2013-11-26 22:09:20 +00:00
|
|
|
@logger = Log4r::Logger.new("vagrant::provisioners::docker")
|
2013-11-26 21:48:51 +00:00
|
|
|
|
|
|
|
@logger.info("Checking for Docker installation...")
|
|
|
|
@installer.ensure_installed
|
|
|
|
|
|
|
|
# Attempt to start service if not running
|
|
|
|
@client.start_service
|
2013-12-03 22:19:31 +00:00
|
|
|
raise DockerError, :not_running if !@client.daemon_running?
|
2013-11-26 21:48:51 +00:00
|
|
|
|
|
|
|
if config.images.any?
|
|
|
|
@machine.ui.info(I18n.t("vagrant.docker_pulling_images"))
|
|
|
|
@client.pull_images(*config.images)
|
|
|
|
end
|
|
|
|
|
|
|
|
if config.containers.any?
|
|
|
|
@machine.ui.info(I18n.t("vagrant.docker_starting_containers"))
|
|
|
|
@client.run(config.containers)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|