Merge pull request #8442 from chrisroberts/fix/bundler-notify-source

Validate plugin sources and report errors if detected.
This commit is contained in:
Chris Roberts 2017-04-05 13:24:54 -07:00 committed by GitHub
commit 869f87d55f
6 changed files with 67 additions and 10 deletions

View File

@ -19,13 +19,15 @@ module Vagrant
# all Vagrant-installed plugins.
class Bundler
# Location of HashiCorp gem repository
HASHICORP_GEMSTORE = "https://gems.hashicorp.com/".freeze
# Default gem repositories
DEFAULT_GEM_SOURCES = [
"https://rubygems.org/".freeze,
"https://gems.hashicorp.com/".freeze
HASHICORP_GEMSTORE
].freeze
HASHICORP_GEMSTORE = "https://gems.hashicorp.com/".freeze
def self.instance
@bundler ||= self.new
end
@ -262,6 +264,9 @@ module Vagrant
@logger.debug("Adding source - #{src}")
Gem.sources << src
end
validate_configured_sources!
source_list.values.each{|srcs| srcs.delete_if{|src| default_sources.include?(src)}}
installer_set.prefer_sources = source_list
@ -321,6 +326,27 @@ module Vagrant
list.values
end
# Iterates each configured RubyGem source to validate that it is properly
# available. If source is unavailable an exception is raised.
def validate_configured_sources!
Gem.sources.each_source do |src|
begin
src.load_specs(:released)
rescue Gem::Exception => source_error
if ENV["VAGRANT_ALLOW_PLUGIN_SOURCE_ERRORS"]
@logger.warn("Failed to load configured plugin source: #{src}!")
@logger.warn("Error received attempting to load source (#{src}): #{source_error}")
@logger.warn("Ignoring plugin source load failure due user request via env variable")
else
@logger.error("Failed to load configured plugin source `#{src}`: #{source_error}")
raise Vagrant::Errors::PluginSourceError,
source: src.uri.to_s,
error_msg: source_error.message
end
end
end
end
# Generate the builtin resolver set
def generate_builtin_set
builtin_set = BuiltinSet.new

View File

@ -596,6 +596,10 @@ module Vagrant
error_key(:plugin_init_error)
end
class PluginSourceError < VagrantError
error_key(:plugin_source_error)
end
class PushesNotDefined < VagrantError
error_key(:pushes_not_defined)
end

View File

@ -3,10 +3,7 @@ module VagrantPlugins
module Command
module MixinInstallOpts
def build_install_opts(o, options)
options[:plugin_sources] = [
"https://rubygems.org",
"https://gems.hashicorp.com",
]
options[:plugin_sources] = Vagrant::Bundler::DEFAULT_GEM_SOURCES.dup
o.on("--entry-point NAME", String,
"The name of the entry point file for loading the plugin.") do |entry_point|

View File

@ -43,7 +43,11 @@ module VagrantPlugins
# Clear the sources so that installation uses custom sources
old_sources = Gem.sources
Gem.sources = Gem.default_sources
Gem.sources << "https://gems.hashicorp.com"
Vagrant::Bundler::DEFAULT_GEM_SOURCES.each do |source|
if !Gem.sources.include?(source)
Gem.sources << source
end
end
# Use a silent UI so that we have no output
Gem::DefaultUserInteraction.use_ui(Gem::SilentUI.new) do

View File

@ -1020,6 +1020,16 @@ en:
You can however, install a plugin with the same name to replace
these plugins. User-installed plugins take priority over
system-installed plugins.
plugin_source_error: |-
Vagrant failed to load a configured plugin source. This can be caused
by a variety of issues including: transient connectivity issues, proxy
filtering rejecting access to a configured plugin source, or a configured
plugin source not responding correctly. Please review the error message
below to help resolve the issue:
%{error_msg}
Source: %{source}
pushes_not_defined: |-
The Vagrantfile does not define any 'push' strategies. In order to use
`vagrant push`, you must define at least one push strategy:
@ -1985,7 +1995,7 @@ en:
untar_failure: |-
The box failed to unpackage properly. Please verify that the box
file you're trying to add is not corrupted and that enough disk space
is available and then try again.
is available and then try again.
The output from attempting to unpackage (if any):
%{output}

View File

@ -66,7 +66,14 @@ a scripting environment in order to set the directory that Vagrant sees.
## `VAGRANT_DOTFILE_PATH`
`VAGRANT_DOTFILE_PATH` can be set to change the directory where Vagrant stores VM-specific state, such as the VirtualBox VM UUID. By default, this is set to `.vagrant`. If you keep your Vagrantfile in a Dropbox folder in order to share the folder between your desktop and laptop (for example), Vagrant will overwrite the files in this directory with the details of the VM on the most recently-used host. To avoid this, you could set `VAGRANT_DOTFILE_PATH` to `.vagrant-laptop` and `.vagrant-desktop` on the respective machines. (Remember to update your `.gitignore`!)
`VAGRANT_DOTFILE_PATH` can be set to change the directory where Vagrant stores
VM-specific state, such as the VirtualBox VM UUID. By default, this is set to
`.vagrant`. If you keep your Vagrantfile in a Dropbox folder in order to share
the folder between your desktop and laptop (for example), Vagrant will overwrite
the files in this directory with the details of the VM on the most recently-used
host. To avoid this, you could set `VAGRANT_DOTFILE_PATH` to `.vagrant-laptop`
and `.vagrant-desktop` on the respective machines. (Remember to update your
`.gitignore`!)
## `VAGRANT_HOME`
@ -128,6 +135,15 @@ Note that any `vagrant plugin` commands automatically do not load any
plugins, so if you do install any unstable plugins, you can always use
the `vagrant plugin` commands without having to worry.
## `VAGRANT_ALLOW_PLUGIN_SOURCE_ERRORS`
If this is set to any value, then Vagrant will not error when a configured
plugin source is unavailable. When installing a Vagrant plugin Vagrant
will error and halt if a plugin source is inaccessible. In some cases it
may be desirable to ignore inaccessible sources and continue with the
plugin installation. Enabling this value will cause Vagrant to simply log
the plugin source error and continue.
## `VAGRANT_NO_PARALLEL`
If this is set, Vagrant will not perform any parallel operations (such as