Usually, to update your site, you have to perform repetitive tasks such as setting a maintenance page, stopping cron jobs, creating a database backup, pulling new code from a repository, migrating databases, collecting static files, testing, starting cron jobs again, and unsetting the maintenance page. That's quite a tedious work, where mistakes can occur. Also, you need not forget the different routines for staging site (the one where new features can be tested) and production site (which is shown to the public). Fortunately, there is a Python library called Fabric that allows you to automate these tasks. In this recipe, you will learn how to create fabfile.py
, the script for Fabric, and how to deploy your project on staging and production environments.
The Fabric script can be called from the directory that contains it, as follows:
(myproject_env)$ fab staging deploy
This will deploy the project on the staging server.