question about multiple ruby + gems installations for dev/test/prod

Discussion in 'Ruby' started by Alex Rice, Dec 25, 2009.

  1. Alex Rice

    Alex Rice Guest

    Hi All, I am pretty new to Ruby, and googled quite a bit about the gem
    utility, but am kind of stuck. I need some advice about maintaining good
    separation between ruby installs and gem directories.

    In this project we have Ruby installs for dev, test and prod. The idea
    is we can test different versions of ruby, rails, and different gems.
    Then when it's getting promoted from test to prod, just cp -R the ruby
    directory and all it's gems from test to prod. Nice idea except the gems
    paths are all fouled up now.

    Question: How does the gem script actually figure out it's environment
    and where it's gems are? Is there a config file somewhere? I can't find
    it if there is.

    Question: What is the best practice for this kind of situation
    (test/dev/prod environments for ruby) ?

    I am aware of the GEM_PATH and GEM_HOME environment variables. They are
    not currently set. I have lots of shell scripts pointing at this ruby
    install, and don't want to have to add GEM_PATH and GEM_HOME to all of
    those shells scripts. However if that's the only way, then I guess I can
    live with that.

    I am also aware of the sandbox gem but do not want to make this overly
    complicated. It should be possible to do this without additional gem
    dependencies.

    $ which ruby
    /home/grindstone/prod/ruby/current/bin/ruby # prod is good

    $ which gem
    /home/grindstone/prod/ruby/current/bin/gem # prod is good

    $ echo $GEM_PATH # not set
    $ echo $GEM_HOME # not set

    # gem env bad! gem seems looking at test, not prod...
    $ gem env
    RubyGems Environment:
    - RUBYGEMS VERSION: 1.3.1
    - RUBY VERSION: 1.9.1 (2009-05-12 patchlevel 129) [x86_64-linux]
    - INSTALLATION DIRECTORY:
    /home/grindstone/test/ruby/1.9.1-p129/lib/ruby/gems/1.9.1
    - RUBY EXECUTABLE: /home/grindstone/test/ruby/1.9.1-p129/bin/ruby
    - EXECUTABLE DIRECTORY: /home/grindstone/test/ruby/1.9.1-p129/bin
    - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
    - GEM PATHS:
    - /home/grindstone/test/ruby/1.9.1-p129/lib/ruby/gems/1.9.1
    - /home/agr/.gem/ruby/1.9.1
    - GEM CONFIGURATION:
    - :update_sources => true
    - :verbose => true
    - :benchmark => false
    - :backtrace => false
    - :bulk_threshold => 1000
    - REMOTE SOURCES:
    - http://gems.rubyforge.org/

    Thanks in advance!
    --
    Alex Rice <>
    Software Engineer
    National Center for Genome Resources (NCGR)
    http://www.ncgr.org
    (505)995-4457
     
    Alex Rice, Dec 25, 2009
    #1
    1. Advertising

  2. Re: question about multiple ruby + gems installations fordev/test/prod

    On 25.12.2009 20:31, Alex Rice wrote:
    > Hi All, I am pretty new to Ruby, and googled quite a bit about the gem
    > utility, but am kind of stuck. I need some advice about maintaining good
    > separation between ruby installs and gem directories.


    http://rvm.beginrescueend.com/
    Seems like that's what RVM was intended for. :)

    > In this project we have Ruby installs for dev, test and prod. The idea
    > is we can test different versions of ruby, rails, and different gems.
    > Then when it's getting promoted from test to prod, just cp -R the ruby
    > directory and all it's gems from test to prod. Nice idea except the gems
    > paths are all fouled up now.
    >
    > Question: How does the gem script actually figure out it's environment
    > and where it's gems are? Is there a config file somewhere? I can't find
    > it if there is.


    While I'm not aware of Rubygem's internals, I know that it does look at
    ".gemrc" in the home directory of a user first, to parse variables,
    including GEM_HOME and GEM_PATH.

    Coupled with RVM, this should enable you to separate your dev/test/prod
    environments on the same machine.

    > I am aware of the GEM_PATH and GEM_HOME environment variables. They are
    > not currently set. I have lots of shell scripts pointing at this ruby
    > install, and don't want to have to add GEM_PATH and GEM_HOME to all of
    > those shells scripts. However if that's the only way, then I guess I can
    > live with that.


    See ".gemrc" in Rubygem's manual: http://docs.rubygems.org/read/chapter/11

    That should enable you to setup a .gemrc-dev, a .gemrc-testing, and a
    gemrc-production with ease.

    Alternatively, you could also use rake rails:gem:freeze to, well, freeze
    the gems your Rails app uses.

    --
    Phillip Gawlowski
    Wishing everyone a Merry Christmas, and happy holidays :)
     
    Phillip Gawlowski, Dec 25, 2009
    #2
    1. Advertising

  3. Re: question about multiple ruby + gems installations fordev/test/prod

    On Fri, Dec 25, 2009 at 11:31 AM, Alex Rice <> wrote:
    > I need some advice about maintaining good
    > separation between ruby installs and gem directories.


    > Question: What is the best practice for this kind of situation
    > (test/dev/prod environments for ruby) ?


    Have you considered virtualization?

    It's so easy to create a single-purpose image and then you have no
    worries about path confusion. As you need to test new releases you
    just create a new clean image, install and go.

    FWIW,
    --
    Hassan Schroeder ------------------------
    twitter: @hassan
     
    Hassan Schroeder, Dec 25, 2009
    #3
  4. Alex Rice

    Alex Rice Guest

    Re: question about multiple ruby + gems installations fordev/test/prod

    Phillip Gawlowski wrote:

    > http://rvm.beginrescueend.com/
    > Seems like that's what RVM was intended for. :)
    > ...
    > See ".gemrc" in Rubygem's manual: http://docs.rubygems.org/read/chapter/11
    >
    > That should enable you to setup a .gemrc-dev, a .gemrc-testing, and a
    > .gemrc-production with ease.
    >
    > Alternatively, you could also use rake rails:gem:freeze to, well, freeze
    > the gems your Rails app uses.


    Thanks- very good suggestions.

    I still am puzzled as to why my prod environment is using gems from the
    test environment. There must be a dotfile or config file somewhere in
    the gem directory. Does anyknow know where the gem path is actualy
    stored in the ruby install, if it's not in .gemrc and not in GEM_PATH
    and GEM_HOM?

    --
    Alex Rice <>
    Software Engineer
    National Center for Genome Resources (NCGR)
    http://www.ncgr.org
    (505)995-4457
     
    Alex Rice, Dec 27, 2009
    #4
  5. Alex Rice

    Alex Rice Guest

    Re: question about multiple ruby + gems installations fordev/test/prod

    Hassan Schroeder wrote:
    > Have you considered virtualization?
    >
    > It's so easy to create a single-purpose image and then you have no
    > worries about path confusion. As you need to test new releases you
    > just create a new clean image, install and go.


    Thanks for the suggestion- I have no experience with virtualization of
    servers. There are also lot of NFS and SMB filesystems involved and I am
    not sure it would be so easy to create a working image. I could be wrong
    though.

    --
    Alex Rice <>
    Software Engineer
    National Center for Genome Resources (NCGR)
    http://www.ncgr.org
    (505)995-4457
     
    Alex Rice, Dec 27, 2009
    #5
  6. Re: question about multiple ruby + gems installations fordev/test/prod

    On 27.12.2009 02:12, Alex Rice wrote:
    > Phillip Gawlowski wrote:
    >
    > I still am puzzled as to why my prod environment is using gems from the
    > test environment. There must be a dotfile or config file somewhere in
    > the gem directory. Does anyknow know where the gem path is actualy
    > stored in the ruby install, if it's not in .gemrc and not in GEM_PATH
    > and GEM_HOM?


    I hacked up a quick script (after digging through rubygem's sources):
    PS C:\Scripts> ruby .\gemconfig.rb
    sitedir: C:/Ruby/lib/ruby/site_ruby
    bindir: C:/Ruby/bin
    sitelibdir: C:/Ruby/lib/ruby/site_ruby/1.8
    datadir: C:/Ruby/share
    vendordir:
    EXEEXT: .exe
    libdir: C:/Ruby/lib
    vendorlibdir:
    ruby_install_name: ruby
    RUBY_SO_NAME: msvcrt-ruby18
    ruby_version: 1.8
    arch: i386-mingw32
    PS C:\Scripts> cat .\gemconfig.rb
    require "rubygems"
    Gem::ConfigMap.each do |config,value|
    puts "#{config}: #{value}"
    end
    PS C:\Scripts>

    The path seems to be built on runtime (I don't have a .gemrc defined in
    my home dir).

    So, this raises the question, if your production environment is isolated
    from the development and testing environments, and if so, how?
    (Mind, this is a question out of curiosity, to get to the root of the
    problem :)

    --
    Phillip Gawlowski
     
    Phillip Gawlowski, Dec 27, 2009
    #6
  7. Alex Rice

    Alex Rice Guest

    Re: question about multiple ruby + gems installations for de

    Phillip Gawlowski wrote:
    >
    > The path seems to be built on runtime (I don't have a .gemrc defined in
    > my home dir).


    The root of my confusion, is as follows. In retrospect it's not
    surprising though. I have everything straightened out now.

    If you run (in Unix - maybe no equivalent in Windows )
    strings ruby | grep lib
    You can see your lib directories are compiled into the binary.

    So gem uses that path appends ruby/gems/[version] and that becomes the
    default GEM_PATH.

    It adds to the gem path if there is a ~/.gem directory with stuff in it.
    gemrc and GEM_PATH environment variables may further change or override
    the gem paths.

    Summary, it's a no-no to move around a ruby install directory like I was
    doing, because the lib paths will get broken.
    --
    Posted via http://www.ruby-forum.com/.
     
    Alex Rice, Dec 28, 2009
    #7
    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. TJ
    Replies:
    2
    Views:
    328
  2. AC
    Replies:
    0
    Views:
    167
  3. The Mighty Chaffinch

    2 Instances of Same App on IIS (Prod'n & Test)

    The Mighty Chaffinch, Dec 2, 2003, in forum: ASP General
    Replies:
    5
    Views:
    129
    Chris Barber
    Dec 4, 2003
  4. Rick DeNatale

    Parallel installations of 1.8 and gems

    Rick DeNatale, Mar 6, 2007, in forum: Ruby
    Replies:
    0
    Views:
    95
    Rick DeNatale
    Mar 6, 2007
  5. jacopo

    PYTHONPATH: dev and prod

    jacopo, Jun 11, 2013, in forum: Python
    Replies:
    7
    Views:
    125
    jacopo
    Jun 13, 2013
Loading...

Share This Page