Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fabfile and default project layout for deploying Django with Nginx, Apache mod_wsgi, Postgres, and Postfix. I don't use this anymore and I'm not sure you should either.

branch: master

timezone, admin, pytz

latest commit d26dd64405
Andrew Badr authored November 29, 2013
Octocat-spinner-32 project timezone, admin, pytz November 29, 2013
Octocat-spinner-32 server timezone, admin, pytz November 29, 2013
Octocat-spinner-32 .gitignore remove print statement January 11, 2013
Octocat-spinner-32 README.md update ubuntu version in README March 20, 2012
Octocat-spinner-32 TODO todo futzing August 08, 2011
Octocat-spinner-32 fabfile.py a bunch of random fixes August 24, 2012
README.md

Intro

I've used this Fabfile for several real-world Django projects. It makes it easy to bring up a production server and deploy/rollback with atomic symlink swaps. It's expecting you to lay things out in a certain way, but probably it wouldn't be too hard to modify to accommodate other layouts.

It comes bundled with a default Django project that includes a few tweaks I usually use. Feel free to delete this project and replace it with your own.

Watch it used to start and launch site in five minutes: http://www.youtube.com/watch?v=HOC0bEqn1iI (Watch in HD to read what I'm typing)

Subjective bits: http://andrewbadr.com/log/9/django-fabfile/

Feature Details

Features

  • Fabfile for fully automated Django project installation and deploy process on an Ubuntu 11.10 server
  • Stack: nginx, Apache, Django, PostgreSQL, Postfix
  • Cooperates with siblings -- run multiple of these on the same server
  • All services run on a single server

Non-features

  • Sites running across multiple servers (e.g., a separate database server, or multiple web servers). This is available in a branch, but you might not like it.
  • Compatibility with servers running setups other than this one. The Fabfile overwrites configuration files and in general might step on things.
  • Accepting inbound email
  • Configuration tuned for high traffic. Set your own values in the server directory's various config files.
  • Running on servers other than Ubuntu 11.10

Non-configurable, but modifying the source should be easy

  • Runs your site from www.yourdomain.com
  • Static files are served with URL prefix /static/
  • Assumes you're using Git and hosting at GitHub

Caveats

  • I haven't tried running this from Windows

Installation & Usage

Installation

If you're starting a new Django project

  1. Move 'project' to your new project name. This is PROJECT_NAME for the steps below.
  2. Change the "Stuff you're likely to change" settings at the top of fabfile.py
  3. In yourproject/settings.py:
    • Change the PROJECT_NAME and DOMAIN at the top of settings.py to match fabfile.py
    • Modify the SECRET_KEY='' line to use a random key (see comment there for help)
    • Change the ADMINS setting (unless you want me getting your tracebacks)
  4. Generate a keypair using ssh-keygen and put it in the server directory. Upload the public key to GitHub as your project's "Deploy Key".
  5. Consider doing a pip freeze on your server and updating server/requirements.txt with version requirements.

If you're converting an existing Django project

  1. Make things look like you did all the steps above.
  2. If you have to change the Fabfile because something isn't configurable, like the static url prefix, consider submitting a patch to make it a configuration setting.

Out of band project setup

  • GitHub project hosting
  • Server provisioning
  • DNS records
  • SPF records (optional)
  • authorized_keys on server (optional)

Usage

  • To bring the server up for the first time, "fab stage_production bootstrap_everything"
  • To deploy a new version, "fab stage_production simple_deploy"
Something went wrong with that request. Please try again.