terraform-pipeline.yml: Investigate options for running Django migrations
It has been noted that the deploy.yml
template runs the Django migrations as part of the .cloud-run-deploy
jobs - see https://gitlab.developers.cam.ac.uk/uis/devops/continuous-delivery/ci-templates/-/blob/master/auto-devops/deploy.yml#L208. However, this functionality is missing from the terraform-pipeline.yml
template which is aiming to replace the deploy.yml
template as we move towards a more GitOps deployment model.
There are a couple of ways that this can be handled and we should discuss and agree the best way forward at the next refinement.
- Add the migration command to the
apply
jobs in theterraform-pipeline.yml
. This is essentially replicating the current setup, albeit with Terraform doing the actual container deployment. - Add a separate
migrate
job to theterraform-pipeline.yml
before each environment'sapply
job. This would mean that devs could opt to not run themigrate
stage if it wasn't necessary. Although this may be more confusing than it needs to be and runs the small risk that migrations do not get deployed before the new version of the app is deployed by Terraform if a dev fails to run themigrate
job. - Add the migration command to the docker image entrypoint script. This is convenient as it doesn't require a change to the pipeline. However, I'm not sure it's optimal to have every new instance of a container checking migrations, especially when autoscaling with Cloud Run etc.
Discuss!