Deploying web applications can be a real nightmare at times, especially when you have numerous SVN repositories of code which all link together when installed on the server to create your application.

I’ve started using Murder to try and work around the headaches and apart from a very small issue (which I’ll discuss at the end!) it’s working perfectly.

I’m not going to document a “Beginners Guide” here – there are plenty online including ones for PHP Applications and the documentation on GitHub is excellent – instead I’m going to discolse a few hints/tips that I’ve picked up in the past 48 hours which could help you deploy any web application from SVN.

I usually use git (and github) for everything, however our in-house SCM at $DAYJOB is SVN, so that’s what we’ll be referencing here.

Checking out a specific branch

The repo layout that I’m using as an example has the following structure:

MyCoolWebApp
|
--trunk
--releases
    |
    -- Release-<major>.<minor>
--tags

Based on an excellent post by Paul Gross I’ve updated my deploy.rb file to have the following at the top:

I then put the following at the top of my Capfile:

This means that when I run “cap deploy” it asks me which version I want to publish.  I can type the number (“1.5” or “3.6” for example) and it checks out and deploys http://svnserver/svn/mycoolwebapp/release/Release-1.5.

Version Dependencies

One of our repos contains a number of libraries which are relied on by other applications.  This presents an interesting issue where if we upload an app which requires a newer version of the libraries than the ones currently deployed, we find our shipment of fail.  Thankfully we have a version file in the Zend application/configs directory which contains the version number of the currently deployed libraries.

To make use of this I created some custom code in the deploy.rb file as follows:

and then in the Capfile:

So if /var/www/libs/application/configs/version contains a number greater than the version that we know we need for this application, it will deploy.  If the ‘libs’ version is lower than the one required for this application, Capistrano aborts the deployment.

The Issue…

One of the issues that I have encountered with Murder (and I’m still not 100% sure on how to fix it!) is that when you run “cap deploy” with Murder enabled it retains the .svn directories.  This is not a good thing and is something which appears to be avoided by the “:deploy_via :copy” which Murder appears to inherit, however Murder doesn’t “svn export” like “:copy” does, it performs an “svn co” for some reason.

I’m hoping to resolve this soon and as soon as I do, I’ll send a pull request to @lg.

Apart from “the issue”, I’ve found that Capistrano is massively powerful and very quick to pick up, although as with many things I feel it could take some time to master…