07 April 2008

Setting up CruiseControl.rb with/for Git Based Projects

[Updated to refer to official ThoughtWorks CC.rb Git repo.]



I have a new Rails project I'm working on and I use Git/GitHub for source control. It was time to setup continuous integration, and my usual weapon of choice for that is CruiseControl.rb. Here's what I did to get my project setup under CruiseControl.rb with Git, on an Ubuntu 7.10 machine...



Setup for accessing GitHub repo


All I needed to do here was generate an SSH key for my account on the host machine, and then add that key to the allowed keys for my GitHub account.

Prerequisites



  • I setup a builder@mydomain.com email address which will get used by CruiseControl for sending build related emails/notifications.

  • You'll need to determine a port you want CruiseControl to run on, and your strategy for accessing it. For example, I run mine on a port other than port 80, and other than the default 3333. I then proxy that via Nginx, and also use Nginx to password protect access to it (since this is not a public project, etc. This will affect the CC dashboard URL setting specified below. Some notes on this:


    • I did my initial Nginx configuration using err's Nginx config generator. However, this makes a lot of path assumptions, and various other things, so you'll definitely want to go through the resulting file closely. I had a few sites on this server, so it was relatively useful to use this as a base starting point, and then just fix up paths to the access and error logs, and the PID file.

    • Here's a quicky on how to add password protection to an Nginx server (and a specific location).




Install CruiseControl and Do Site Configuration



  1. Cloned the Git version of CruiseControl.rb in location I wanted it (you could also simply download it and expand the tarball): git clone git://github.com/benburkert/cruisecontrolrb.git

  2. The DEPENDENCIES file indicated I needed to have the grit and mime-types gems, so installed those.

  3. Where your projects get stored for CruiseControl.rb is now defined by the CRUISE_DATA_ROOT environment variable, and if you don't set this, it defaults to $HOME/.cruise. I personally changed this to be /var/cruisecontrolrb.
  4. Edit the config/site_configuration.rb (probably need to rename the example version accordingly) to set site-wide settings, such as your email config and so on.

    • For email setup, I use Gmail for domains, so I have a block like this:

      ActionMailer::Base.smtp_settings = {
      :address => "smtp.gmail.com",
      :port => 587,
      :domain => "mydomain.com",
      :authentication => :plain,
      :user_name => "builder@ mydomain.com",
      :password => "password"
      }

    • You'll want to specify the Configuration.dashboard_url setting so URL's work properly.

    • There are a variety of other settings available in the file that you may want to tweak.




Add Project and Configure



  1. Did the usual usual cruise add command to add my project, but with the Git variant: ./cruise add MyProjectName --git-url git@github.com:mylogin/myproject.git (modify the Git project URL for your Git repo of course). Note that you can see all the options by doing a ./cruise add

  2. Create the test database for your project. The easiest way is just to go into $CRUISE_DATA_ROOT/projects/MyProjectName/work and do a rake db:create RAILS_ENV=test. Your first build will have already failed because this hasn't been made, this step hopefully fixes that.

  3. If your log directory isn't in Git, you'll need to go mkdir it, so something like:mkdir $CRUISE_DATA_ROOT/projects/MyProjectName/work/log.



Setup CruiseControl.rb Service/Daemon



  1. Copy the cruisecontrolrb file into /etc/init.d.

  2. I set the port for CruiseControl.rb to run on in the above /etc/init.d/cruisecontrolrb daemon file, by adding "--port 1234" (for example) to the DAEMON_ARGS variable.
  3. Start the CruiseControl.rb daemon as appropriate for your system (e.g. "sudo /etc/init.d/cruisecontrolrb start").



Finally, surf to your cc.rb site on the web and see how your build has done. If you run into build problems, you'll want to look at the cc.rb build logs (if it was your project test/build that failed) which are in the $CRUISE_DATA_ROOT/projects/MyProjectName directory (or rather, the subdirectory in there for the particular build). And Enjoy!

28 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Gigi Ann said...

Congratulations!!You made "Blogs of Note" today;)

Alexi Frest said...

Congrats by me, too.

I should visit blogs like this more often.

librabrunnetevegetarian said...

You are smartalicious! (a word I made up):)
http://librabrunnetevegetarian.blogspot.com

Arjun said...

Wow, im taking classes at my highschool for javascript and java but dang you know so much more.

Congrats on blog of note!

High Power Rocketry said...

: )

K.C. said...

Everyone has their own unique skills. I do not have the same ones that you do. I am most impressed by yours. You might as well be talking alien swheeli to me. That is sad, huh. I am most impressed with you and what you are doing. Keep it going.... K.C.

Brian said...

Congrats!

Jeb said...

Nice job!

Chris said...

Just updated the project setup steps to include creating the test database.

Anonymous said...

One note which may be of help to some: Git has moved fast in the last few months, and has added features the cc.rb fork relies upon. Make sure you have 1.5.3.something. 1.4.something will not work!

On Debian or Ubuntu, do "apt-get update" then "apt-get upgrate git-core" to get the lastest git.

Anonymous said...

Thanks for your help! :)

Anonymous said...

nice blog!!!thanks for the information with http://filestance.com/

Chris said...

@christopher Please do not upload my blog posts to a file sharing service. They are copyrighted (see bottom of page). If you want to personally track them, then I suggest you bookmark them with del.icio.us or your bookmarking solution of choice. Thanks.

Saimon Moore said...

Hi,

Not so long a go I wrote a CC.rb plugin for git myself (http://saimonmoore.net/2007/12/19/git-plugin-for-cruisecontrolrb). It (mostly worked) so I'm very thankful you gone and completed it.

What I still prefer from my approach is the change to the cruise add command. I added --scm option (defaults to svn) to allow multiple scms. The url is still taken from --url.

I even added a patch (http://jira.public.thoughtworks.org/browse/CCRB-167) for that but it seems to have been ignored after some positive initial feedback.

Regards,

Saimon

Chris said...

@Saimon I believe the cc.rb Git version still allows for SVN repos as well. The checkin comments indicate that, and I believe it simply just figures out whether it's SVN or GIT by the URL you supply.

Note that I did not do the Git implementation for CC.rb, Ben Burkett did the work, or spearheaded the work anyway.

Harm said...

I believe you made a small typo in step 4. The file should be called config/site_config.rb instead of config/site_configuration.rb. Otherwise great work!

Chris said...

Harm, good catch! I've updated the entry to correct that file name, thanks.

Anonymous said...

Great article, thanks!

Carlisia said...
This comment has been removed by the author.
Carlisia said...

Chris,

The fork from @benburkert didn't work for me and your instructions on how to add. I got a "all done" msg but the ~/.cruise/projects dir did not have a folder with my project after I ran the 'add'. Nor did @thoughtbot's, same behavior.

What did work was to download CC directly from GH here:

http://github.com/thoughtworks/cruisecontrol.rb/tree/master

They now have support from git, even though in their own website they state they don't.

I figured out the command to run by looking up help, and it was like this:

./cruise add [project-name] --url [source control URL] -s git

Thanks for putting together the details for the complete installation.

Anonymous said...

Sweet..!
Got this up and running in no time.

Unknown said...

Thanks Carlisia ,
I was wasting time making the Git fork of cruisecontrolrb to work.

Arun Kumar said...

To track a remote branch other that master use --branch while adding the project.

Eg:
./cruise add milestone_2 --git-url git@git.assembla.com:project.git --branch milestone_2

Unknown said...

Hello,

Have any of you tried to use ruby 1.9 with CruiseControl.rb and git ? I know officially cruisecontrol.rb supports only 1.8.4 and 1.8.5 but wanted to know if anyone has ported cruisecontrol.rb to ruby 1.9.

Thanks,
Kannan

Chris said...

I've only used it with Ruby 1.8.6. But, it's on GitHub, so you can certainly try it and make any fixes for 1.9 (and contribute them back of course :) I would really doubt that CC would be all that hard to fix up for 1.9.

Jason F said...

I can't find a file called 'cruisecontrolrb' to copy into the /etc/init.d directory. Is the filename correct?

Chris said...

Jason F, sorry for the delay, I've added a link in the original posta bove for the daemon file. But, here's also a direct link: http://gist.github.com/157741.