Safew Technology Labs. He has been working with Ruby and Rails since 2005. He loves to write software in Rails apart from managing his company.is Co-Founder and CEO of
He also has a knack for system administration and is an expert level Linux system administrator. In his free time, he likes to listen to music and read fiction. He can be reached at saurabh (at) noisybrain (dot) net.
In past few years the software engineering principles have undergone a phenomenal change, what could be called a complete paradigm shift. Software development Life cycle used to rule the software companies, with strenuous phases of requirement "freezing", design development and testing phases. However, Moore's law has applied to each and every part of technology. The rate at which requirements change in real-time in today's times is phenomenal and spares no scope for the traditional software development life cycle to be used as the development process.
One of twelve core principles of Extreme Programming, continuous integration is a practice that imparts discipline to the development process and streamlines the code to always keep it production ready.
A few Practices that make continuous integration highly effective for the projects are:
Single Source Code Repository
Today most of the projects make it a point to follow the source code Repositories as an integral part of the project, but many of tend to add only the development core of the application. A good practice is to add Tests, schema and each every asset related to the Project, everything that is needed to generate a build and supposed to go into production. SCM like git and svn allow to keep multiple branches for the same repository, hence there can be a development branch where you do the development and check for the build errors and merge it with the main branch which will contain the final tested working production ready code.
Automate Build and Build Often
Adding scripts that build whenever the repository is updated and getting the assessment of build errors is a process that signifies a tectonic shift in the philosophy of software development over the ages. So,when we have a single source code repository we have all the components that would be required to emulate a production environment and generate build. One of the agile practices is to avoid quick-fixes and make final production ready drafts from the beginning. Building as often as every commit makes it easy to inflict discipline for such kind of processes.
Test automation is the most logical implication of the above two concepts. What it means is, whenever we send the code into the repository,the tests should run by themselves and you should get results in the a format which you keep checking regularly, for instance Twitter, Yahoo Messenger or email.
There are several tools for these purposes like svn, git, bazaar, perforce as source control systems, cerberus, cruisecontrol.rb, hudson, Selenium continuous integration runner, and test automation tools like selenium. There are several combinations that can be made out of these tools, but the best solution is the one with which you are the most comfortable.
Let's watch some of these tools in action. Starting with the most basic implementation of continuous integration,yet one of the most powerful and effective tools available around for building applications in ruby on rails is Cerberus. Lets get an introduction to the various scenarios in which Cerberus can be used.
Cerberus is a continuous builder which is compatible with all ruby projects that use Rake, so it can be used, not only for Rails but also for Merb and Sinatra. The home of Cerberus project defines it as
“Cerberus is a lightweight and easy-to-use Continuous Builder software for Ruby.”
Cerberus runs periodically to check the latest changes in the repository and checks for tests. If the tests fail and the build is broken, it notifies the users through various channels, like twitter, emails, Campfire, IRC and RSS.
Cerberus is distributed as a gem package so it is easy to install,upgrade and maintain. This also makes
Cerberus usable on any OS platform. The prerequisite for installation is Ruby 1.8.2 or greater version and Rubygems. In order to install, just run the following command:
saurabh@laptop:~$sudo gem install cerberus --include-dependencies
Successfully installed cerberus-0.7
Successfully installed actionpack-2.3.4
2 gems installed
Add the project to the Cerberus in two ways:
1. Mention the path to the directory directly, mention the application name and email of the people who intend to receive the status of the build.
saurabh@laptop:~/allnews/safewlabs_an$ cerberus add /home/saurabh/allnews/safewlabs_an APPLICATION_NAME=safewlabs_an RECIPIENTSemail@example.com
Application 'safewlabs_an' has been added to Cerberus successfully
2. Mention the svn url and rest remains the same.
saurabh@laptop:~$ cerberus add http://safewlabs.unfuddle.com/svn/safewlabs_traffictwit/ APPLICATION_NAME=traffictwit RECIPIENTSfirstname.lastname@example.org
Application 'traffictwit' has been added to Cerberus successfully
Now goto the Cerberus directory in your home and edit the configuration file with your favourite editor.
saurabh@laptop:~$ cd .cerberus/
saurabh@laptop:~/.cerberus$ nano config.yml
The ~/.cerberus/config.yml file looks like this:
# active: mail jabber rss campfire
# on_event: all
# jid: email@example.com/cerberus
# password: somepassword
# login: twitter_username
# password: twitter_password
# nick: cerb
# server: irc.freenode.net
# channel: cerberus
# url: http://someemail:firstname.lastname@example.org/room/51660
# file: /usr/www/rss.xml
# task: migrate test
# on_event: successful, setup #by default - run hook for any state
# action: 'export CERBERUS_HOME=/home/anatol && sudo chown www-data -R /home//anatol/cerberus && rcov' #Add here any hook you want
You can uncomment the options you want to and get the messages to the notification of your choice.
Now Goto config folder inside cerberus directory and list the files inside it. You will be able to see the configuration files of applications you had added earlier.
saurabh@laptop:~/.cerberus$ cd config/
Make sure the options in this file are also right:
saurabh@laptop:~/.cerberus/config$ cat traffictwit.yml
Once you have made sure all this, we are ready to prepare the first build of the project.
cerberus build traffictwit
The result of this is shown in the following screens:
This command goes to the svn repository and builds the latest version available. In case the tests fail,you get a mail mentioning the details of the build.
Now, in order to stick to the agile methodology, we will go ahead and automate Cerberus build. In order to do this, we setup cron jobs on our system.
saurabh@laptop:~$ crontab -e
Setup the crontab file in order to check for the changes to the repository every 10 minutes.
# m h dom mon dow command
10 * * * * cerberus build traffictwit
If you are hosting your repository on your own server, you can build using subversion hook and run after commit.
Other SCMs supported by Cerberus are git, bazaar, darcs, bjam and perforce.
Continuous Integration is an essential practice in today's scenario, because of the pace at which the projects are carried out. Cerberus is a minimal continuous builder tool, which works pretty well, but does not have a dashboard or a gui for the users. There are several other tools we will explore in the coming articles, which have a UI and have several interesting features.