Sha256: 6db1c2b2fd4c19f71880d14f40e1d46097633b2008e99d94793c1efd4f0814c0

Contents?: true

Size: 1.93 KB

Versions: 30

Compression:

Stored size: 1.93 KB

Contents

require_relative "client"
require_relative "installer"

module VagrantPlugins
  module DockerProvisioner
    class DockerError < Vagrant::Errors::VagrantError
      error_namespace("vagrant.provisioners.docker")
    end

    class Provisioner < Vagrant.plugin("2", :provisioner)
      def initialize(machine, config, installer = nil, client = nil)
        super(machine, config)

        @installer = installer || Installer.new(@machine)
        @client    = client    || Client.new(@machine)
      end

      def provision
        @logger = Log4r::Logger.new("vagrant::provisioners::docker")

        @logger.info("Checking for Docker installation...")
        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

        # Attempt to start service if not running
        @client.start_service
        raise DockerError, :not_running if !@client.daemon_running?

        if config.images.any?
          @machine.ui.info(I18n.t("vagrant.docker_pulling_images"))
          @client.pull_images(*config.images)
        end

        if config.build_images.any?
          @machine.ui.info(I18n.t("vagrant.docker_building_images"))
          @client.build_images(config.build_images)
        end

        if config.containers.any?
          @machine.ui.info(I18n.t("vagrant.docker_starting_containers"))
          @client.run(config.containers)
        end
      end

      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
    end
  end
end

Version data entries

30 entries across 26 versions & 4 rubygems

Version Path
vagrant-unbundled-2.2.7.0 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.2.6.2 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.2.6.1 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.2.6.0 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.2.5.0 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.2.4.0 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.2.3.0 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.2.2.0 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.2.0.0 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.1.4.0 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.1.2.0 plugins/provisioners/docker/provisioner.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/provisioners/docker/provisioner.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/provisioners/docker/provisioner.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/provisioners/docker/provisioner.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/provisioners/docker/provisioner.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/provisioners/docker/provisioner.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.1.1.0 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.0.4.0 plugins/provisioners/docker/provisioner.rb
vagrant-unbundled-2.0.3.0 plugins/provisioners/docker/provisioner.rb