Automating gem installs?

J

Justin Hahn

I'm trying to setup an automated build system for all of our upstream
binary dependencies (that we don't get from our OS). Since we track a
newer ruby than most of our machines ship with, this means building ruby
and installing gems. For the most part this works fine, except when I
need to install a gem like mongrel that has several versions.


For example, if I run 'gem install -y mongrel' from my Makefile, I get
an error like this (since stdin isn't attached):


Select which gem to install for your platform (x86_64-linux)
1. mongrel 1.1 (ruby)
2. mongrel 1.1 (mswin32)
3. mongrel 1.0.4 (mswin32)
4. mongrel 1.0.4 (ruby)
5. Skip this gem
6. Cancel installation
ERROR: While executing gem ... (NoMethodError)
undefined method `strip' for nil:NilClass

Unfortunately, the list entries aren't even stable -- sometimes option
#1 is the mswin32 and sometimes it's the ruby choice. So I can't even do
something nasty like "echo 1 | gem install -y mongrel" and be assured of
getting the right thing.

Is there any way to tell gem, from the commandline, precisely which gem
I want? The documentation seems sparse, and I haven't had the time to go
digging through gem's source code yet. (My hope is that this is any easy
answer...)
 
R

Ryan Davis

Is there any way to tell gem, from the commandline, precisely which
gem
I want? The documentation seems sparse, and I haven't had the time
to go
digging through gem's source code yet. (My hope is that this is any
easy
answer...)

not yet... but we're getting there. I've got this requirement as well
and I sit next to eric all the time. don't worry. :)
 
N

nate

Justin said:
I'm trying to setup an automated build system for all of our upstream
binary dependencies (that we don't get from our OS). Since we track a
newer ruby than most of our machines ship with, this means building ruby
and installing gems. For the most part this works fine, except when I
need to install a gem like mongrel that has several versions.


I do this the hard way probably, but I convert gems into RPMs and then
push the RPMs to the systems. It takes quite a while but I can be sure
of:

(assuming your using Linux and an RPM-based distribution)
- no external dependencies(e.g. servers calling to the internet to
download something)
- one package manager to query for all files on the system
- more compatible with our automated management system(www.cfengine.org)
- installs exactly the versions we use, never have to worry about the
wrong version getting installed by accident.
- don't need development stuff installed to install the gems
(though we still have development stuff installed, at some point
I expect we'll remove non essentials from most systems)

Currently I maintain 29 gems using this method. If your interested I
can send you a short little HOWTO doc I wrote so when I go through
this painful process I remember all of the commands I need.

Basically what I do is:
- build a list of files in /usr
- install the gem(one gem at a time!), for me I resolve dependencies
manually, and download the gems direct from
http://rubyforge.vm.bytemark.co.uk/gems/
- build a list of files again in /usr
- run a diff between the two lists to find new files(this is a fairly
complicated command, the one I often forget:
for i in `diff -u /tmp/usr-before-gd.log /tmp/usr-after-gd.log | grep ^+ |
grep /usr/ | sed s'/+//'g`; do [ -d $i ] || echo $i ;done >/tmp/new.txt

- tar those new files up into a tarball
- copy tarball to debian/ubuntu system (or some system that has alien
installed)
- run alien in prepare mode, edit the SPEC file, change values as needed(I
add descriptions and stuff so we can query what the rpm is)
- run rpmbuild to build the binary

it takes about 10 minutes per gem, if your updating gems often this is
painful, but we don't update too often, I've gone through this process about
4 times in the past year. Been deploying gems this way for over a year now
and haven't had any problems(as in the files I built missing stuff or bad
versions etc). If there's a better/faster way to build RPMs that'd be great,
I'd love to build source rpms from gems, though the only way I know how to
build rpms myself is with alien which is cheating, but it works.. I think
building source rpms would take a lot more time.

The resulting RPMs are pushed out to about 60 systems.

nate
 
J

Justin Hahn

nate said:
- install the gem(one gem at a time!), for me I resolve dependencies
manually, and download the gems direct from
http://rubyforge.vm.bytemark.co.uk/gems/

That tells me what I needed to know. The only way to accomplish this
right now is by downloading the gems manually and installing them that
way. I was beginning to lean that way anyhow, but I guess there are
worse things than making my dependencies more explicit.

Thanks.
 
E

Ezra Zygmuntowicz

That tells me what I needed to know. The only way to accomplish this
right now is by downloading the gems manually and installing them that
way. I was beginning to lean that way anyhow, but I guess there are
worse things than making my dependencies more explicit.

Thanks.

Here is a script called gemcmd. This script is to be used in place of
the gem command. It will choose the proper platform and will install
the latest version of the requested gem available with no interaction
so it is suitable to be called from scripts.

Cheers-
-Ezra



#!/usr/bin/env ruby
#--
# 'gemcmd' - A non-interactive version of 'gem'.
#
# Original code
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
#
# Monkey Patch by Todd Fisher:
# http://revolutiononrails.blogspot.com/2007/06/code-digest-2.html
#
# Integrated into command line by Neil Wilson <[email protected]>
# (c) 2007
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
along
# with this program; if not, write to the Free Software Foundation,
Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#
#++

require 'rubygems'
Gem.manage_gems

required_version = Gem::Version::Requirement.new(">= 1.8.0")
unless required_version.satisfied_by?(Gem::Version.new(RUBY_VERSION))
puts "Expected Ruby Version #{required_version}, was #{RUBY_VERSION}"
exit(1)
end

Gem::RemoteInstaller.class_eval do


alias_method
:find_gem_to_install_without_ruby_only_platform, :find_gem_to_install

def find_gem_to_install( gem_name, version_requirement, caches =
nil )
if caches # old version of rubygems used to pass a caches object
caches.each {|k,v| caches[k].each { |name,spect|
caches[k].remove_spec(name) unless spec.platform ==
(ENV['GEMCMD_PLATFORM']||Gem::platform::RUBY) } }
find_gem_to_install_without_ruby_only_platform( gem_name,
version_requirement, caches )
else
Gem::StreamUI.class_eval do


alias_method
:choose_from_list_without_choosing_ruby_only, :choose_from_list
def choose_from_list( question, list )
result_index = -1
result= nil
list.each_with_index do |item,index|
if item.match(/\(#{ENV['GEMCMD_PLATFORM']||
Gem::platform::RUBY}\)/)
result_index = index
result = item
break
end
end
return [result, result_index]
end

end

find_gem_to_install_without_ruby_only_platform( gem_name,
version_requirement )

end
end
end

# We need to preserve the original ARGV to use for passing gem options
# to source gems. If there is a -- in the line, strip all options after
# it...its for the source building process.
args = !ARGV.include?("--") ? ARGV.clone : ARGV[0...ARGV.index("--")]

Gem::GemRunner.new.run(args)
 
N

nate

Here is a script called gemcmd. This script is to be used in place of
the gem command. It will choose the proper platform and will install
the latest version of the requested gem available with no interaction
so it is suitable to be called from scripts.

Looks like that script has it's uses, but it wouldn't be suitable for
me, I want to be sure that the same version of a gem is installed on
every system, whether I install the system in 10 minutes or 6 weeks
from now, or 6 months from now(been running most of the same gem versions
for probably at least 10 months so far).

nate
 
E

Eric Hodel

That tells me what I needed to know. The only way to accomplish this
right now is by downloading the gems manually and installing them that
way. I was beginning to lean that way anyhow, but I guess there are
worse things than making my dependencies more explicit.

No, try the beta.

There's a new one coming out probably Tuesday night, I'm waiting on
one more patch.
 
J

Jano Svitok

I'm trying to setup an automated build system for all of our upstream
binary dependencies (that we don't get from our OS). Since we track a
newer ruby than most of our machines ship with, this means building ruby
and installing gems. For the most part this works fine, except when I
need to install a gem like mongrel that has several versions.


For example, if I run 'gem install -y mongrel' from my Makefile, I get
an error like this (since stdin isn't attached):


Select which gem to install for your platform (x86_64-linux)
1. mongrel 1.1 (ruby)
2. mongrel 1.1 (mswin32)
3. mongrel 1.0.4 (mswin32)
4. mongrel 1.0.4 (ruby)
5. Skip this gem
6. Cancel installation
undefined method `strip' for nil:NilClass

Unfortunately, the list entries aren't even stable -- sometimes option
#1 is the mswin32 and sometimes it's the ruby choice. So I can't even do
something nasty like "echo 1 | gem install -y mongrel" and be assured of
getting the right thing.

Is there any way to tell gem, from the commandline, precisely which gem
I want? The documentation seems sparse, and I haven't had the time to go
digging through gem's source code yet. (My hope is that this is any easy
answer...)

One way is to install the gems on one machine and run a gem server on it.
Then install the other machines from that server (--source=http://yourserver)

If you install only one version of a gem, only one will be offered and
you'll exactly
know which one.

This will make the install a bit faster, as you'll be downloading from
the local network.
Setting up a gem server is pretty easy -- e.g.
http://rambleon.org/2007/04/19/creating-your-own-gem-server/

J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top