Skip to content

Commit

Permalink
Merge branch 'main' into miketheman/fix-naive-date-to-datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin authored Sep 30, 2024
2 parents 60d01d8 + 18e1d74 commit 1f559d3
Show file tree
Hide file tree
Showing 15 changed files with 729 additions and 731 deletions.
10 changes: 10 additions & 0 deletions Dockerfile.static
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ruby:2.7.8-bullseye AS static

RUN mkdir /code
WORKDIR /code

COPY Gemfile Gemfile.lock /code/

RUN bundle install

COPY . /code
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
source "https://rubygems.org"

group :media do
gem "compass", "~>0.12.2"
gem "sass", "~>3.2.5"
gem "susy", "~>1.0.5"
gem "compass", "~>0.12.7"
gem "sass", "~>3.2.19"
gem "susy", "~>1.0.9"
end

group :development do
Expand Down
19 changes: 11 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
GEM
remote: https://rubygems.org/
specs:
chunky_png (1.2.7)
compass (0.12.2)
chunky_png (1.4.0)
compass (0.12.7)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
sass (~> 3.2.19)
foreman (0.61.0)
thor (>= 0.13.6)
fssm (0.2.10)
sass (3.2.6)
susy (1.0.5)
sass (3.2.19)
susy (1.0.9)
compass (>= 0.12.2)
sass (>= 3.2.0)
thor (0.17.0)
Expand All @@ -19,7 +19,10 @@ PLATFORMS
ruby

DEPENDENCIES
compass (~> 0.12.2)
compass (~> 0.12.7)
foreman (~> 0.61.0)
sass (~> 3.2.5)
susy (~> 1.0.5)
sass (~> 3.2.19)
susy (~> 1.0.9)

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions bin/static
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
cd static
bundle exec sass --compass --scss -I $(dirname $(dirname $(gem which susy))) --trace --watch sass:sass
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ services:
test: ["CMD", "redis-cli","ping"]
interval: 1s

static:
command: bin/static
build:
dockerfile: Dockerfile.static
volumes:
- .:/code

web:
build: .
image: pythondotorg:docker-compose
Expand Down
20 changes: 20 additions & 0 deletions fastly/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,23 @@ def purge_url(path):
return response

return None


def purge_surrogate_key(key):
"""
Purge a Fastly.com Surrogate-Key given a key.
"""
if settings.DEBUG:
return

api_key = getattr(settings, 'FASTLY_API_KEY', None)
service_id = getattr(settings, 'FASTLY_SERVICE_ID', None)
if api_key and service_id:
response = requests.request(
"POST",
f'https://api.fastly.com/service/{service_id}/purge/{key}',
headers={'Fastly-Key': api_key},
)
return response

return None
Empty file added pydotorg/management/__init__.py
Empty file.
Empty file.
14 changes: 14 additions & 0 deletions pydotorg/management/commands/postdeploy.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 8 additions & 2 deletions pydotorg/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@
MAILING_LIST_PSF_MEMBERS = "psf-members-announce-request@python.org"

### Fastly ###
FASTLY_API_KEY = False # Set to Fastly API key in production to allow pages to
# be purged on save
FASTLY_SERVICE_ID = False # Set to a Fastly Service ID in production to allow
# purges by Surrogate-Key
FASTLY_API_KEY = False # Set to Fastly API key in production to allow
# pages to be purged on save

# Jobs
JOB_THRESHOLD_DAYS = 90
Expand Down Expand Up @@ -349,6 +351,10 @@

GLOBAL_SURROGATE_KEY = 'pydotorg-app'

### pydotorg.settings.cabotage.add_surrogate_keys_to_static

STATIC_SURROGATE_KEY = 'pydotorg-static'

### PyCon Integration for Sponsor Voucher Codes
PYCON_API_KEY = config("PYCON_API_KEY", default="deadbeef-dead-beef-dead-beefdeadbeef")
PYCON_API_SECRET = config("PYCON_API_SECRET", default="deadbeef-dead-beef-dead-beefdeadbeef")
Expand Down
8 changes: 7 additions & 1 deletion pydotorg/settings/cabotage.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
},
}

def add_surrogate_keys_to_static(headers, path, url):
headers['Surrogate-Key'] = STATIC_SURROGATE_KEY

WHITENOISE_ADD_HEADERS_FUNCTION = add_surrogate_keys_to_static

EMAIL_HOST = config('EMAIL_HOST')
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
Expand All @@ -63,7 +68,8 @@
PEP_REPO_PATH = None
PEP_ARTIFACT_URL = config('PEP_ARTIFACT_URL')

# Fastly API Key
# Fastly
FASTLY_SERVICE_ID = config('FASTLY_SERVICE_ID')
FASTLY_API_KEY = config('FASTLY_API_KEY')

SECURE_SSL_REDIRECT = True
Expand Down
Loading

0 comments on commit 1f559d3

Please sign in to comment.