Merge pull request #5910 from mitchellh/sethvargo/preserve_original_env
Add Vagrant.original_env and break out of bundler in subprocess
This commit is contained in:
commit
912a878840
|
@ -227,6 +227,22 @@ module Vagrant
|
|||
requirements: requirements.join(", "),
|
||||
version: VERSION
|
||||
end
|
||||
|
||||
# This allows plugin developers to access the original environment before
|
||||
# Vagrant even ran. This is useful when shelling out, especially to other
|
||||
# Ruby processes.
|
||||
#
|
||||
# @return [Hash]
|
||||
def self.original_env
|
||||
{}.tap do |h|
|
||||
ENV.each do |k,v|
|
||||
if k.start_with?("VAGRANT_OLD_ENV")
|
||||
key = k.sub(/^VAGRANT_OLD_ENV_/, "")
|
||||
h[key] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Default I18n to load the en locale
|
||||
|
|
|
@ -91,6 +91,15 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# Reset the Bundler environment back - this is required for anyone who
|
||||
# is not using the official Vagrant installers and is running Vagrant
|
||||
# via bundler
|
||||
if defined?(Bundler::ORIGINAL_ENV)
|
||||
Bundler::ORIGINAL_ENV.each do |k, v|
|
||||
process.environment[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
# Set the environment on the process if we must
|
||||
if @options[:env]
|
||||
@options[:env].each do |k, v|
|
||||
|
|
|
@ -98,4 +98,23 @@ describe Vagrant do
|
|||
to raise_error(Vagrant::Errors::VagrantVersionBad)
|
||||
end
|
||||
end
|
||||
|
||||
describe "original_env" do
|
||||
before do
|
||||
ENV["VAGRANT_OLD_ENV_foo"] = "test"
|
||||
ENV["VAGRANT_OLD_ENV_bar"] = "test"
|
||||
end
|
||||
|
||||
after do
|
||||
ENV["VAGRANT_OLD_ENV_foo"] = "test"
|
||||
ENV["VAGRANT_OLD_ENV_bar"] = "test"
|
||||
end
|
||||
|
||||
it "should return the original environment" do
|
||||
expect(Vagrant.original_env).to eq(
|
||||
"foo" => "test",
|
||||
"bar" => "test",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,15 @@ Vagrant has a set of environmental variables that can be used to
|
|||
configure and control it in a global way. This page lists those environmental
|
||||
variables.
|
||||
|
||||
## VAGRANT\_CHECKPOINT\_DISABLE
|
||||
## VAGRANT\_DEBUG\_LAUNCHER
|
||||
|
||||
For performance reasons, especially for Windows users, Vagrant uses a static
|
||||
binary to launch the actual Vagrant process. If you have _very_ early issues
|
||||
when launching Vagrant from the official installer, you can specify the
|
||||
`VAGRANT_DEBUG_LAUNCHER` environment variable to output debugging information
|
||||
about the launch process.
|
||||
|
||||
## VAGRANT\_CHECKPOINT\_DISABLE
|
||||
|
||||
Vagrant does occasional network calls to check whether the version of Vagrant
|
||||
that is running locally is up to date. We understand that software making remote
|
||||
|
|
Loading…
Reference in New Issue