.comment-link {margin-left:.6em;} <$BlogRSDURL$>

Wednesday, May 07, 2008

Using Cruise Control with Django 

I wanted to set up a Continuous Integration server for our project, and after doing a quick tour of the available options I settled on Cruise Control as one of the better options, even though it doesn't have any python-specific features.

We use mercurial as our source control system, so this example uses mercurial, but resources abound for configuring cruise-control with CVS and SVN if you're using one of those SCCS systems.

  1. Download and install Cruise Control as per http://cruisecontrol.sourceforge.net/gettingstartedsourcedist.html. I used the binary distribution, the latest being 2.7.2 as of this writing.

  2. Creating and populate a work directory as per the Running the Build Loop instructions.  They make the sensible recommendation to keep your working directory separate from your Cruise Control installation directory.  Mine is called "work":
    mkdir -p work/checkout work/logs work/artifacts


  3. Check out your project under work/checkout.

  4. DO NOT bother creating a delegating build script as per the Running the Build Loop instructions.  This is only used if you're using Ant to control your build.

  5. In your work directory, create config.xml, replacing MY_PROJECT_1 with your django root directory.  The following configuration will run "python manage.py test" whenever there are new changes to pull from your mercurial repository.

    <cruisecontrol>
    <project name="MY_PROJECT_1" buildafterfailed="true">
    <listeners>
    <currentbuildstatuslistener file="logs/MY_PROJECT_1/status.txt">
    </currentbuildstatuslistener>
    </listeners>

    <!-- Bootstrappers are run every time the build runs, *before* the modification checks -->
    <bootstrappers>
    <mercurialbootstrapper localworkingcopy="checkout/MY_PROJECT_1">
    </mercurialbootstrapper>
    </bootstrappers>

    <!-- Defines where cruise looks for changes, to decide whether to run the build -->
    <modificationset quietperiod="10">
    <mercurial localworkingcopy="checkout/MY_PROJECT_1">
    </mercurial>
    </modificationset>

    <!-- Configures the actual build loop, how often and which build file/target -->
    <schedule interval="60">
    <exec workingdir="checkout/MY_PROJECT_1" command="python" args="manage.py test">
    </exec>
    </schedule>

    <!-- directory to write build logs to -->
    <log logdir="logs/MY_PROJECT_1">

    <!-- Publishers are run *after* a build completes -->
    <publishers>
    </publishers>
    </log>
    </project>
    </cruisecontrol>


  6. If you're using mercurial, mercurialbootstrapper won't allow you to specify a username or password for hg pull, so edit the .hg/hgrc in your checked out directory to add authentication to your url.  Note that this means your password is stored in plain text on your local machine and will be exposed when doing pulls across the network.

    [paths]
    default = https://username:password@host/path


  7. Optionally copy dashboard-config.xml from the Cruise Control install directory into your work directory. This'll allow you to view the dashboard at http://yourhost:yourport/dashboard.  It's pretty nice, I recommend it.

  8. Start up your server FROM YOUR WORK DIRECTORY. 

    cd work
    <cruise-control-install-dir>/cruisecontrol.sh


If everything went according to plan, you should now be able to view your builds at http://localhost:8080/dashboard.

Currently, Cruise Control doesn't seem to recognize the django test output format, so it won't show individual testcases.  However, if your tests pass the build will succeed, and if your test fail the build will fail.

Resources
  1. http://cruisecontrol.sourceforge.net/

Comments: Post a Comment


This page is powered by Blogger. Isn't yours?