Brian Cain 09af983caa
Fixes #11051: Only use host vm if specified
Prior to this commit, the docker login action assumed that if there was
a password to authenticate with, Vagrant was using a host vm to run
docker. This is likely due to some legacy decisions with how Vagrant
used to manage running docker. This commit fixes that by only grabbing a
host_vm lock if the host_vm is actually in use, otherwise login
normally.
2019-09-05 14:54:40 -07:00

49 lines
1.3 KiB
Ruby

require "log4r"
module VagrantPlugins
module DockerProvider
module Action
class Login
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::docker::login")
end
def login(env, config, driver)
# Login!
env[:ui].output(I18n.t("docker_provider.logging_in"))
driver.login(
config.email, config.username,
config.password, config.auth_server)
# Continue, so that the auth is protected
# from meddling.
@app.call(env)
# Log out
driver.logout(config.auth_server)
end
def call(env)
config = env[:machine].provider_config
driver = env[:machine].provider.driver
# If we don't have a password set, don't auth
return @app.call(env) if config.password == ""
if !env[:machine].provider.host_vm?
# no host vm in use, using docker directly
login(env, config, driver)
else
# Grab a host VM lock to do the login so that we only login
# once per container for the rest of this process.
env[:machine].provider.host_vm_lock do
login(env, config, driver)
end
end
end
end
end
end
end