总结

总结

我有一台 Ubuntu 16.04 机器位于代理后面。从这台机器上,我可以使用http_proxyhttps_proxy环境变量按预期使用代理。但是,当启动新的 vagrant box 时,其配置脚本会尝试 HTTP 访问并失败。

显然,这个问题的答案是按照以下方法安装 vagrant-proxyconf 插件这个问题

vagrant plugin install vagrant-proxyconf

有了这个,我遇到了一个已知问题我成功修补了它,但即便如此,我还是遇到了更多问题,显然与 HTTP 相关:

$ vagrant plugin install vagrant-proxyconf
Installing the 'vagrant-proxyconf' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:

Net::HTTPForbidden: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
... <snip - see rendered HTML> ...
</html>


Warning: this Gemfile contains multiple primary sources. Using `source` more than once without a block is a security risk, and may result in installing unexpected gems. To resolve this warning, use a block to indicate which gems should come from the secondary source. To upgrade this warning to an error, run `bundle config disable_multisource true`.
$

我保存了此错误的 HTML 输出并在 Firefox 中呈现:

在此处输入图片描述

这似乎表明 GET http://gems.hashicorp.com/quick/Marshal.4.8/io-console-0.4.3.gemspec.rz由于某种原因,我的公司网络拒绝了该 URL,但我能够wget从同一台机器毫无问题地访问该 URL。

因此,我的下一步是尝试手动安装所需的 ruby​​ 宝石。在上述错误之前,我遇到了与宝石相同的问题bigdecimal-1.2.6。在这种情况下,我能够成功手动安装宝石,如下所示:

 sudo -E gem install bigdecimal -v 1.2.6

然而io-console-0.4.3gem 的情况就不同了。我可以手动安装 0.4.2 和 0.4.5 版本,但 0.4.3 版本rubygems.org 上不可用

总结

我该如何安装io-console-0.4.3gem?或者是否可以以某种方式破解依赖版本并改用 0.4.5?

答案1

在仔细阅读 HTTP 错误后,我意识到这是失败的,因为我的公司防火墙阻止了 HTTP 请求User-Agent: bundler/1.11.2 ...。我能够通过curl(有效) 与curl -A "bundler/1.11.2 ...(无效) 来确认这一点。


管理解决方案是配置公司防火墙以允许捆绑器作为用户代理。我提交了一个内部案件 - 我们将看看结果如何...


临时的技术解决方案是修补捆绑器源,以便它使用更可接受的用户代理。

  1. bundler-hack-useragent.patch创建包含以下内容的文件:
diff --git a/fetcher.rb b/fetcher.rb
index aaf4679..e4738f4 100644
--- a/fetcher.rb
+++ b/fetcher.rb
@@ -238,7 +238,8 @@ module Bundler
         end

         con.read_timeout = Fetcher.api_timeout
-        con.override_headers["User-Agent"] = user_agent
+#        con.override_headers["User-Agent"] = user_agent
+        con.override_headers["User-Agent"] = 'curl/7.19.7'
         con.override_headers["X-Gemfile-Source"] = @remote.original_uri.to_s if @remote.original_uri
         con
       end
  1. 应用补丁:
sudo patch --directory /usr/lib/ruby/vendor_ruby/bundler < bundler-hack-useragent.patch

这会将 curl 硬编码为中的用户代理/usr/lib/ruby/vendor_ruby/bundler/fetcher.rb。curl 可与我的公司防火墙配合使用,但您可能需要选择其他东西。

相关内容