Deploying Django with Fabric
December 2nd, 2008 | Published in django | 3 Comments
Since I started using Ruby and Rails last year, I’ve come to know and like Capistrano, the deployment utility that makes pushing code and databases around a lot easier than it has to be. We use Capistrano for internal and external deploys at the Times, and it’s a pretty robust tool. While working on Fumblerooski and some other projects, I was looking for a Python-based deployment utility (although, to be fair, Capistrano can be used with just about anything), and I came upon Fabric.
If you haven’t heard of Capistrano, it and similar utilities save you the trouble of typing a series of commands to login to remote servers, update your code, bounce Apache, clean up files, etc. You put all that stuff into a single file that just runs those tasks when you need them. If you have an app that you’re regularly updating, it’s a godsend.
If you’ve used Capistrano before, Fabric is pretty similar in terms of its philosophy; there’s a fabfile in your project (like a capfile for Capistrano) that contains the configuration details and your commands for deploying code, restarting servers and the like. What I like about Fabric is that it makes virtually no assumptions about what you want to do. It doesn’t default to Subversion, or git, as a VCS. It doesn’t assume much of anything, which can be a little daunting if you’re used to a bit of code generation.
But that’s actually a good thing, because you end up writing fabfiles that only contain the stuff you need to have and nothing else. There’s a Django app that ties Fabric more tightly to Django’s manage.py utility, but I’m not sure I see the need for it. Without it, you type something like “fab deploy” instead of “python manage.py fab deploy”. But it’s there.
One thing I’d like to see from Fabric is better handling for sudo tasks on remote servers. This has been raised on the mailing list, and hopefully it gets resolved soon. Otherwise I’m really enjoying its simplicity and will use it for my Django apps going forward.
December 2nd, 2008 at 11:33 pm (#)
I also use and enjoy fabric, without the django pluging, which I haven’t tried. I’ve also never tried Capistrano with Django, so I don’t have any criticism. It might be awesome.
But the thing I like most about fabric is how I can easily customize a variety of upkeep and monitoring tasks in addition to revision control on application code. Plus it’s really easy for my simple brain to read.
FWIW, my chosen shazam line is:
$ fab prod deploy reboot
December 3rd, 2008 at 11:39 am (#)
Fabric is great, and the developers are even more so. They’ve routinely answered questions and even turned around quick feature improvements in response to issues on the mailing list. Kudos to them.
I wrote some quick fab code to interact with MySQL database dumping and loading, etc, since that’s the most frequent beast I struggle with. I wrote it up in a quick blog post here:
http://nicksergeant.com/blog/programming/developing-and-deploying-applications-fabric-and-subversion
Happy coding!
April 26th, 2009 at 2:10 pm (#)
[...] is a fab command that can run remote and sudo commands on one or more remote hosts. So let’s deploy Django using fab. Here’s an example fabfile with 2 commands: restart and nginx. These commands should only be [...]