[Solved]-Fabric + buildout as opposed to Fabric + pip + virtualenv

17đź‘Ť

âś…

Summary: Pip only installs python packages and there’s more you need to do, obviously. You can do most of the extra work in buildout with the advantage that buildout does it for you both locally and on the server. Fabric has to do less, that way. The drawback is buildout’s extra complexity, so if a couple of custom fabric commands is enough for you, that might be preferable for you. So: how does the trade-off work for you?

The long version:

Pip is good at installing python packages for your project. Buildout is good at setting up almost everything for a project (including python packages). That’s the difference in goals.

Now… you bring fabric into the mix. With pip+fabric, you can call pip from within fabric to grab all the python packages and then you use fabric itself to set up everything else. An apache/nginx config file, creation of a couple of directories (“var/log/”), etc.

With buildout+fabric, you’ll have configured buildout already to do a lot of the things like creating directories and generating files from templates and setting up supervisor and setting up a cronjob to fire up supervisor upon @reboot. So the fabfile has to do less.

So… you swap responsibilities. Everything you can do in buildout, you can do in fabric. Everything you can do in buildout, you can do with custom python (or shell) scripts in combination with pip (“read the README for the extra commands you have to do”).

Buildout is a good place to do things if it is an integral part of your project. Think about it like this: if you need it both in production on the server and locally on your development machine, you’re better off doing it in buildout. Otherwise you have to run fabric on your local machine, too. You can do it, but…

I use fabric in combination with buildout, myself. Buildout is for setting up the project itself, fabric for everything around it. Some examples:

  • Actually cloning the buildout from git on the production server.

  • Git pull (and checkout of the proper tag).

  • Restarting supervisor.

My suggestion: look on pypi for buildout recipes to see if they are handy for you. Do they save you enough work to make it worthwhile to dive into the extra complexity that a full buildout configuration means? If you don’t get enough out of buildout, you might be better off with just fabric+pip and a bunch of custom commands in your fabric file.

3đź‘Ť

Take a look at fabtools which adds a lot of nice buildout functionality into your fabfile. I’ve worked with all sorts, Chef, Puppet (sledgehammer for a walnut) Ansible and Fabric. I find Ansible great for devops teams who are stuck, but don’t want to learn a language, but personally, a well organised Fabric project wins hands down.

👤Ben Hughes

Leave a comment