Package: heroku_tools
Opinionated tools for managing Heroku applications, based on the workflow used by YunoJuno, outlined inthis blog post.BackgroundWe (YunoJuno) have been deploying our application to Heroku for the past three years, and we’ve evolved a set of Fabric scripts to help us with this process. This project is extracted out of that work. It includes CLI applications for deploying apps to Heroku and managing configuration via remote config vars.It isopinionated, and enforces a specific workflow, and can (currently) be used for deploying only Django applications.WorkflowThe workflow that this application supports is based ongitflow, and works in the following way.The project has two permanent git branches -masteranddev(as per gitflow), and three Heroku environments:live,uatanddev.The dev branch is deployed to thedevenvironment, and is where integration testing is done. Developers working locally on feature branches do their own testing locally, and when they are finished, submit pull requests for merging their branch back into dev. When this is done, dev is pushed.When a release is due, dev is merged into master, and the master branch is pushed touatandliveenvironments. The only difference between these two is thatuatis not public, and so is used for final testing (e.g. User Acceptance Testing). This may map to “pre-production” or “staging” in other projects.(Following this model, code is pushed ‘up’ through the environments fromdevtouattolive. At the same time, data is migrated down through the environments fromlivetouattodev. Theuatenvironment is where the latest code meets the latest data - hence it being used for testing. This project will also contain data migration and anonymisation scripts once ported over.)Heroku DeploymentsDeploying an application to Heroku is often described as being as simple as a singlegit push, which is technically correct. That will update your application. However, in most real-world scenarios this is wholly inadequate.In most cases it looks more like this:See what’s in the proposed deployment (git log)Turn on the app maintenance pagePush up the codeRun collectstatic ^^Run post-deployment tasks - eg: database migrationsTurn off maintenance pageWrite a release noteInform others of the deploymentThis project encapsulates these steps.^^ Collectstatic will run automatically as part of the default Herkou Django buildpack, but if you are pushing content to CDN this may not be the desired behaviour, and you may wish to runcollectstaticexplicitly post-deployment.$heroku-toolsdeploydev$heroku-toolsdeploydev--branchfeature/xxxThe command to apply Migrations is specified via the configuration file as a post_deploy action. This is a change compared to version of Heroku-tools < 0.3DeploymentsUPDATEThis project has been scaled back in ambition - the deploy function is no longer generic, and is specifically written for Django.This project contains adeploycommand line application that reinforces this workflow. It takes a number of options (rundeploy--helpfor the full list), but by default it will enforce the workflow described above. A deployment the the dev environment will push the dev branch, uat will push master, etc. It will run a diff against the remote Heroku repo to determine the list of commits (and changed files) that will be pushed, and infer from that whether to run the migrations and collectstatic.The workflow specifics are configured in application / environment files:application:# the name of the Heroku applicationname:live_app# the default branch to push to this applicationbranch:master# use the heroku pipeline:promote featurepipeline:True# the upstream application to promoteupstream:staging_app# add a tag to the commit using the release version from Herokuadd_tag:False# add a tag, and write a release note into the tag message (experimental)add_rich_tag:False# Heroku application environment settings managed by the conf commandsettings:DJANGO_DEBUG:TrueDJANGO_SECRET_KEY:foobarDJANGO_SETTINGS_MODULE:my_app.settingsDATABASE_URL:postgres://postgres:postres@heroku.com/my_appConfigurationTheconfigcommand line application incorporates ourconfiguration management process. It sets application environment variables from the settings block in theapplication.conffile. Before applying the settings to the Heroku application it will run a diff against the current value of each setting in the local file. It prints out the diff, so that you can see which settings will be applied, and prompts the user to confirm that the settings should be applied before pushing to Heroku.StatusIn development. Please don’t use right now.