A Simple Deploy Script for Django with Venv

2014-09-09 | #django, #solution

Deploying a Django project, provided a decent setup of the project exists, is quite easily done. If you didn't change the models it's a five line script.

Change login and paths to your liking.

#!/bin/bash

# mirror dev verbosely (have a rsync-exluded file ala git ignore specifying filename schemes to ignore)

rsync -av --exclude-from 'rsync-excluded.txt' --delete . user@server:/absolute/project/path

# update required packages via venvs pip, gather static data, update ownership and tell apache to reload project

# make sure your key is installed on the machine you try to ssh from

ssh user@server '/absolute/venv/path/bin/pip install --upgrade -r /absolute/project/path/requirements.txt'

ssh user@server '/absolute/venv/path/bin/python /absolute/project/path/manage.py collectstatic --noinput'

ssh user@server 'chown -R www-data:www-data /absolute/project/path'

ssh user@server 'touch /absolute/project/path/project/folder/wsgi.py'

This script does not take migrations an other DB-changes into account. Small changes can easily done by hand or using the migration scripts from dev, but are not automatically treated here. For more complex cases you should read up up continuous integration strategies.