Inspired by capistrano, django-deploy is a fabfile to aid quick and easy setup and deployment of django-powered websites. Configured for use with git, ubuntu, apache virtual hosts, nginx, mod_wsgi and mysql / mysqlite3.
Download the fabfile into the root of a django project (alongside manage.py
etc.):
git clone git://github.com/martinogden/django-deploy.git fabfile
Add the following settings to your settings.py
file
FABRIC_DOMAIN = 'your-domain.com'
FABRIC_USER = 'Your SSH username'
FABRIC_PASSWORD = 'Your SSH password'
FABRIC_HOST = 'Your server IP'
FABRIC_REPO = 'git@your-git-repository.git'
Optional:
FABRIC_RELEASES = number of old releases to keep (default 5)
From the root of your django project you can run the fab commands. The commands are in the format fab <ENVIRONMENT> <COMMAND>
e.g. fab staging deploy
.
Example: fab production boostrap
.
- create apache / nginx / mod_wsgi configuration files
- create a new virtualenv
- checkout the git repository
- create static / media folders
- Create database and initial schema (not including migrations)
Example: fab production deploy
.
- checkout the latest release of the git repository
- backup the current version - keeps last 5 (
settings.FABRIC_RELEASES
) - run south migrations
- collect any new static files and move them to
settings.STATIC_ROOT
Example: fab production rollback
.
Move project back to previous state, update migrations and static files
Example: fab production test deploy
.
Run all tests locally. Useful if chained before a deploy command as the deploy will not run if any tests fail.
Example: fab production create_database
.
Creates remote database and runs syncdb
. Currently uses your ssh user and
password, @todo add facility to override this.
Example: fab production sync_local_database
.
Update your local environment with data from remote database. Useful for quickly accessting data to work with in development.
Example: fab production sync_local_media
.
Same as above, but syncs remote user-uploaded media.
Example: fab production django_admin:'migrate app 0002'
.
Small wrapper around remote django-admin.py
command.
- django
- fabric
- south (for database migrations)