how to build a transparent private gem source server - ruby

My connection to default gem source server http://rubygems.org/ is slow. So I am looking for a method to build a private gem server on a machine which I have fast connection to. I have some questions after reading gems doc:
If I have multiple gem sources , what is the order which source is used when running gem install xxx?
Will any method documented in http://docs.rubygems.org/read/chapter/18 help build a transparent gem server? "Transparent" means I need this only one gem server in my gem sources, and when I request a gem from this server, it will first serve the gem from cache. If the gem is not in cache yet, the server will try to download it from http://rubygems.org/, serve and cache it.
If the answer for question 2 is "No", how can I build a transparent gem source server?

I'd suggest just installing the pre-release bundler, which is several orders of magnitude faster due to major architectural changes. It's not just your connection to rubygems that is slow; it's that painful for all of us ;) gem install bundler --pre will give you a much faster bundler.
That said, if you really want a loca gem server, try Gem in a box:
https://github.com/cwninja/geminabox

Here are a few projects that are specifically made to run a RubyGems.org mirror:
https://github.com/YorickPeterse/gem-mirror
https://github.com/rubygems/rubygems-mirror

Related

Where are gem installs coming from?

I am wondering, while I'm sifting through samples, how I locate the source library when installing gems. For example, I have
require 'oauth2'
and to install, I run
gem install oauth2
What repository is pulled from for gem installs? I want to use reflection to reverse engineer some of the calls in the samples.
By default gem pulls from Rubygems, the main gem repository, but you can install from anywhere if you give it a URL or use the --source option to specify an alternate source. Some prefer to use private gem hosting for their dependencies.
Why not use a Gemfile to manage your dependencies? It makes it a lot more clear:
source 'https://rubygems.org/'
gem 'oauth2'
Then you install:
bundle install
Then you can see where it got installed:
bundle show oauth2
From there you can look at the source. You can also look at the gem listing page for oauth2 where links to documentation and source are provided.
There are a few useful options for looking at source code for ruby gems.
As #tadman has mentioned you generally can expect the default gem source to be hosted at https://rubygems.org and using Bundler is also highly recommended.
In many cases the open source code will be hosted on https://github.com. I tend to prefer to fork the gem source and download my fork locally where I can analyze it in my editor without fear of accidentally breaking anything since your forked repo will contain the full git history/repo etc.
If you're new to ruby, I would highly recommend you use a ruby version manager, i.e. RVM or perhaps RBENV, although I tend to find RVM a bit simpler and less problematic.
My other personal favorite ruby code hacking/inspecting tool is PRY

Can I download all of rubygems.org?

I have an air gapped network that I use for development. Is there any way that I can easily download a snapshot of rubygems.org to import to the gem server running on said network?
I saw the help article on the rubygems site about how to get specific gems with no network:
$ gem install rails -i repo --no-rdoc --no-ri
I want to try to get everything at once. Any idea how big this would be even without the rdoc and ri?
I have not ever used it, but googling, this tool claims to be able to do that:
https://github.com/rubygems/rubygems-mirror
you can build a gem server at your server.
I think this article can help you.
http://guides.rubygems.org/run-your-own-gem-server/

Local gem install vs running setup.rb

What is the difference between a ruby library installed from a tarball versus through a gem install?
My machine can't connect to rubygems.org because of a university proxy, so all my installations happen locally. I have some gems that I've installed using a gem local install, and others where I've downloaded a tarball and run setup.rb or some such. In my newbie-ish state when messing around with Ruby I wasn't too phased about this inconsistency, but it bothers me now.
I assume rubygems is the preferred method, but I'd like to understand the exact pitfalls so that I can know what to watch out for when I try clean out my machine.
The most important difference is that Ruby extensions installed without the gem mechanism cannot be easily uninstalled or updated (except they provide their own mechanism for that). Automatic installation of dependencies is also largely simplified with gems.
If you are behind a proxy, you can tell gem to use that proxy as well, e.g.
gem install foo --http-proxy http://192.168.0.1:81
or define the environment variable HTTP_PROXY like
export HTTP_PROXY=http://192.168.0.1:81
Look into your browser/network settings to find the proxy address.

Where can I install gems from when rubygems.org is down?

Currently Rubygems.org is down - the website reports an error, and a few gem install tasks are returning 500 errors.
Is there a mirror / backup source of gem files, or is rubygems.org essentially a single point of failure within the ruby gem installation process ?
As per several folks on Twitter, add this to your Gemfile:
source 'https://production.cf.rubygems.org'
Also, if you're not using Bundler you can just run:
$ gem source -a 'https://production.cf.rubygems.org'
For the record, the folks on Twitter include:
laizer, iltempo, and jimneath. Major thanks to them for saving my morning :)
same issue affecting all git push to Heroku
solved the same was by changing the source on GemFile to the http://production.cf.rubygems.org
Mirror for Asia/Pacific Region: https://ruby.taobao.org/ (recommended, high availability, syncing every 15 min)
Other mirrors:
https://gems.cloudafrica.net/
https://tokyo-m.rubygems.org/
Having experienced my share of flaky network connections I find I've most often got the .gem files I need on my system, it's just a matter of finding them and installing them locally.
Use the find command to find local .gem files and install them directly with gem install [file].
find ~/.rbenv/versions -type f -name 'minitest*.gem'
That works for individual gems but if you need to install dependencies, etc. it can be a pain.
If you've got the gem on some other computer, or on other rubies on the same
computer, use
gem server
to create your own gem server.
Otherwise, download the source code for the gem in question from github, and do
the rake task to build the gem.

How many times was a Ruby gem installed via `gem install` or `gem update`

I am trying to find out how many times a gem was installed via gem install or gem update.
For example, Watir 1.6.2:
it was installed 97 times via gemcutter (http://gemcutter.org/gems/watir/versions/1.6.2)
it is downloaded 4,027 times from http://rubyforge.org/frs/?group_id=104
I have been told that 4,027 does not include installs made via gem install or gem update. Is that information correct? If yes, where can I find the numbers for gem install and gem update? I have looked everywhere I could think of at rubyforge, but no luck.
Yup, I hope to migrate all the download stats over to gemcutter... although we're going to have to do that carefully since there are about 50M rows. That said, here's what I've got for watir-1.6.2 on RubyForge:
gforge=> select count(*) from gem_downloads where gem_name = 'watir-1.6.2.gem';
count
-------
29169
(1 row)
With gemcutter being the new canonical source for gems, you'll have better luck with these statistics in the future. All future gem installs will go through gemcutter. Unfortunately, I'm pretty sure the old rubyforge download numbers are just web downloads; they don't include gem install or gem update stats.
I'm not sure if the gem install stats exist in any shape or form from the old rubyforge platform, but the person to email would be Tom Copeland.

Resources