I was reading The Joel Test and I got to number #2 which says "Can you make a build in one step?" My initial thought was that there aren’t really builds per se in web applications (unless you use ASP.NET). But then I thought, I wonder if I could make publishing my Django application a one step process. So that’s what I set out to do.

Here are the manual steps I go through to publish my Django App:

  1. Commit my code changes to Subversion (I use TortoiseSVN – Yes, I’m running Windows)
  2. Log in to my Webfaction account via SSH using PuTTy.
  3. Run a subversion update on media folder
  4. Back up my settings.py file for good measure
  5. Run a subversion update on my Django application folder
  6. If there were model additions, run manage.py syncdb
  7. Restart apache for good measure

Ok, so maybe the title of this post is a bit misleading because I did not automate step one. Let me explain why though. When I commit code, I sometimes leave debug code in where I don’t want to. I live to verify that I’m not committing changes that shouldn’t be there so I often look at diff files in TortoiseSVN before I commit. That’s just one step that I prefer to keep my eyes on. I suppose you could say that it’s not really part of the publishing process and we assume that publishing comes after committing code changes then yeah, it’s still one step.

My solution is actually a combination of two scripts. I found this app called Plink that is basically PuTTy for your command line. Inside my Django project folder I’ve created a batch script called publish.bat which contains the following:

@echo off
plink -ssh MYDOMAIN.com -l MYLOGIN -pw MYPASSWORD ./update.sh

This essentially logs in to my server via SSH and runs a shell script. Here are the contents of that shell script:

cd webapps/media
svn update
cd ../myapp/myapp
cp settings.py settings.backup.py
svn update
python2.5 manage.py syncdb

That’s basically it. Now I just commit my code and when I want to publish I just double-click on publish.bat and I’m done.