One Click Django Project Publishing

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
pause

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
../apache2/bin/restart

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.

Related posts:

  1. Django cron on Webfaction James Bennett addresses one of the most frequently asked questions...
  2. Mobile App on Subdomain with Django I’ve noticed a fairly common pattern arising with mobile and...
  3. Django: Login Form on Every Page Up to the point, when it has come to Django...
  4. Django & Djson… er, JSON I must admin this is my first attempt at even...
  5. Webfaction Review I was looking at my web stats and noticed I...

Related posts brought to you by Yet Another Related Posts Plugin.

May 15, 2009  Tags: , , , , , ,   Posted in: Programming & Internet

12 Responses

  1. Arthur - May 15, 2009

    You may want to take a look at Fabric: http://docs.fabfile.org/
    For me, it’s just a “fab deploy” to deploy.

  2. bill - May 15, 2009

    +1 on Fabric

    fab deploy FTW!

  3. Jonas - May 15, 2009

    No kidding… put South into the mix and ./manage migrate into your fabfile and you can even deploy database changes in one step.

  4. Dustin - May 15, 2009

    Thanks guys. I haven’t heard of Fabric before. I just saw South yesterday and I was going to look into it. I wanted to get something for migrations so I could be as cool as those smug Rails developers ;)

  5. Rich - May 15, 2009

    Fabric offers the bonus that you can have multiple tasks inside the one wrapper.

    This means that you can have one script to do for example:

    fab deploy2test
    fab deploy2prod
    fab rollback-prod (assuming your fab task kept track of the previous SVN revision).

    Cheers!

  6. Rich - May 15, 2009

    PS: If you try South (http://south.aeracode.org/) let us know how you go!

  7. 墨尔本 - May 15, 2009

    This is a very useful project!
    Thanks for sharingl

  8. vishal - June 6, 2009

    Hi Dustin
    where did yu place yur file ./update.sh on server?

  9. Melvin from Car Hire New Zealand - December 1, 2009

    Automation has always been greek and latin to me. Dustin, I think I have to read your posts several times to get what is on my mind. I was thinking about a automated script to enhance the ip address look up of hosted pages. I know there are several apps available already, but I wish to do some custom made app with some niche features.

  10. Alex from Niche Blueprint 2 Bonus - December 9, 2009

    I also use Fabric – it works very well. On another note – can you tell me where you got the theme for this blog? Cheers!

  11. tzangms - March 3, 2010

    Try fabric, you can do more things easily with fabric.

  12. Craig from Instant Money Code Bonus - March 4, 2010

    I’ve read that Django was designed to be used in a newsroom situation…supposedly it is good for building applications although the very idea of doing so scares the heck out of me!

Leave a Reply