The IJC Digital Blog

Posted by: Matt Mansour 8 years, 3 months ago (0 comments)

Fabric and Git have made my life much easier. I am working on a project that is on a server farm. Deploying changes to django models, views and templates from my local machine to each server on the server farm is as easy as typing two commands in the Terminal on Mac:

fab commit_to_hub
fab deploy

Here is my fab file if you're interested. It is called "" and it sits in the root of your Django project. It also assumes you have a git repository set up in the root of your Django project:

from fabric.api import local, run, env, cd, hosts

code_dir = "/home/username/webapps/mysite/"
env.user = "username"

def commit_to_hub():
    message = raw_input("Enter a git commit message:  ")
    local("git add . && git commit -m \"%s\"" % message)
    local("git push origin master")

@hosts('', '', '')
def deploy():
    with cd(code_dir):
        run("git pull origin master")
        run("touch mysite.wsgi")

The function commit_to_hub() pushes all modified files from my local git repository to my central repository on

The function deploy() logs in to each server defined in @hosts, then pulls the files from into the git repository located in the project root on each server. 

Keep in mind this is not robust enough for production deployments. But during early development stages it gets the job done.

Current rating: 3.9