From 9cde50af87f6ace3f0868723142235e52b655b05 Mon Sep 17 00:00:00 2001 From: Lucas Pickering Date: Fri, 18 Aug 2023 20:43:02 -0400 Subject: [PATCH] Run migrations in job instead of API pod --- api/scripts/cmd_prd.sh | 1 - api/src/beta_spray/settings/settings_prd.py | 3 -- deploy/helm/templates/migration.yml | 37 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 deploy/helm/templates/migration.yml diff --git a/api/scripts/cmd_prd.sh b/api/scripts/cmd_prd.sh index 36ab5121..6db274a5 100755 --- a/api/scripts/cmd_prd.sh +++ b/api/scripts/cmd_prd.sh @@ -2,5 +2,4 @@ set -ex -./m.sh migrate gunicorn beta_spray.wsgi -b :8000 diff --git a/api/src/beta_spray/settings/settings_prd.py b/api/src/beta_spray/settings/settings_prd.py index c75589b3..7bcdbdc6 100644 --- a/api/src/beta_spray/settings/settings_prd.py +++ b/api/src/beta_spray/settings/settings_prd.py @@ -16,6 +16,3 @@ # By not starting this URL with /api/, we avoid collisions between URL matches # in nginx STATIC_URL = "/api-static/" - -if not GS_BUCKET_NAME: # noqa F405 - raise ValueError("Media GCS bucket `GS_BUCKET_NAME` not set.") diff --git a/deploy/helm/templates/migration.yml b/deploy/helm/templates/migration.yml new file mode 100644 index 00000000..83a83abb --- /dev/null +++ b/deploy/helm/templates/migration.yml @@ -0,0 +1,37 @@ +apiVersion: batch/v1 +kind: Job +metadata: + # We have to version this because existing jobs can't be overwritten + name: "migrations-{{ .Release.Revision }}" + namespace: "{{ .Release.Namespace }}" +spec: + template: + spec: + containers: + - name: migrations + image: "ghcr.io/lucaspickering/beta-spray-api:{{ .Values.versionSha }}" + command: ["./m.sh", "migrate"] + resources: + requests: + cpu: 50m + memory: 150Mi + env: + - name: BETA_SPRAY_DB_HOST + value: db + - name: BETA_SPRAY_DB_NAME + valueFrom: + secretKeyRef: + name: database-creds + key: database + - name: BETA_SPRAY_DB_USER + valueFrom: + secretKeyRef: + name: database-creds + key: username + - name: BETA_SPRAY_DB_PASSWORD + valueFrom: + secretKeyRef: + name: database-creds + key: password + restartPolicy: Never + backoffLimit: 2