Django is a great framework for developing websites but as with most projects there isn't a particular focus on the system administration side of running a real site. There are great instructions describing the source-level changes you'll want to make and what you'll need to configure your webserver to do but … what about afterwards?
The process of deploying any site has a few basic steps: update the code, apply any database changes and reload the running site. How people choose to do this varies wildly but in the Python world it tends to involve a lot of manual work setting up the Python environment and running commands by hand or using a tool such as Fabric or Buildout to run those commands for you.
This approach works but it has a few drawbacks:
None of these are new problems - in fact, the BSD and Linux communities have been working on package managers for the last decade or two, which is why you can install a brand new Linux system with hundreds of applications in less time than it takes to bring a large Python website up on a new server.
A well-behaved application is going to do a few things:
For Django apps, I'm using the following conventions:
<VirtualHost example.org:80>
ServerName example.org
ErrorLog logs/my_app.errors.log
CustomLog logs/my_app.access.log combined
LogLevel info
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT56:+HIGH:+SSLv3:+TLSv1
SSLCertificateFile "/etc/httpd/ssl.crt/my_app.crt"
SSLCertificateKeyFile "/etc/httpd/ssl.key/my_app.key"
Include /opt/my_app/deploy/apache_common.conf
</VirtualHost>
try:
import local_settings
except ImportError:
logging.warning("No local settings - running in development mode")
This is where you put things like database username and password, production email contact addresses, etc.
git archive --format=tar --prefix=my_app-1.0/ my_app-1.0 | gzip -9 > ~/rpmbuild/SOURCES/my_app-1.0.tar.gz
svn export . /tmp/my_package
tar -C /tmp -cjf ~/rpmbuild/SOURCES/my_app.tar.bz2
rpmbuild -ba --clean SPECS/my_site.spec
If you want to see what files your RPM will install, use RPM's query options: rpm -q --fileprovide -p RPMS/noarch/my_site.rpm
For future releases the process is simple: update the specfile if you've changed your dependencies (add, remove, change versions, etc.) and recompile.
Here's an example project containing an RPM specfile and the general recommended site structure. There are a few key things you will want to customize:
%post and %install sections can contain arbitrary shell scripts, allowing you to do things like run `manage.py syncdb`, push updated schema to Solr, etc. If this gets too complicated I recommend writing a Python program or Django management command which does the actual work.