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:
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:
cp settings.py settings.backup.py
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.Google+