Here are a few notes on how to get individual CruiseControl.rb project Builders running with RVM.
[Note: I'm making an assumption here that you know and understand Bundler and RVM.]
[Also: Cruise may or may not be running on RVM]
Create and check in a .rvmrc file in your rails root directory. Here’s an example.
rvm ruby-1.8.7-p174@rails-example
Then, add a project build command to your cruise_config.rb file.
Project.configure do |project| project.build_command = './cruise_build.sh' end
Finally, create a cruise_build.sh file. The bash script setups rvm and just calls your cruise control build task.
[Note: Your cruise rake task should probably call Bundler's "bundle install".]
#!/bin/sh source $HOME/.rvm/scripts/rvm && source .rvmrc rake cc:build
…and your cruise project builder is now using RVM!
rvm will not create the gemset for you unless you ask, so your `.rvmrc` should say
rvm use ruby-1.8.6@myapp –create
If you’re using Bundler, you should probably add this line before calling `rake`:
bundle check || bundle install &&
(the trailing && means that it’ll run the next line only if the bundle stuff succeeded).
With /bin/sh I got “source: not found” on whatever box is running ci.pivotallabs.com so I switched to `#!/bin/bash`.
After much debugging, here’s my `cruise_build.sh` that conditionally installs ruby 1.8.6, bundler, and the project’s gems in an isolated rvm gemset. I chose not to use an `.rvmrc` file since I’m pretty sure it’s not necessary and I wanted to centralize all the settings.
#!/bin/bash
desired_ruby=ruby-1.8.6-p399
project_name=erector
# remove annoying “warning: Insecure world writable dir”
function remove_annoying_warning() {
chmod go-w $HOME/.rvm/gems/${desired_ruby}{,@{global,${project_name}}}{,/bin} 2>/dev/null
}
# enable rvm for ruby interpreter switching
source $HOME/.rvm/scripts/rvm || exit 1
# show available (installed) rubies (for debugging)
rvm list
# install our chosen ruby if necessary
rvm list | grep $desired_ruby > /dev/null || rvm install $desired_ruby || exit 1
# use our ruby with a custom gemset
rvm use ${desired_ruby}@${project_name} –create
remove_annoying_warning
# install bundler if necessary
gem list –local bundler | grep bundler || gem install bundler || exit 1
# debugging info
echo USER=$USER && ruby –version && which ruby && which bundle
# conditionally install project gems from Gemfile
bundle check || bundle install || exit 1
# remove the warning again after we’ve created all the gem directories
remove_annoying_warning
# finally, run rake
rake cruise
October 27, 2010 at 2:15 pm
The best shebang is:
#!/usr/bin/env bash
Also, using an .rvmrc IS centralizing your settings – for developers as well as CI.
– Chad
October 27, 2010 at 2:29 pm
An `.rvmrc` file changes the current ruby every time you `cd` into its directory. But the preferred version for an individual developer may or may not be the preferred version for a collective CI instance. So I prefer not to check in `.rvmrc` files because that would clobber individual developers’ own ruby settings. (How annoying would it be if you were working on 1.9 compatibility and kept getting your ruby switched out to 1.8? Or if you accidentally checked in your 1.9 .rvmrc and annoyed everyone else?)
Also, I’d like to get CI to run the same tests on many rubies, one after another. I’m already doing that in [Wrong](http://github.com/sconover/wrong) and I may do it in Erector (extending the above script) soon. But if I were using an `.rvmrc` then it would naturally conflict with all but one of the iterations…
So if you agree with me then `.rvmrc` should always be in `.gitignore` and never checked in.
October 27, 2010 at 2:49 pm
@Chad Wooley
On ubuntu it is :
#!/bin/env bash
Do you know any way to detect that?
I agree that .rvmrc is a centralized setting – avoid checking it in by accident if you change it.
November 4, 2010 at 5:30 pm
btw Mike – nice post!
November 4, 2010 at 5:35 pm
Thanks for the post Mike. I had major issues getting RVM to play nice with CC, but this post did help.
As an aside, I found Hudson more straightforward, and will be writing up instructions on how to set up Hudson + RVM + gemsets on Ubuntu.
November 6, 2010 at 6:15 am
Hi Sandeep,
We also use hudson. You might also like cimonitor – https://github.com/pivotal/cimonitor
it’s been a while, we should catch up soon…
November 6, 2010 at 7:49 am