Allow passing custom env vars to vagrant plugin cmds
This commit is contained in:
parent
16a9635553
commit
613f40b048
|
@ -137,10 +137,11 @@ module Vagrant
|
|||
# Installs the list of plugins.
|
||||
#
|
||||
# @param [Hash] plugins
|
||||
# @param [Hash] env_vars Additional/override environment variables
|
||||
# @param [Boolean] env_local Environment local plugin install
|
||||
# @return [Array<Gem::Specification>]
|
||||
def install(plugins, env_local=false)
|
||||
internal_install(plugins, nil, env_local: env_local)
|
||||
def install(plugins, env_vars={}, env_local=false)
|
||||
internal_install(plugins, nil, env_vars: env_vars, env_local: env_local)
|
||||
end
|
||||
|
||||
# Installs a local '*.gem' file so that Bundler can find it.
|
||||
|
@ -385,27 +386,33 @@ module Vagrant
|
|||
# dependencies are satisfied by gems in the install directory (which will likely not
|
||||
# be true)
|
||||
install_path = extra[:env_local] ? env_plugin_gem_path : plugin_gem_path
|
||||
result = request_set.install_into(install_path.to_s, true,
|
||||
ignore_dependencies: true,
|
||||
prerelease: Vagrant.prerelease?,
|
||||
wrappers: true
|
||||
)
|
||||
result = result.map(&:full_spec)
|
||||
result.each do |spec|
|
||||
existing_paths = $LOAD_PATH.find_all{|s| s.include?(spec.full_name) }
|
||||
if !existing_paths.empty?
|
||||
@logger.debug("Removing existing LOAD_PATHs for #{spec.full_name} - " +
|
||||
existing_paths.join(", "))
|
||||
existing_paths.each{|s| $LOAD_PATH.delete(s) }
|
||||
end
|
||||
spec.full_require_paths.each do |r_path|
|
||||
if !$LOAD_PATH.include?(r_path)
|
||||
@logger.debug("Adding path to LOAD_PATH - #{r_path}")
|
||||
$LOAD_PATH.unshift(r_path)
|
||||
Vagrant::with_temp_env(extra[:env_vars]) do
|
||||
# TODO: we're writing the env_vars for each installed plugin to plugins.json, but
|
||||
# we're unable to honour them here because the RequestSet defines the changes for
|
||||
# all plugins. How do we fix this so that vagrant plugin update honours the
|
||||
# original install env vars?
|
||||
result = request_set.install_into(install_path.to_s, true,
|
||||
ignore_dependencies: true,
|
||||
prerelease: Vagrant.prerelease?,
|
||||
wrappers: true
|
||||
)
|
||||
result = result.map(&:full_spec)
|
||||
result.each do |spec|
|
||||
existing_paths = $LOAD_PATH.find_all{|s| s.include?(spec.full_name) }
|
||||
if !existing_paths.empty?
|
||||
@logger.debug("Removing existing LOAD_PATHs for #{spec.full_name} - " +
|
||||
existing_paths.join(", "))
|
||||
existing_paths.each{|s| $LOAD_PATH.delete(s) }
|
||||
end
|
||||
spec.full_require_paths.each do |r_path|
|
||||
if !$LOAD_PATH.include?(r_path)
|
||||
@logger.debug("Adding path to LOAD_PATH - #{r_path}")
|
||||
$LOAD_PATH.unshift(r_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
# Generate the composite resolver set totally all of vagrant (builtin + plugin set)
|
||||
|
|
|
@ -135,7 +135,7 @@ module Vagrant
|
|||
if local_spec.nil?
|
||||
result = nil
|
||||
install_lambda = lambda do
|
||||
Vagrant::Bundler.instance.install(plugins, opts[:env_local]).each do |spec|
|
||||
Vagrant::Bundler.instance.install(plugins, opts[:env_vars], opts[:env_local]).each do |spec|
|
||||
next if spec.name != name
|
||||
next if result && result.version >= spec.version
|
||||
result = spec
|
||||
|
@ -158,6 +158,7 @@ module Vagrant
|
|||
require: opts[:require],
|
||||
sources: opts[:sources],
|
||||
env_local: !!opts[:env_local],
|
||||
env_vars: opts[:env_vars],
|
||||
installed_gem_version: result.version.to_s
|
||||
)
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ module Vagrant
|
|||
"require" => opts[:require] || "",
|
||||
"sources" => opts[:sources] || [],
|
||||
"installed_gem_version" => opts[:installed_gem_version],
|
||||
"env_vars" => opts[:env_vars],
|
||||
"env_local" => !!opts[:env_local]
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ module VagrantPlugins
|
|||
plugin_name = env[:plugin_name]
|
||||
sources = env[:plugin_sources]
|
||||
version = env[:plugin_version]
|
||||
env_vars = env[:env_vars]
|
||||
env_local = env[:plugin_env_local]
|
||||
|
||||
# Install the gem
|
||||
|
@ -33,6 +34,7 @@ module VagrantPlugins
|
|||
require: entrypoint,
|
||||
sources: sources,
|
||||
verbose: !!env[:plugin_verbose],
|
||||
env_vars: env_vars,
|
||||
env_local: env_local
|
||||
)
|
||||
|
||||
|
|
|
@ -12,13 +12,21 @@ module VagrantPlugins
|
|||
LOCAL_INSTALL_PAUSE = 3
|
||||
|
||||
def execute
|
||||
options = { verbose: false }
|
||||
options = {
|
||||
verbose: false,
|
||||
env_vars: {},
|
||||
}
|
||||
|
||||
opts = OptionParser.new do |o|
|
||||
o.banner = "Usage: vagrant plugin install <name>... [-h]"
|
||||
o.separator ""
|
||||
build_install_opts(o, options)
|
||||
|
||||
o.on("-D VARIABLE=VALUE", "--define VARIABLE=VALUE", "Set environment variable") do |e|
|
||||
name, value = e.split('=', 2)
|
||||
options[:env_vars][name] = value
|
||||
end
|
||||
|
||||
o.on("--local", "Install plugin for local project only") do |l|
|
||||
options[:env_local] = l
|
||||
end
|
||||
|
@ -61,6 +69,7 @@ module VagrantPlugins
|
|||
plugin_version: info[:version],
|
||||
plugin_sources: info[:sources] || Vagrant::Bundler::DEFAULT_GEM_SOURCES.dup,
|
||||
plugin_name: name,
|
||||
env_vars: options[:env_vars],
|
||||
plugin_env_local: true
|
||||
)
|
||||
end
|
||||
|
@ -73,6 +82,7 @@ module VagrantPlugins
|
|||
plugin_sources: options[:plugin_sources],
|
||||
plugin_name: name,
|
||||
plugin_verbose: options[:verbose],
|
||||
env_vars: options[:env_vars],
|
||||
plugin_env_local: options[:env_local]
|
||||
)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue