Simple & Easy Deployment with Fabric and Virtualenv
In the process of prepping Gondola CMS for public consumption, we’ve grown from having a developer (me), to having a development team. One pain point that quickly arose was the amount of time it took for new developers to setup a local development environment. In addition to our source code, the project depends on nearly a dozen other Django apps and Python packages. Initially, we simply tracked the requirements in a text file, but it required a lot of manual work to get them downloaded and installed.
Necessity is the Mother of Invention
Of course, this problem has been tackled many, many times before1. As I looked into what was out there, my first thought was that most of the existing options were far too complex for our needs. If I didn’t grok a system after clicking around the docs for 10 minutes or so, I moved on. The tool I eventually decided on was Fabric.
I was attracted to Fabric, primarily because I found it simple and easy to understand. Unfortunately, I didn’t find a lot of information on using it for local buildouts, so I forged ahead building my own.
fab bootstrap
Our needs were simple. I wanted a script that would:
- Setup our standard directory structure
- Download source code from a number of disparate systems, properly handling branches and version requirements
- Load the source into a virtualenv
The results of a few hours of hacking are available as lincoln-loop-deploy. Our local buildout is now a simple process:
- Get requirements: easy_install Fabric virtualenv
- Checkout our buildout repository (only contains 2 files fabfile.py and fabreqs.py)
- Build project: fab bootstrap
- Activate the virtualenv: source ./ve/bin/activate
My goal is to keep the fabfile.py totally generic so it can be used across all our projects. While it serves my purposes for now, we’ll likely be extending it in the future to allow for remote deployment, source updates, and additional version control systems. Yann and I also discussed an option to work without the virtualenv requirement for those who haven’t seen the light yet don’t want to use it.
Do you have a better way of doing things? We’d love to hear what you have to say. Patches are always welcome too.
1 Ian Bicking’s summary of build systems
Comments
Got something to say?
This was written on December, 7 2008 and is filed in django, gondola.
Our Products
Categories
- SEO
- accessiblity
- code
- company news
- django
- gondola
- open source
- portfolio
- presentation
- review
- screencast
- software
- subversion
- trailmapping
- wordpress
Archives
- December, 2009
- November, 2009
- October, 2009
- September, 2009
- June, 2009
- April, 2009
- February, 2009
- December, 2008
Elsewhere
What we’ve been up to online
-
pushed to inline-widget at lincolnloop/django-geotagging
Pete, 1 week, 3 days ago -
pushed to inline-widget at lincolnloop/django-geotagging
Pete, 1 week, 3 days ago -
pushed to inline-widget at lincolnloop/django-geotagging
Pete, 1 week, 3 days ago -
pushed to inline-widget at lincolnloop/django-geotagging
Pete, 1 week, 3 days ago -
pushed to inline-widget at lincolnloop/django-geotagging
Pete, 1 week, 3 days ago -
pushed to inline-widget at lincolnloop/django-geotagging
Pete, 1 week, 3 days ago -
pushed to master at lincolnloop/django-startproject
Pete, 1 week, 3 days ago -
pushed to inline-widget at lincolnloop/django-geotagging
Pete, 1 week, 4 days ago -
pushed to inline-widget at lincolnloop/django-geotagging
Pete, 1 week, 5 days ago -
pushed to inline-widget at lincolnloop/django-geotagging
Pete, 1 week, 6 days ago -
@HenrikJoreteg +1 on scansnap & evernote. almost seamless. Only complaint: each scan opens a new evernote window when scanning many docs
Pete, 1 week, 6 days ago -
Selenium RC is amazing! After groking it, I had an EC2 instance and taking screenshots of our sites in the big 5 browsers in about 30 min.
Pete, 3 weeks, 3 days ago -
closed issue 10 on lincolnloop/django-startproject
Pete, 4 weeks ago -
pushed to master at lincolnloop/django-startproject
Pete, 4 weeks ago -
pushed to master at lincolnloop/django-startproject
Pete, 1 month ago


The fab bootstrap worked fine for me.
I have used fabric for various uploading tasks, but only recently started working on some automation for client deployments. Some of this stuff will be quite helpful!
Hello. I’m learning about python and django and i’m very interested in help you with Gondola CMS.
If you want an spanish translation for the app, write me.
Congratulations on you work
I’d also have a look at Dan Fair’s article on using django recipe for zc.buildout that does very similar things:
http://www.stereoplex.com/two-voices/a-django-development-environment-with-zc-buildout
HTH
Dan
It would be interesting to see if pip (http://pypi.python.org/pypi/pip) could be used for this, since it supports creating and installing from “Requirements Files”.
Nice timing – I just started to think about building something that whould’ve looked a bit like your solution ;)
It would be nice to be able to update an existing deployment just by changing the requirements file and running fab update or something like that…
I think this is an awesome solution. We’ve taken your fabfile.py and made some improvements. We’ll share them as soon as we’re confident they are actually improvements.
Alex brings up an interesting point. Could we handle new requirements in a nice way? Maybe “fab update”.
Yep, `fab update` needs to be in there. If any of you feel like tackling it before I do, it should reparse fabreqs.py, updating any packages that aren’t tied to specific version number and installing new packages that have been added.
I got curious about “Yann and I also discussed an option to work without the virtualenv requirement for those who haven’t seen the light yet don’t want to use it.”
Is there something wrong about virtualenv? I’m new to python and just read a little about it and it seemed like a good idea?
I modified my version of the fabfile to detect the version of python in use rather than using a hardcoded python2.5.
I also played around with a fresh build of python (2.6) to work out the minimum baseline Python install for the virtualenv to inherit:
- PIL
– PyCrypto (from pypi)
– Virtualenv
– fabric
– setuptools
– mercurial
– readline (mac)
– mysqldb (if you need it)
These things are either need to run virtualenv and fabric or can’t be installed easily under a virtualenv.
After doing this, I now have a requirements file that allows me to build a complete working environment for my sites (I put my site code in the requirements file as well) with just one command. Now I just need to get it playing nice with pydev and mod_wsgi (shouldn’t be too challenging).