We’ve been using Capistrano to deploy Afrigator to our various servers for a while now. I can seriously not complain or say anything bad about Capistrano. Thing is, I’m more familiar with Python than I am with Ruby, thus for me it just makes more sense for me to use Fabric.
Here is a small example of how to write a typical deploy script with Python Fabric:
First, define your various servers which you need to deploy to. Ideally, you’ll have a test, staging and live server. Thus you’ll set them up as follows.
def test():
config.fab_user = 'test_user_name'
config.fab_hosts = ['test.yourserver.com']
def staging():
config.fab_user = 'staging_user_name'
config.fab_hosts = ['staging.yourserver.com']
def live():
config.fab_user = 'live_user_name'
config.fab_hosts = ['www1.yourserver.com', \
'www2.yourserver.com', 'www3.yourserver.com']
This allows you to deploy your code to the various servers. Please note, you need to setup automatic login for your different servers. See here how to do automatic logins.
Next, write the steps you would take to deploy your site manually:
def deploy():
"Deploy code to servers"
msg = "deploying"
require('fab_hosts', provided_by = [test,staging,live])
local('svn ci -m "$(msg)"')
run('svn export repos /path/to/repository/export/')
run('cp -R /path/to/repository/export/* /path/to/your/site/')
To deploy to the staging server you can run the following command:
$ fab staging let:msg="Reason for check in" deploy
To deploy to the 3 live servers, all you do is:
$ fab live let:msg="Reason for check in" deploy
The command works as follows: fab is the command. live/stating/test are the environments you would like to load. If you said staging, it will do the commands in deploy for the staging server. The last part is the command you want to run. In this instance, deploy.
The let:msg=”Reason for check in” is the coolest bit! It basically allow you to override Fabric variables. If you look closely, in my deploy script I’ve set a variable msg to just say “deploy”. Now that is a stupid SVN message for a commit. In order to commit with meaningful messages, I override the msg variable with my own message. Simple, yet very effective!
You may want to write a number of different functions in a single fabfile. If you have 100 commands and you’re not one hundred percent sure, just do a:
$ fab list
and all the commands available to you will be printed with their description. Fabric rocks! Seriously.
Welcome back! You should subscribe to my RSS feed here.
You should follow me on Twitter here
You should follow me on Gatorpeeps here.


If you still use FTP or SCP or sFTP to deploy projects, you’re missing out big time on the ease of either 




