ã¡ã¿ãã¼ã¿ã®åå¾ã¯*_proxyç°å¢å¤æ°ãè¦ãã®ã¿ãªã®ã ããgemã®ãã¦ã³ãã¼ãã¯rubygemãå©ç¨ãã¦ãã¦ããã®ã§ãç°å¢å¤æ°ã ãã§ãªã.gemrcã®http_proxyã®è¨å®ãè¦ã¦ãã¾ããããã«ã.gemrcã®æ¹ãåªå ãã¦ãã¾ãã
ãã®ããã.gemrcã«ééã£ãè¨å®ãå ¥ãã¦ããã¨ç°å¢å¤æ°ã®æ¹ã«æ£ããè¨å®ããã¦ãã¦ããã¡ã¿ãã¼ã¿ã®ã¿åå¾ãã¦gemã¯åå¾ã§ããªãã¨ãããããªãã¨ã«ãªã£ã¦ãã¾ãã
ä¾ãã°ãproxyã®ãªãç°å¢ã§.gemrcã«
http_proxy: http://hogehoge:8080
ã¨åå¨ããªãproxyã®è¨å®ããã¦ãbundle installãå®è¡ããã¨
$ bundle install Fetching gem metadata from https://rubygems.org/........... Fetching version metadata from https://rubygems.org/... Fetching dependency metadata from https://rubygems.org/.. Using rake 10.4.2
ã¨ãã¾ããã£ã¦ããããã«è¦ãã¦ãgemãã¤ã³ã¹ãã¼ã«ãã段éã«ãªãã¨ä»¥ä¸ã®ãããªã¨ã©ã¼ã«ãªãã
Gem::RemoteFetcher::UnknownHostError: no such name (https://rubygems.org/gems/faker-1.1.2.gem) An error occurred while installing faker (1.1.2), and Bundler cannot continue. Make sure that `gem install faker -v '1.1.2'` succeeds before bundling.
ã³ã¼ãçã«ã¯ã ããããããªæãã(Bundler v1.10.0)
ã¡ã¿ãã¼ã¿ã®åå¾æã«ã¯lib/bundler/fetcher.rbã®fetch_specã¡ã½ããã®ä¸ã§ã
def fetch_spec(spec) spec = spec - [nil, 'ruby', ''] spec_file_name = "#{spec.join '-'}.gemspec" uri = URI.parse("#{remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz") if uri.scheme == 'file' Bundler.load_marshal Gem.inflate(Gem.read_binary(uri.path)) elsif cached_spec_path = gemspec_cached_path(spec_file_name) Bundler.load_gemspec(cached_spec_path) else Bundler.load_marshal Gem.inflate(downloader.fetch uri) end rescue MarshalError raise HTTPError, "Gemspec #{spec} contained invalid data.\n" \ "Your network or your gem server is probably having issues right now." end
downloader.fetchãã¦ãlib/bundler/fetcher/downloader.rbã®fetchã¡ã½ããã®ä¸ã§
def fetch(uri, counter = 0) raise HTTPError, "Too many redirects" if counter >= redirect_limit response = request(uri)
requestã¡ã½ãããå¼ã³ãrequestã¡ã½ããã®ä¸ã§
def request(uri) Bundler.ui.debug "HTTP GET #{uri}" req = Net::HTTP::Get.new uri.request_uri
Net::HTTPãå©ç¨ãã¦ããã®ã§*_proxyç°å¢å¤æ°ãè¦ããã¨ã«ãªãã
gemã®ã¤ã³ã¹ãã¼ã«ã®å ´åã¯lib/bundler/rubygems_integration.rbã®download_gemã¡ã½ããã®ä¸ã§
def download_gem(spec, uri, path) uri = Bundler.settings.mirror_for(uri) fetcher = Gem::RemoteFetcher.new(configuration[:http_proxy]) fetcher.download(spec, uri, path) end
configuration[:http_proxy]ãå¼æ°ã«Gem::RemoteFetcherãçæãã¦ãããconfigurationã¯gemã®è¨å®ãã¡ã¤ã«(.gemrc)ã§ãããGem::RemoteFetcherã®ã³ã³ã¹ãã©ã¯ã¿ã¯å¼æ°ã¨ãã¦proxyãã¨ãã*_proxyç°å¢å¤æ°ããåªå ãããã