This repository includes code for generating a self-extracting zip archive of the code and all of its Python dependencies. We use these archives to deploy the site to a Linux server.

Generating a deployment artifact

Running the script at ./docker/deployable-zipfile/ will start a CentOS 6 container, generate the artifact (via this script), and save it to ./

We use CentOS 6 here, so that the Python modules that include compiled code, will be compiled for the same environment they will be run in.

What's in an artifact?

Here's a (very abbreviated) peek into what's in the zip file:

The file contains the code that runs when the zip file is invoked as a Python module.

The wheels/ directory contains all of our python dependencies, while bootstrap_wheels/ contains modules needed at deployment time, to install everything. and loadenv-init.pth are used to load environment variables from a environment.json file, deployed seperately.

Before the final version of the zip file is saved, we prepend a python "shebang" line, #!/usr/bin/env python. This, combined with described above, is what makes the file executable and self-extracting.

Deploying an artifact

We currently use Ansible to prepare servers to run an artifact, and to do the actual deployment. If we ignore some specifics and quirks of our environment, the basic steps look something like this:

  1. copy the artifact to the system
  2. execute the artifact, with the -d (destination) argument, ./ -d destination-dir. This will unpack the files, create a new virtualenv, and install all of the wheels in wheels/ into that virtualenv. Important Note: This should be done with the same Python interpreter that will run the application. For example, on our servers this means using scl enable to specify a particular Python version from Software Collections.
  3. put an environment.json file in place, in your destination-dir
  4. run Django utilities like 'collectstatic' and 'migrate'
  5. update a symlink to point to the latest release
  6. restart your WSGI server.