Docker provider to run provisioners if available

This commit is contained in:
sophia 2020-05-05 13:19:14 -04:00
parent 1a3e6c8ed5
commit 33576b5846
2 changed files with 39 additions and 8 deletions

View file

@ -216,14 +216,12 @@ module VagrantPlugins
Vagrant::Action::Builder.new.tap do |b|
b.use Call, IsState, :running do |env, b2|
if env[:machine_action] != :run_command
b2.use Call, HasSSH do |env2, b3|
if env2[:result]
b3.use Provision
else
b3.use Message,
I18n.t("docker_provider.messages.provision_no_ssh"),
post: true
end
b2.use Call, HasProvisioner do |env2, b3|
ids = env2[:run].map { |r| r.id }
name_type = env2[:skip].map { |r| [r.name, r.type] }
b3.use Provision, ids
# TODO: fix message
b3.use Message, "skipping provisioners: #{name_type}"
end
end
@ -304,6 +302,7 @@ module VagrantPlugins
autoload :DestroyNetwork, action_root.join("destroy_network")
autoload :ForwardedPorts, action_root.join("forwarded_ports")
autoload :HasSSH, action_root.join("has_ssh")
autoload :HasProvisioner, action_root.join("has_provisioner")
autoload :HostMachine, action_root.join("host_machine")
autoload :HostMachineBuildDir, action_root.join("host_machine_build_dir")
autoload :HostMachinePortChecker, action_root.join("host_machine_port_checker")

View file

@ -0,0 +1,32 @@
module VagrantPlugins
module DockerProvider
module Action
# This middleware is used with Call to test if this machine
# has available provisioners
class HasProvisioner
def initialize(app, env)
@app = app
end
def call(env)
env[:run] = []
env[:skip] = []
has_ssh = env[:machine].provider_config.has_ssh
if has_ssh
env[:run] = env[:machine].config.vm.provisioners
else
env[:machine].config.vm.provisioners.each do |p|
if p.communicator_required
env[:skip].push(p)
else
env[:run].push(p)
end
end
end
@app.call(env)
end
end
end
end
end