FAQ | This is a LIVE service | Changelog

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.

  1. Add the migration command to the apply jobs in the terraform-pipeline.yml. This is essentially replicating the current setup, albeit with Terraform doing the actual container deployment.
  2. Add a separate migrate job to the terraform-pipeline.yml before each environment's apply job. This would mean that devs could opt to not run the migrate 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 the migrate job.
  3. 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!