Automating gem installs?

Discussion in 'Ruby' started by Justin Hahn, Nov 9, 2007.

  1. Justin Hahn

    Justin Hahn Guest

    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...)
    --
    Posted via http://www.ruby-forum.com/.
    Justin Hahn, Nov 9, 2007
    #1
    1. Advertising

  2. Justin Hahn

    Ryan Davis Guest

    On Nov 9, 2007, at 09:48 , Justin Hahn wrote:

    > 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. :)
    Ryan Davis, Nov 9, 2007
    #2
    1. Advertising

  3. Justin Hahn

    nate Guest

    Justin Hahn wrote:
    > 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
    nate, Nov 11, 2007
    #3
  4. Justin Hahn

    Justin Hahn Guest

    nate wrote:

    > - 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.
    --
    Posted via http://www.ruby-forum.com/.
    Justin Hahn, Nov 11, 2007
    #4
  5. On Nov 11, 2007, at 3:01 PM, Justin Hahn wrote:

    > nate wrote:
    >
    >> - 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.
    > --
    > Posted via http://www.ruby-forum.com/.
    >


    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 <>
    # (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)
    Ezra Zygmuntowicz, Nov 12, 2007
    #5
  6. Justin Hahn

    nate Guest

    Ezra Zygmuntowicz wrote:
    >


    > 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
    nate, Nov 12, 2007
    #6
  7. Justin Hahn

    Eric Hodel Guest

    On Nov 11, 2007, at 15:01 , Justin Hahn wrote:
    > nate wrote:
    >> - 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.


    No, try the beta.

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

    --
    Poor workers blame their tools. Good workers build better tools. The
    best workers get their tools to do the work for them. -- Syndicate Wars
    Eric Hodel, Nov 12, 2007
    #7
  8. Justin Hahn

    Eric Hodel Guest

    On Nov 11, 2007, at 06:28 , nate wrote:
    > - 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/


    No!!!

    Download gems direct from http://gems.rubyforge.org/gems. It will
    round-robin across all the mirrors.

    Don't punish one mirror.

    --
    Poor workers blame their tools. Good workers build better tools. The
    best workers get their tools to do the work for them. -- Syndicate Wars
    Eric Hodel, Nov 12, 2007
    #8
  9. Justin Hahn

    Justin Hahn Guest

    Eric Hodel wrote:
    > On Nov 11, 2007, at 06:28 , nate wrote:
    >> - 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/

    >
    > No!!!
    >
    > Download gems direct from http://gems.rubyforge.org/gems. It will
    > round-robin across all the mirrors.
    >
    > Don't punish one mirror.


    You may want to update this page then:

    http://gems.rubyforge.org/

    The gems link is a direct reference to that one mirror.
    --
    Posted via http://www.ruby-forum.com/.
    Justin Hahn, Nov 13, 2007
    #9
  10. Justin Hahn

    Tom Copeland Guest

    On Tue, 2007-11-13 at 08:21 +0900, Eric Hodel wrote:
    > On Nov 11, 2007, at 06:28 , nate wrote:
    > > - 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/

    >
    > No!!!
    >
    > Download gems direct from http://gems.rubyforge.org/gems. It will
    > round-robin across all the mirrors.
    >
    > Don't punish one mirror.


    Yup, what Eric said. And thanks again to our mirror providers!

    http://rubyforge.org/credits/

    Yours,

    Tom
    Tom Copeland, Nov 13, 2007
    #10
  11. Justin Hahn

    Jano Svitok Guest

    On Nov 9, 2007 6:48 PM, Justin Hahn <> wrote:
    > 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...)


    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.
    Jano Svitok, Nov 13, 2007
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Automating Installs

    , Mar 18, 2006, in forum: Java
    Replies:
    1
    Views:
    415
    Roedy Green
    Mar 18, 2006
  2. Austin 7873
    Replies:
    5
    Views:
    176
    Eric Hodel
    Jan 27, 2007
  3. braver
    Replies:
    4
    Views:
    122
  4. Stefano Crocco
    Replies:
    0
    Views:
    79
    Stefano Crocco
    Oct 17, 2008
  5. Daniel Berger
    Replies:
    2
    Views:
    147
    Daniel Berger
    Dec 31, 2009
Loading...

Share This Page