2013-12-12 19:54:20 +00:00
|
|
|
require_relative "client"
|
|
|
|
require_relative "installer"
|
2013-11-26 21:48:51 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
2014-03-26 23:32:31 +00:00
|
|
|
module DockerProvisioner
|
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
|
|
|
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
|
|
|
|
2015-11-20 01:45:16 +00:00
|
|
|
@installer = installer || Installer.new(@machine)
|
2013-12-12 19:54:20 +00:00
|
|
|
@client = client || Client.new(@machine)
|
2013-11-26 21:48:51 +00:00
|
|
|
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...")
|
2017-06-23 23:32:36 +00:00
|
|
|
if @installer.ensure_installed
|
|
|
|
if !config.post_install_provisioner.nil?
|
|
|
|
@logger.info("Running post setup provision script...")
|
|
|
|
env = {
|
|
|
|
callable: method(:run_provisioner),
|
|
|
|
provisioner: config.post_install_provisioner,
|
|
|
|
machine: machine}
|
|
|
|
machine.env.hook(:run_provisioner, env)
|
|
|
|
end
|
|
|
|
end
|
2013-11-26 21:48:51 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2013-12-09 22:52:45 +00:00
|
|
|
if config.build_images.any?
|
|
|
|
@machine.ui.info(I18n.t("vagrant.docker_building_images"))
|
|
|
|
@client.build_images(config.build_images)
|
|
|
|
end
|
|
|
|
|
2013-11-26 21:48:51 +00:00
|
|
|
if config.containers.any?
|
|
|
|
@machine.ui.info(I18n.t("vagrant.docker_starting_containers"))
|
|
|
|
@client.run(config.containers)
|
|
|
|
end
|
|
|
|
end
|
2017-06-23 23:32:36 +00:00
|
|
|
|
|
|
|
def run_provisioner(env)
|
|
|
|
klass = Vagrant.plugin("2").manager.provisioners[env[:provisioner].type]
|
|
|
|
result = klass.new(env[:machine], env[:provisioner].config)
|
|
|
|
result.config.finalize!
|
|
|
|
|
|
|
|
result.provision
|
|
|
|
end
|
2013-11-26 21:48:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|