Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use subversion to deploy web applications?

We are a small team of 4 developers working on a web application. We use trac+svn on a shared server for version control and ticketing and we are happy and satisfied with this. The same shared server also hosts our web application. The application itself is a Perl CGI application that uses CGI::Application and a moderate number of standard (CPAN) and custom Perl modules that are installed in the usual (/usr/lib/perl...) and a few unusual locations (/home/user/lib/perl..). While the broad details might be irrelevant, the most important point is that the location/layout of libraries on our development machines is different from that on the production (shared) server. We have to live with this as a given. The library layout is identical on all development machines though.

Here is a typical, but clearly sub-optimal work-cycle that my colleagues and I follow:

  1. Code and test on development machines
  2. Checkout/Commit/Update our code onto the SVN
  3. Periodically "svn export" onto the appropriate DocumentRoot of the server
  4. Hand edit the exported tree to set the library includes match the library layout on the server
  5. Test application on live server, raise tickets for each other
  6. Go to 1

Clearly there must be a better way and would appreciate hearing from others who might be handling this better than we are. For example is there a way to svn export and fix the library locations in an automated way? Or is there some completely different way to handle this situation than we have been doing so far.

Thank you for your attention

like image 442
Ya. Perelman Avatar asked Apr 27 '09 19:04

Ya. Perelman


4 Answers

You should have scripts that do this for you that can be run from a local box. Mine always look something like:

$> checkout from source or copy from working
$> run sed/perl -pi/copy to convert configs to the production values 
     (ie cp production.config myconfig)
$> upload to web server (rsync/ssh/ftp/etc)
$> ssh $SERVER migrate_db, set permissions, run unit tests, etc

The last one requires ssh access which I always look for but everything else can be done locally. You'd usually have a set of dev configs and a set of production configs (or a script to convert from dev to production

One step uploads are always a really good idea.

like image 78
Alan Jackson Avatar answered Nov 05 '22 09:11

Alan Jackson


Keep a config file (e.g. config.pl) that stores all the system-dependant paths and variables. Then set the svn:ignore property on this file so that it is never commited. This will allow you to easily keep a local configuration script per system that is separate from the commited tree.

like image 31
moinudin Avatar answered Nov 05 '22 11:11

moinudin


If you don't have the possibility of mirroring your development server in production, why can't you mirror your production server in development? That might take some reconfiguring, but what's the risk? Everything's checked into svn.

But maybe that really, really isn't an option for you. My preference for deploying web applications is to do an svn checkout and then run a symlinking script. The idea is that you write a system of rules that logically maps the contents of one folder to the contents of another. Of course, if you drop folder symlinks in your document root, you have to tell Apache to follow them.

Frankly, the absolute safest scenario would be to set up a virtual machine that you can configure exactly like your production machine. This way you can actually test the contents of your deployment script and submit tickets. Then, when the problem is discovered, you modify the script to make it more likely that development deployment will follow the new and improved procedure.

And, as a side note: I much prefer to use svn checkouts in place rather than svn exports. It shouldn't be hard (especially if you use a deployment script) to make sure that apache or whatever your web server is doesn't have permission on the .svn folders. Ideally, anything you can do to make an svn rollback a one-line command is absolutely key.

like image 2
David Berger Avatar answered Nov 05 '22 11:11

David Berger


If this is a Linux box you could write a cron job to take care of this for you. You could use sed/awk to replace the needed strings in the code and svn export works fine from a cron job. You would need to maintain the script but it seems faster than doing it by hand every time.

like image 1
trent Avatar answered Nov 05 '22 09:11

trent