We have a number of Oracle APEX products of which are released in a weekly schedule. This is part of an automated script which is currently running.
We want to add to that a release of Heroku hosted Django web apps which are git controlled.
In the Heroku dashboard for an app, you can click Deploy Branch:
I want to be able to do the equivalent of this, plus run a command to update the database (typically
python3 manage.py migrate
on a weekly basis.
Question is, how would I achieve this? I'm hoping a few lines of a python script should be achievable...?
I have attempted to do this from CLI but that does not appear to be an option. The Heroku documentation is very involved and has taken me round in circles several times, so need a basic 'how to do this' answer before I look at the Heroku docs again.
Since you have already enabled GitHub integration, the easiest solution is to enable automatic deployment on merges to master
. This may be more (or less) frequently than your weekly plan, but I would argue that this is a benefit, not a drawback.
If you really want to deploy on that weekly schedule, you are probably better off using the regular git push
deployment method instead of the GitHub method. Configure your remote once, then simply git push heroku main
(or master
) when you want to deploy.
In either case, automatically running your migrations can be done via a release phase task in your Procfile
, e.g.:
web: gunicorn myproject.wsgi
release: python manage.py migrate
The release phase enables certain tasks to be run before a new release of an app is deployed. The release phase can be useful for tasks such as:
- Sending CSS, JS, and other assets from the app’s slug to a CDN or S3 bucket
- Priming or invalidating cache stores
- Running database schema migrations
If a release phase task fails, the new release is not deployed, leaving the current release unaffected.