File tree 7 files changed +50
-3
lines changed
7 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ release: python manage.py migrate --noinput
2
2
web : bin/start-nginx gunicorn -c gunicorn.conf pydotorg.wsgi
3
3
worker : celery -A pydotorg worker -l INFO
4
4
worker-beat : celery -A pydotorg beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
5
+ postdeploy : python manage.py postdeploy
Original file line number Diff line number Diff line change @@ -20,3 +20,23 @@ def purge_url(path):
20
20
return response
21
21
22
22
return None
23
+
24
+
25
+ def purge_surrogate_key (key ):
26
+ """
27
+ Purge a Fastly.com Surrogate-Key given a key.
28
+ """
29
+ if settings .DEBUG :
30
+ return
31
+
32
+ api_key = getattr (settings , 'FASTLY_API_KEY' , None )
33
+ service_id = getattr (settings , 'FASTLY_SERVICE_ID' , None )
34
+ if api_key and service_id :
35
+ response = requests .request (
36
+ "POST" ,
37
+ f'https://api.fastly.com/service/{ service_id } /purge/{ key } ' ,
38
+ headers = {'Fastly-Key' : api_key },
39
+ )
40
+ return response
41
+
42
+ return None
Original file line number Diff line number Diff line change
1
+ from django .core .management .base import BaseCommand
2
+ from django .conf import settings
3
+
4
+ from fastly .utils import purge_surrogate_key
5
+
6
+
7
+ class Command (BaseCommand ):
8
+ """ Do things after deployment is complete """
9
+
10
+ def handle (self , * args , ** kwargs ):
11
+ # If we have a STATIC_SURROGATE_KEY set, purge static files to ensure
12
+ # that anything cached mid-deploy is ignored (like 404s).
13
+ if settings .STATIC_SURROGATE_KEY :
14
+ purge_surrogate_key (settings .STATIC_SURROGATE_KEY )
Original file line number Diff line number Diff line change 285
285
MAILING_LIST_PSF_MEMBERS = "[email protected] "
286
286
287
287
### Fastly ###
288
- FASTLY_API_KEY = False # Set to Fastly API key in production to allow pages to
289
- # be purged on save
288
+ FASTLY_SERVICE_ID = False # Set to a Fastly Service ID in production to allow
289
+ # purges by Surrogate-Key
290
+ FASTLY_API_KEY = False # Set to Fastly API key in production to allow
291
+ # pages to be purged on save
290
292
291
293
# Jobs
292
294
JOB_THRESHOLD_DAYS = 90
349
351
350
352
GLOBAL_SURROGATE_KEY = 'pydotorg-app'
351
353
354
+ ### pydotorg.settings.cabotage.add_surrogate_keys_to_static
355
+
356
+ STATIC_SURROGATE_KEY = 'pydotorg-static'
357
+
352
358
### PyCon Integration for Sponsor Voucher Codes
353
359
PYCON_API_KEY = config ("PYCON_API_KEY" , default = "deadbeef-dead-beef-dead-beefdeadbeef" )
354
360
PYCON_API_SECRET = config ("PYCON_API_SECRET" , default = "deadbeef-dead-beef-dead-beefdeadbeef" )
Original file line number Diff line number Diff line change 53
53
},
54
54
}
55
55
56
+ def add_surrogate_keys_to_static (headers , path , url ):
57
+ headers ['Surrogate-Key' ] = STATIC_SURROGATE_KEY
58
+
59
+ WHITENOISE_ADD_HEADERS_FUNCTION = add_surrogate_keys_to_static
60
+
56
61
EMAIL_HOST = config ('EMAIL_HOST' )
57
62
EMAIL_HOST_USER = config ('EMAIL_HOST_USER' )
58
63
EMAIL_HOST_PASSWORD = config ('EMAIL_HOST_PASSWORD' )
63
68
PEP_REPO_PATH = None
64
69
PEP_ARTIFACT_URL = config ('PEP_ARTIFACT_URL' )
65
70
66
- # Fastly API Key
71
+ # Fastly
72
+ FASTLY_SERVICE_ID = config ('FASTLY_SERVICE_ID' )
67
73
FASTLY_API_KEY = config ('FASTLY_API_KEY' )
68
74
69
75
SECURE_SSL_REDIRECT = True
You can’t perform that action at this time.
0 commit comments