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:
- Commit my code changes to Subversion (I use TortoiseSVN – Yes, I’m running Windows)
- Log in to my Webfaction account via SSH using PuTTy.
- Run a subversion update on media folder
- Back up my settings.py file for good measure
- Run a subversion update on my Django application folder
- If there were model additions, run manage.py syncdb
- 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:
- Django cron on Webfaction James Bennett addresses one of the most frequently asked questions...
- Mobile App on Subdomain with Django I’ve noticed a fairly common pattern arising with mobile and...
- Django: Login Form on Every Page Up to the point, when it has come to Django...
- Django & Djson… er, JSON I must admin this is my first attempt at even...
- 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: django, plink, putty, ssh, subversion, webfaction, windows Posted in: Programming & Internet




12 Responses
You may want to take a look at Fabric: http://docs.fabfile.org/
For me, it’s just a “fab deploy” to deploy.
+1 on Fabric
fab deploy FTW!
No kidding… put South into the mix and ./manage migrate into your fabfile and you can even deploy database changes in one step.
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
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!
PS: If you try South (http://south.aeracode.org/) let us know how you go!
This is a very useful project!
Thanks for sharingl
Hi Dustin
where did yu place yur file ./update.sh on server?
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.
I also use Fabric – it works very well. On another note – can you tell me where you got the theme for this blog? Cheers!
Try fabric, you can do more things easily with fabric.
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