October archive
How I deploy saebyn.info
Tags: django fabric git pip python virtualenv
Sun Oct 18 11:24:57 2009A few months ago I drank the koolaid and began using git on my new projects. When I started working on this new blog site I created a git server on my VPS using gitosis. I keep my entire Django project in the repository along with all of the static media and other scripts, which is a pretty standard practice.
Every time I push changes to the gitosis server, it results in calling a hook script that pulls changes from the live branch of the repository into the live website root, and pulls changes from the master branch into the testing website root. When I want to push my changes to the live website, I simply re-base the live branch to where the master branch is at and then push that branch to the server.
The server is running Apache 2 with mod_wsgi, and I'm using Apache to serve static media for now. I wouldn't necessarily suggest serving media files like this for a higher traffic site. I'm using this same server to host a few other Django projects, not all of which use the same version of Django or other Python packages. Fortunately I came across virtualenv before I started setting all of this up. In a nutshell, virtualenv lets you have a complete set of Python modules that are installed outside of your server's main Python module directory. This allows you to have multiple sets of Python modules whose versions differ.
I didn't want to have to maintain all of these Python virtual environments manually, installing each package for each project/virtualenv by hand, so I turned to pip. pip allows me to create a “requirements.txt” file which defines which packages I want to install, either from subversion or from pypi, along with a specific revision, or an exact or minimum version.
To bring this all together I used another great piece of Python software called Fabric to handle the details of my deployment process. Here's the “fabfile” I'm using for this site: fabfile.py.