I just pushed a change for my teammates: we’re now using Bundler on our Rails 2.3.5 application. Things went rather well, but our continuous testing server choked a bit on that.

First, I had forgotten to run bundle install after pulling changes. Then I had to ignore our cucumber environment, because it depends on rb-appscript which is a native gem on Mac OS X. Our CT machine is a Linux box, hence the change. Then, bundle install would fail installation because it didn’t have sudo access:


1 Fetching git://github.com/bloom/rails.git
2 Fetching git://github.com/francois/active_url
3 Fetching git://github.com/francois/safariwatir.git
4 Fetching source index for http://rubygems.org/
5 sudo: no tty present and no askpass program specified
6 sudo: no tty present and no askpass program specified
7 Using rake (0.8.7)
8 sudo: no tty present and no askpass program specified
9 sudo: no tty present and no askpass program specified
10 /usr/lib64/ruby/site_ruby/1.8/rubygems/format.rb:38:in `from_file_by_path’: Cannot load gem at [/usr/lib64/ruby/gems/1.8/cache/SystemTimer-1.2.gem] in /home/francois/adgear-admin (Gem::Exception)
11 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/source.rb:77:in
`
fetch
12 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/installer.rb:45:in `run

13 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/spec_set.rb:12:in `each’
14 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/spec_set.rb:12:in
`
each
15 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/installer.rb:44:in `run

16 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/installer.rb:8:in `install’
17 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/cli.rb:185:in
`
install
18 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/vendor/thor/task.rb:22:in `send

19 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/vendor/thor/task.rb:22:in `run’
20 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/vendor/thor/invocation.rb:118:in
`
invoke_task
21 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/vendor/thor.rb:246:in `dispatch

22 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/lib/bundler/vendor/thor/base.rb:389:in `start’
23 from /usr/lib64/ruby/gems/1.8/gems/bundler-1.0.0.rc.5/bin/bundle:13
24 from /usr/bin/bundle:19:in
`
load
25 from /usr/bin/bundle:19
26

I was busy writing a message to the Ruby Bundler Google Group when I remembered bundle install has an optional parameter which specifies where the bundle should be installed. I changed my CT script to run bundle install --without=cucumber vendor/gems and bundle did it’s magic, and my CT box started running tests.

Much rejoicing ensued.

For the record, here’s our testing script:


1 #!/bin/bash
2 cd /home/francois/adgear-admin
3
4 if [ z $1 ] ; then
5 echo "Can’t proceed if I don’t know which branch to test"
6 exit 1
7 fi
8
9 TSTAMP=`date +%Y
%m-%d-%H:%M`
10 BRANCH=$1
11 LOG=/home/francois/build-logs/$BRANCH-$TSTAMP.log
12
13 (
14 git fetch origin && \
15 git reset -hard origin/$BRANCH && \
16 echo ======= && \
17 git show && \
18 ( bundle install —without=cucumber vendor/cache || true ) && \
19 nice rake db:adgear:production:update parallel:prepare parallel:test
20 ) > $LOG 2>&1
21
22 if [ "$?" = "0" ] ; then
23 /usr/bin/curl -s -o /dev/null -d "{\"message\":{\"body\":\"Test Suite Passed -
$BRANCH — http://ct.local:9001/logs/$BRANCH/$TSTAMP\"}}" HContent-Type:application/json -u 12345:X http://oursite.campfirenow.com/room/12345/speak.json
24 else
25 /usr/bin/curl -s -o /dev/null -d "{\"message\":{\"body\":\"Test Suite FAILED -
$BRANCH — http://ct.local:9001/logs/$BRANCH/$TSTAMP\"}}" -HContent-Type:application/json -u 12345:X http://oursite.campfirenow.com/room/12345/speak.json
26 fi
27
28 # vi: sw=8 ts=8 expandtab

This script is run from cron.

At Bloom, we’re looking into using JRuby instead of MRI. To support the two implementations, some gems are different. Case in point: RMagick and the JSON gems:

config/environment.rb

1 # More config.gem declarations elided
2
3 if defined?(JRUBY_VERSION) then
4 config.gem "activerecord-jdbc-adapter", :version => "0.9.2", :lib => "jdbc_adapter"
5 config.gem "json-jruby", :version => "1.2.0", :lib => "json"
6 config.gem "rmagick4j", :version => "0.3.6", :lib => "RMagick"
7 else
8 config.gem "json", :version => "1.2.0"
9 config.gem "rmagick", :version => "2.12.2", :lib => "RMagick"
10 end

I created the following in Gemfile:

Gemfile

1 source :gemcutter
2
3 gem "rails", "= 2.3.4"
4 gem "pg", "~> 0.8.0" if !defined?(JRUBY_VERSION)
5
6 if defined?(JRUBY_VERSION) then
7 gem "activerecord-jdbc-adapter", ">= 0.9.2", :lib => "jdbc_adapter"
8 gem "json-jruby", ">= 1.2.0"
9 gem "rmagick4j", ">= 0.3.6"
10 else
11 gem "json", ">= 1.2.0"
12 gem "rmagick", ">= 2.12.2"
13 end
14
15 # Ruby’s 1.9 stdlib replaced CSV with the implementation of 1.8’s FasterCSV, but
16 # the upgrade path is problematic: we have to change how we’re loading the library.
17 gem "fastercsv" if RUBY_VERSION =~ /^1\.8/

Notice I target 3 versions of Ruby: MRI 1.8, MRI 1.9 and JRuby. If I bundle lock from one Ruby implementation, then the other ones won’t be able to use the locked bundle:


1 [jruby-1.4.0]$ bundle unlock && bundle lock
2 The bundle is now unlocked. The dependencies may be changed.
3 The bundle is now locked. Use `bundle show` to list the gems in the environment.
4
5 [jruby-1.4.0]$ rvm use 1.8.7
6 Now using ruby 1.8.7 p248
7
8 [ruby-1.8.7-p248]$ bundle check
9 Could not find gem ‘rmagick4j (= 0.3.7, runtime)’ in any of the sources.

I’m using Bundler in the context of a Rails 2.3.4 application, but we’ll eventually move to Rails 3. Anybody has any experience using Bundler in this way?

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on