From 4729534c7391522bb4889b05fba7cd0d43cdef09 Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Wed, 25 Sep 2024 10:51:08 -0400 Subject: [PATCH] add a postdeploy step to purge surroage-keys for static files --- Procfile | 1 + pydotorg/management/__init__.py | 0 pydotorg/management/commands/__init__.py | 0 pydotorg/management/commands/postdeploy.py | 14 ++++++++++++++ 4 files changed, 15 insertions(+) create mode 100644 pydotorg/management/__init__.py create mode 100644 pydotorg/management/commands/__init__.py create mode 100644 pydotorg/management/commands/postdeploy.py diff --git a/Procfile b/Procfile index 16deb5f5b..cce927ff8 100644 --- a/Procfile +++ b/Procfile @@ -2,3 +2,4 @@ release: python manage.py migrate --noinput web: bin/start-nginx gunicorn -c gunicorn.conf pydotorg.wsgi worker: celery -A pydotorg worker -l INFO worker-beat: celery -A pydotorg beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler +postdeploy: python manage.py postdeploy diff --git a/pydotorg/management/__init__.py b/pydotorg/management/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pydotorg/management/commands/__init__.py b/pydotorg/management/commands/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pydotorg/management/commands/postdeploy.py b/pydotorg/management/commands/postdeploy.py new file mode 100644 index 000000000..17c518e31 --- /dev/null +++ b/pydotorg/management/commands/postdeploy.py @@ -0,0 +1,14 @@ +from django.core.management.base import BaseCommand +from django.conf import settings + +from fastly.utils import purge_surrogate_key + + +class Command(BaseCommand): + """ Do things after deployment is complete """ + + def handle(self, *args, **kwargs): + # If we have a STATIC_SURROGATE_KEY set, purge static files to ensure + # that anything cached mid-deploy is ignored (like 404s). + if settings.STATIC_SURROGATE_KEY: + purge_surrogate_key(settings.STATIC_SURROGATE_KEY)