"Best practices" are very context sensitive, so I will not argue that my methods are better, only that they work for me. I work mainly on small sites, so there are no deployments with multiple servers, CDNs, etc. I need to support the deployment of Webfaction shared hosting, as some customers need the cheapest hosting that they can find. I often have to deploy sites several times in different environments, so recurring deployment scenarios are crucial.
- I do not use pip packages, I install from the .txt requirement. I start my own chishop server with sdists of everything I need, so there aren’t several points of failure during the build process, I also use PIP_DOWNLOAD_CACHE on my development machines to speed up the project’s boot environments, as most of my project requirements overlap a bit.
- I have Fabric Scripts that can automatically configure and configure nginx + Apache / mod_wsgi on Ubuntu VPS or configure the equivalent on Webfaction and then deploy the project.
- I do not use -no-site-packages with virtualenv because I prefer to have slow compiled packages (Python Imaging Library, psycopg2) installed at the system level; too slow and troublesome to do inside each virtual. I had no problems with contaminated system package sites, because I do not pollute it at all. And in any case, you can install another version of something in virtualenv, and it will take precedence.
- Each project has its own virtualenv. I have several bash scripts (not virtualenvwrapper , although many people use it and love it) that automate the deployment of virtualenv for a given project to a known location and setting the project requirements to it.
- The entire deployment process with an open Ubuntu VPS or Webfaction host account on a website works using Fabric.
- Fabric scripts are part of the project source tree, and I run them from a local development check.
- I do not need SCons (what I know).
Deployment
Currently, the new deployment is divided into the following stages:
fab staging bootstrap (server installation and source deployment)fab staging enable (enable the Apache / nginx configuration for this site)fab staging reload_server (reload Apache / nginx configuration).
You can, of course, combine fab staging bootstrap enable reload_server into one command line.
Once these steps are completed, updating the deployment with the new code will be just fab staging deploy .
If I need to cancel the update, fab staging rollback . Nothing particularly magical in the rollback; it just rolls back the code to the last deployed version and transfers the database to a previous state (this requires some metadata to be recorded about the migration state after the database is deployed, I just do it in a text file).
Examples
I have not used the Fabric scripts described in this answer for several years, so they are not supported at all, and I disclaim responsibility for their quality :-) But you can see them at https://bitbucket.org/carljm/django -project-template - in fabfile.py in the root of the repo and in the deploy/ subdirectory.
Carl Meyer Mar 15 2018-10-15T00: 00Z
source share