Deploying Django apps to Heroku (#3)
In the third (probably not final) post on our deployment process, our Fabric
script has become intelligent enough to manage deployment options on our
behalf.
First a quick recap. As I've posted previously, YunoJuno is a Django app,
hosted on Heroku. We use Fabric to manage deployments, which, as is the
Heroku way, start with a git push, and then add various additional options
that may be required to update the app - database migrations, static content
publication, fixture loading etc. All of this is wrapped up with automated
management of the site maintenance page, and hooked into HipChat for team
notifications.
In my last post on the subject I explained how our Fabric script uses the
latest Heroku release commit hash to determine the git diff prior to any new
deployment. It outputs the individual commits included in the deployment, as
well as the files that have changed - which can be used to sanity check which
options have been set. For instance, if you are deploying without a static
collection step, but you notice that a .gif icon is in the changed files, then
you can abort the deployment and change the options.
In the latest update we have wrapped all this information up together, to
allow the Fabric script itself to determine the deployment options (these
can always be overridden, but the default is now to allow Fabric to set them automatically).
It's a fairly blunt process at the moment:
- All deployments require a git push, as that is the definition of a deployment
- If any files include "migrations" in the path, then run migrations
- If any files include "fixtures" in the path, then load fixtures
- If any known static file extensions are found, publish static content to CDN
If you do set your own options, and the deployment disagrees with your selection,
then you are prompted to confirm that you wish to override those options -
again, as a simple sanity check.
It works surprisingly well. Instead of having to think through the options
a deployment is now as simple as defining the target environment:
$ fab heroku_deploy_app:uat
Git changelog since latest release (v81):
* 4ea1479 Improved warning message for search validation errors.
The following files have changed:
* [redacted]/views.py
Options have been automatically set to a value of 1 from the
contents of the deployment.
----------------------------
Target environment: uat
Git branch: master
Git remote: git@heroku.com:[redacted].git
Force push: False
Preboot: True
Heroku app: [redacted]
Options: 1
[1] Git push: True
[2] Syncdb: False
[4] Migrations: False
[8] Load fixtures: False
[16] Collect static: False
----------------------------
Please confirm your intention to continue by typing in '245631' at the prompt:
This will continue to evolve, particularly in light of yesterday's Heroku
'pipeline' announcement - which should speed up deployments, and reinforce
the uat->live deployment workflow (which we 'encourage' but don't always
enforce).
Making Freelance Work