Home
Using Fabric for deploying server software

Fabric - a tool for writing deployment scripts

Deploying a new version of server-side software is not trivial. Here are a few things that I need to do while deploying a new version of App Translator (written in Go) from my Mac dev computer to a production server:
Doing this by hand every time would be slow and tedious. Iteration speed matters.
The solution is automation, but that’s tricky since it involves operations both on the local machine (like prepare the source for upload) and remote server (like compiling the sources on the server).
Luckily, I’m not the first person to encounter this problem which is why Fabric exists.
Fabric is both a tool written in Python and a library of Python code for writing automatic deployment scripts.

Installation

On my Mac I’ve installed Fabric with sudo easy_install pip; sudo pip install fabric

Usage basics

The basics of Fabric are:
As an example, I only have one action named deploy so to deploy a new version, I run fab deploy.

Remote execution is via ssh

The code is deployed to Unix-based servers via ssh, so for convenience you can set up password-less (public key based) login for the account you use for deployment.
The code running locally runs under your account.
You need to specify which account on the server to use.
You can run an action against a single server or multiple servers at once.

Possibilites

Fabric can run arbitrary code both locally and on the server, so the possibilities are, literally, limitless.
My App Translator deploy script is an example of a fairly complex script.
What you can learn from it:
I’ve used Fabric in 3 of my projects and it does what it supposed to do well.
If I was writing new project from scratch, I would automate essentially everything related to setting up a new instance (it doesn’t make sense to do it for existing projects since they’re already set up).
programming
Feb 13 2023

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you: