What is he banging on about this time?
Having a Continuous Integration system in place is a central practice of a functioning agile development team.
Our old CI server was bardy, supa dupa bardy, and over complicated. We were using cruisecontrol.rb, it did the trick but we were using java to run our selenium tests, which was a bit of a pain, so we decided to use Integrity to handle it all instead. ( And dropped the selenium tests for the time being and just use cucumber and rspec. )
So you’ve built a bog standard Ubuntu Server build with ruby and apache with passenger installed, as well as all the normal security, monitoring and maintenance software loaded and configured. (Hopefully we’ll get an article up soon on how to do all this, without giving away too many secrets of course :-))
You’ll also need to install all the software on the system that you’ll need to run whatever tests you want to run in every project that needs to be tested. Nearly all the gems will be bundled, so they’re not so much of a worry, but things like imagemagick and relevant development libraries and system tools need to be installed.
Let’s grab the code, install it and create the sqlite db
$ gem install bundler $ git clone git://github.com/integrity/integrity $ cd integrity $ git checkout -b deploy v0.2.3 $ gem bundle --only default $ ./bin/rake db
uncomment this line(we’re going to use campfire notifier)
and change c.base_url to be the url of your integrity server
add this block prior to running the app to add some security to the site
use Rack::Auth::Basic do |user, pass| user == "admin" && pass == "secret" end
Uncomment these two lines
gem "broach", :git => "git://github.com/Manfred/broach.git" gem "nap", :git => "git://github.com/qrush/nap.git"
Now you need to run gem bundle again inside the integrity app to add the new gems for the campfire notifier
$ gem bundle --only default
I’m going to serve it with apache, so I need to create the virtual host definition and enable it.
sudo vi /etc/apache2/sites-available/integrity <VirtualHost myintegrityserver.com:80> ServerName myintegrityserver.com CustomLog /var/log/apache2/integrity_access.log combined DocumentRoot /path/to/integrity/public <Directory /path/to/integrity/public> AllowOverride all Options -MultiViews </Directory> </VirtualHost> sudo a2ensite integrity sudo /etc/init.d/apache2 restart
When you browse to your server you should now see the integrity application running, but obviously with no projects built yet, let’s build one.
We use the same name as our git repository on github, e.g.
This is the clone URL to your github project with .git at the end removed(current issue).
Branch to Track
We currently use a bash script to perform some tasks prior to running the test suite. We were using a rake task, but ran into some issues with rack1.1 so we’re using this method now.
/path/to/bashscript.sh && script/cucumber
sudo vi /path/to/bashscript #!/bin/sh cp /path/to/database.yml config/ RAILS_ENV=test rake db:migrate --trace /usr/bin/gem bundle > /dev/null 2>&1
Tick the Campfire Notifications and you’ll see some extra configuration options. We’re going to use this to send the result of the test back to our campfire site so we can all see the test results, good or bad :-)
This is you campfire subdomain, so if my campfire site was at matt.campfirenow.com it would be
This is the name of the room itself, not the URL to it. e.g., if my room was called matts’s pictures 1.0, then you need to put in this box exactly that, matt’s pictures 1.0.
This is your API authentication token from Campfire. If you login to campfire and click on My info you’ll see it there
Notify on success
Tick it, it’s always good to know when the tests pass, in a vain attempt to balance out the failures :-(
Update the project.
Firstly I had to add the contents of ~/.ssh/config/id_rsa.pub as a SSH Public Key on my github account.
Now we need to configure our Post Receive Hook on the Repo we’re testing, so click on the repository, then click on Admin. In there click on Service Hooks and then select Post receive URLS
Now add one with this format
this is defined in config.ru
Once you’ve updated you’re settings you can test that hook. What should happen is the payload should be delivered to your integrity server and the test process should start. It may not, more than likely won’t, so I’d go back to my integrity project and try manual builds from there until you get it to work.
Try out a manual build at http://myintegrityserver.com to see how it goes.
Couple of tips
1. Always have tail -f integrity.log open, it will give you some information about what’s happening.
2. Output the results of the different commands happening in your build so you can see what’s happening in detail. I found this really helpful.
e.g. in the Build Scripts section you could do this
/path/to/bashscript.sh && script/cucumber > /path/to/cucumber.log
you can then tail that log during a build to output any debugging you need
3. The bash scripts and whatever code you put into the Build Scripts section of the app will run in the new build folder. If you’re having problems running anything just cd into that new build and try running the commands there. NB, you must be the same user that apache is running as, which is the same user that owns the integrity files and folders and you’re apps files and folder.
Now when anyone pushes to our master branch of our application on github, our complete test suite runs and we all get notified of whether or not the tests passed in our campfire room. Now the fun never ends :-)