From e70bc7846a319785e35fe7db3dfd98d38ddbadaa Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Fri, 7 Jun 2024 20:28:47 +0100 Subject: Update site to run migrations in an init container In accordance with updates from python-discord/site#1338 this changes the way migrations are run. Previously, migrations would be run all from within the manage.py execution process with the command being manually spawned using Django internals. After python-discord/site#1338 merges the Dockerfile will directly invoke gunicorn and bypass manage.py to simplify the process and avoid problems with shared database contexts. Hence, we need to manually run migrations using an init container. With testing there is no additional delay in doing this as spinning up an init container is cheap and we don't cut over any traffic until the site passes a healthcheck anyway. --- kubernetes/namespaces/web/site/deployment.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'kubernetes/namespaces/web') diff --git a/kubernetes/namespaces/web/site/deployment.yaml b/kubernetes/namespaces/web/site/deployment.yaml index bdb4073..abaf28d 100644 --- a/kubernetes/namespaces/web/site/deployment.yaml +++ b/kubernetes/namespaces/web/site/deployment.yaml @@ -13,6 +13,19 @@ spec: labels: app: site spec: + initContainers: + - name: migrations + image: ghcr.io/python-discord/site:latest + imagePullPolicy: Always + command: + - sh + - -c + - "poetry run python manage.py migrate" + envFrom: + - secretRef: + name: site-env + securityContext: + readOnlyRootFilesystem: true containers: - name: site image: ghcr.io/python-discord/site:latest -- cgit v1.2.3