Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Rails 3 with RVM and Cruise Control

Mike Barinek
Tuesday, October 26, 2010

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!

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

7 Comments

  1. Alex Chaffee says:

    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

  2. Chad Woolley says:

    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

  3. Alex Chaffee says:

    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

  4. Curtis Schofield says:

    @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

  5. Curtis Schofield says:

    btw Mike – nice post!

    November 4, 2010 at 5:35 pm

  6. Sandeep Ghael says:

    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

  7. Mike Barinek says:

    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

Add New Comment Cancel reply

Your email address will not be published.

Mike Barinek

Mike Barinek
Boulder

Recent Posts

  • American Thrombosis and Hemostasis Network (ATHN) is looking for a Web Application Developer
  • Portico is looking for a Web Application Developer
  • Testing Ruby Services without Mocks
Subscribe to Mike's Feed

Author Topics

boulder (4)
jobs (3)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >