My fabfile used to manage Django powered sites, using Git and Virtualenv
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



My fabfile used to manage Django powered sites, using Git and Virtualenv.


My goal is use Git for versioning and deploying, Virtualenv for creating known environments and Fabric for automated workflow.

The ideal workflow should look like this:

  • Local development and testing using temporary database and local settings
  • Deployment to staging enviroment, which has the same properties as production one. The only difference is DEBUG = True.
  • Run tests on staging version.
  • If tests runs well, deploy to production environment and tag this version in git.


Three stages, development, staging and production have three related branches in Git: dev, staging and stable.


Stable branch should be probably renamed to production.


Local settings: testing database (SQLite, unless I need run database-specific code), cache disabled, SECRET_KEY = 42, etc.


Production settings with DEBUG = True. This runs on server in virtual environment similar to production one. Accessed on <host>:8080 with HTTP Authentication.


Final version, production settings, visible for all users.


Settings are divided into 4 files under <project_dir>/settings:

  • -- with all common settings, almost everything from original
  • -- inherit from, DEBUG = True, disabled cached, etc.
  • -- inherit from and, just set DEBUG = True
  • -- inherit from, production settings. This is the only file which contains sensitive data as passwords, secret key, etc. All others could be used for debugging purposes.

Example usage

Create in your project directory and add your own environment settings.

from elvard.fabfile import *

env.hosts = ['']
env.project_dir = 'src'
env.activate = 'env/bin/activate'
env.wsgi = ''
env.repository = 'tomas_ehrlich.git'
stages = {'staging': {'master': 'staging',
             'slave': 'dev',
             'directory': '~/dev',
             'settings': 'staging'},
 'stable': {'master': 'stable',
            'slave': 'staging',
            'directory': '~/web',
            'settings': 'production'}}