I used to be a .NET guy, and enjoyed using a nightly build system (continuous integration) called CruiseControl.NET to automatically deploy my applications to my staging environment each night.
Now that I’ve made the jump to Ruby on Rails and GitHub, I’ve found myself a little confused about how to setup an equivalent automated, nightly build system. I want to do things right, the Rails way, but I could use a push in the right direction.
Here’s what I’m using…
- Ruby on Rails 3.2.9 (with asset pipeline)
- RVM
- Apache + Passenger
- MySQL
- Ubuntu 12.04 (staging server OS)
- GitHub (SCM)
I’m looking for a system/solution that fulfills these requirements: (Ideally utilizing Capistrano…)
- Deploy the latest commit from my ‘master’ branch in my GitHub repository to my staging server.
- One-click build on-demand: I want to click a button or link to force a deploy (or re-deploy) at any time
- Have the capability to run custom commands on the staging server as a part of the deploy (i.e. ‘bundle install’, restart Apache, etc…)
- Automatic deploy daily or after a commit on GitHub (optional)
And because I’d never ask this question without doing some research first, here are some relevant resources I’ve found, but haven’t been able to decipher:
Suggestions, anyone? Thanks!
- David
Well, it turns out there is alot of good information out there regarding how to use Capistrano for this purpose (including Prakash’s reference), but none of it seems to be fully comprehensive.
After many hours of picking through guide, after forum, after stack overflow question, I managed to fulfill most of my goals. To save time for others, I will try to provide answers and information that I found in the context of my original question.
UPDATE:
It turns out I was looking for Jenkins all along: it’s a perfect (an even an improved) analog to the CruiseControl build server application I had used before. Jenkins is a web application that kicks off builds on a scheduled basis or, with plugins, commit events. It doesn’t include functionality to actually deploy my Rails app, so that’s where Capistrano steps in. Using Jenkins’ “shell execute” build task to trigger Capistrano deploys, I was able to accomplish all of my goals above.
Take a look at this guide for more detail.
ORIGINAL POST:
First off, Capistrano can work for the purpose of build system, however, it is not at all similar to CruiseControl.
CruiseControl is:
Capistrano is:
rake; it bears similar functionality to the Ant and Nant scripts used by CruiseControl for the purpose of deploying.cap deploy(this is as close as it gets to ‘one click’ deploys.)In regards to my original requirements…
Configuring Capistrano’s deploy.rb file will accomplish this.
All Capistrano deploys are done through ‘force’: you run ‘cap deploy’ in your console manually
Configuring Capistrano’s deploy.rb file will accomplish this. Most of these commands are included out of the box.
I haven’t figured this one out yet… a cron job might be the best way to do this.
Setting up Capistrano
Start with this tutorial from GitHub first. In your Rails App folder, you should end up with a
Capfileandconfig/deploy.rbfile.To save you some time, copy and paste these files, and tweak the settings to your needs.
The files below are configured for:
database.ymlfile you didn’t commit to SCM)Capfile
config/deploy.rb