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/
- 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
- 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
serverdirectory's various config files.
- Running on servers other than Ubuntu 11.10
- Runs your site from www.yourdomain.com
- Static files are served with URL prefix /static/
- Assumes you're using Git and hosting at GitHub
- I haven't tried running this from Windows
- Move 'project' to your new project name. This is PROJECT_NAME for the steps below.
- Change the "Stuff you're likely to change" settings at the top of fabfile.py
- 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)
- 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".
- Consider doing a
pip freezeon your server and updating server/requirements.txt with version requirements.
- Make things look like you did all the steps above.
- 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.
- GitHub project hosting
- Server provisioning
- DNS records
- SPF records (optional)
- authorized_keys on server (optional)
- To bring the server up for the first time, "fab stage_production bootstrap_everything"
- To deploy a new version, "fab stage_production simple_deploy"