Appendix A. Running Your Own Gem Server

Rubygems is a great system for maintaining libraries for use with Ruby. It makes it simple to upgrade to new versions of Rails, Capistrano, Mongrel, etc. with a single command.

However, if you use a default Rubygems configuration, each time a developer installs a gem they fetch it from a repository on the Internet. This could result in different developers ending up with different versions of a single gem, depending on which was available when they performed the installation. While this might not make a difference in some cases, with gems like Rails (which change radically between versions), it could result in an application working on one machine and not on another.

Another issue is finding the more obscure gems, which reside in non-standard repositories. In this case, configuring the developers' machines for each non-standard repository can be painful, particularly if you use several such repositories.

The simplest way to give developers access to a consistent repository with all the gems they require is to set up your own gem server. There are two methods for doing this:

  1. If you have a machine with all the required gems installed, you can use the built-in gem_server command on that machine to serve up its gems to others.
  2. You can serve gems out of Apache by manually setting up a gem repository. This gives you more control over which gems are presented to client machines, but is harder to maintain.

Both techniques are covered in the next two sections.

Serving Installed Gems

To explain how this technique is applied, let's remind ourselves of Acme's setup. They have a production machine to which their applications are deployed, which contains most of the gems required by the developers (see, Chapter 3). Note that I said most, as Capistrano is not installed: technically, it is only required on the developer machines. However, to be able to serve it from the production machine, it needs to be installed on that machine too. (The gem_server command only offers up gems installed on the machine where it is running.) They install Capistrano (and its dependencies) with the following:

$ gem install capistrano -y

Next, they can make the gems on the production machine available via HTTP using this simple command:

$ gem_server
[2007-07-03 21:34:38] INFO WEBrick 1.3.1
[2007-07-03 21:34:38] INFO ruby 1.8.4 (2005-12-24) [i486-linux]
[2007-07-03 21:34:38] INFO WEBrick::HTTPServer#start: pid=7543 port=8808

As you can see from the output, this starts a WEBrick server on the default port 8808 (gem_server -p N can be used to start the server on port N). Browsing to http://<server address>:8808/ (replacing<server address> with the IP address or domain name of the production machine) will now yield the documentation for the gems on the server. We had a brief look at this feature in the section: A Note on Rails Documentation in Chapter 3. If the gems were installed without documentation (using the --no-rdoc switch), you will just get a list of the installed gems without documentation links.

But there is another hidden aspect to the gem server: if you browse to the same address with the path /gems/, i.e. to http://<server address>:8808/gems/, you'll see the gems installed on the server displayed as links.

Serving Installed Gems

This indicates that the gem server is presenting its installed gems over HTTP. Once this is up and running, you can now use the gem command line tool on a developer machine to list the gems on the gem server:

$ gem list --remote --source http://192.168.13.131:8808
Bulk updating Gem source index for: http://192.168.13.131:8808
*** REMOTE GEMS ***
actionmailer (1.3.3)
Service layer for easy email delivery and testing.
... etc. ...

(Replacing the IP address of the --source URL with the one for your server, of course.)

You can also install a gem from your own gem server with:

$ sudo gem install rails -y --source http://192.168.13.131:8808
Password:
Bulk updating Gem source index for: http://192.168.13.131:8808
Successfully installed rails-1.2.3

Setting Your Gem Server as the Default

If you want to configure gem to use your gem server as the default repository, create a file called .gemrc in your home directory (/home/username on Linux, Documents and SettingsUsername on Windows). Next, add this single line (it's a YAML file):

gem: --source http://192.168.13.131:8808 -y

Remember to replace the --source URL with the one appropriate to your server. Note that I also added the -y switch to ensure that all dependencies are installed each time you install a gem. Now, each time you install a gem, your intranet gem server will be used as the default repository, rather than the public Internet gem repository.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.133.233