Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add mirror support. #2062

Closed
wants to merge 2 commits into from

4 participants

@mkristian

each uri to a repository can be replaced by an mirror uri via the bundler configuration. add mirrors like this

bundle config mirror.http://rubygems.org http://localhost:8081/nexus/content/repositories/rubygems.org
@mkristian

I am currently working on some ruby support for nexus https://github.com/sonatype/nexus-ruby-support

this plugin allows to mirror/proxy the gem repository from rubygems.org - that works fine with gem command itself, just replace rubygems.org with the mirror with gem sources. but with bundler there is no way to use that nexus-proxy without changing the Gemfile. this patch allows to tell bundler to use a mirror-uri instead of the uri from the Gemfile. that works fine with current state of the nexus-plugin (via the full index fallback) with keeping the Gemfile as it is.

this patch is also useful for other project setting up an mirror of rubygems.org and for the nexus plugin it feels essential to be able to use bundler with mirrors/proxies.

any thoughts ?

@mkristian

hoops - no tests/specs. they will come !

@travisbot

This pull request passes (merged b31f8371 into 8acc82f).

@trhodeos

Recently started using the nexus rubygems proxy. It would be awesome to get this merged!

@indirect
Owner

@tylerrhodes want to write specs for it? :)

mkristian added some commits
@mkristian mkristian add mirror support. each uri to a repository can be replaced by an
mirror uri via the bundler configuration. add mirrors like this
$ bundle config mirror.http://rubygems.org http://localhost:8081/nexus/content/repositories/rubygems.org
7f1f861
@mkristian mkristian specs for mirror config 06073a4
@mkristian

#2366 seems to be more "refined" to conventions. did not see it before I pushed my recent changes. but it would be nice to get the pull request in. currently I am using the monkey-patched version of bundler from https://github.com/sonatype/nexus-ruby-support/tree/master/nexus-gem - it is really hard to switch from "bundle install" to "nbundle install" (old habits die hard). the nexus gem proxy is getting close to a working state, too.

@mkristian

my specs fail on ruby18 - I stop this here in favour of #2366

@mkristian mkristian closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 7, 2013
  1. @mkristian

    add mirror support. each uri to a repository can be replaced by an

    mkristian authored
    mirror uri via the bundler configuration. add mirrors like this
    $ bundle config mirror.http://rubygems.org http://localhost:8081/nexus/content/repositories/rubygems.org
  2. @mkristian

    specs for mirror config

    mkristian authored
This page is out of date. Refresh to see the latest.
View
5 lib/bundler/fetcher.rb
@@ -1,4 +1,5 @@
require 'bundler/vendored_persistent'
+require 'bundler/rubygems_mirror'
module Bundler
@@ -56,8 +57,8 @@ def download_gem_from_uri(spec, uri)
end
def initialize(remote_uri)
- @remote_uri = remote_uri
- @public_uri = remote_uri.dup
+ @remote_uri = RubygemsMirror.to_uri(remote_uri)
+ @public_uri = @remote_uri.dup
@public_uri.user, @public_uri.password = nil, nil # don't print these
if USE_PERSISTENT
@connection ||= Net::HTTP::Persistent.new 'bundler', :ENV
View
2  lib/bundler/rubygems_integration.rb
@@ -2,6 +2,7 @@
# rubygems master requires UI for ConfigFile but doesn't require it
require 'rubygems/user_interaction'
require 'rubygems/config_file'
+require 'bundler/rubygems_mirror'
module Bundler
class RubygemsIntegration
@@ -163,6 +164,7 @@ def build_gem(gem_dir, spec)
end
def download_gem(spec, uri, path)
+ uri = RubygemsMirror.to_uri(uri)
Gem::RemoteFetcher.fetcher.download(spec, uri, path)
end
View
27 lib/bundler/rubygems_mirror.rb
@@ -0,0 +1,27 @@
+module Bundler
+ class RubygemsMirror
+
+ private
+
+ def self.mirrors
+ @mirrors ||= Bundler.settings.all.inject({}) do |h, k|
+ if k =~ /^mirror./
+ uri = add_slash(k.sub(/^mirror./, ''))
+ h[uri] = URI.parse(add_slash(Bundler.settings[k]))
+ end
+ h
+ end
+ end
+
+ def self.add_slash(uri)
+ uri = uri.to_s
+ uri =~ %r{/$} ? uri : uri + '/'
+ end
+
+ public
+
+ def self.to_uri(uri)
+ mirrors[add_slash(uri)] || uri
+ end
+ end
+end
View
7 man/bundle-config.ronn
@@ -132,3 +132,10 @@ accidental locking to a different branch.
Finally, Bundler also ensures that the current revision in the
`Gemfile.lock` exists in the local git repository. By doing this, Bundler
forces you to fetch the latest changes in the remotes.
+
+## MIRRORS OF GEM REPOSITORIES
+
+each uri to a repository can be replaced by an mirror uri. example
+
+ bundle config mirror.http://rubygems.org http://localhost:8081/nexus/content/ruby/rubygems.org
+
View
37 spec/install/gems/simple_case_spec.rb
@@ -1,6 +1,43 @@
require "spec_helper"
describe "bundle install with gem sources" do
+ describe "with mirror settings" do
+
+ it 'configures mirrors' do
+ config("BUNDLE_MIRROR__HTTPS://RUBYGEMS.ORG" => "file://repo1/",
+ "BUNDLE_MIRROR__HTTP://RUBYGEMS.ORG/" => "file://repo2",
+ "BUNDLE_MIRROR__HTTPS://RUBYGEMS.ORG/" => "file://repo3/",
+ "BUNDLE_MIRROR__HTTP://RUBYGEMS.ORG" => "file://repo4")
+
+ gemfile # Bundler.settings needs a Gemfile
+
+ expect(Bundler::RubygemsMirror.to_uri('http://rubygems.org').to_s).to eq('file://repo4/')
+ expect(Bundler::RubygemsMirror.to_uri('https://rubygems.org/').to_s).to eq('file://repo3/')
+ end
+
+ it "creates a Gemfile.lock" do
+ config("BUNDLE_MIRROR__HTTPS://RUBYGEMS.ORG" => "file://#{gem_repo1}/")
+ install_gemfile <<-G
+ source 'https://rubygems.org'
+ gem "rack"
+ G
+
+ expect(bundled_app('Gemfile.lock')).to exist
+ end
+
+ it "should fail with wrong mirror" do
+ config("BUNDLE_MIRROR__HTTPS://RUBYGEMS.ORG" => "file://me.and.the.corner")
+ install_gemfile <<-G, :expect_err => true
+ source 'https://rubygems.org'
+ gem "rack"
+ G
+
+ expect(out).to match(/Could not fetch specs from file:\/\/me.and.the.corner/)
+ expect(bundled_app('Gemfile.lock')).to_not exist
+ end
+
+ end
+
describe "the simple case" do
it "prints output and returns if no dependencies are specified" do
gemfile <<-G
Something went wrong with that request. Please try again.