Skip to content

Commit faaa45b

Browse files
authored
Merge pull request #3 from NHSDigital/whitenoise
Self contained image that serves static files
2 parents a1fa81c + e1293f4 commit faaa45b

33 files changed

+198
-15
lines changed

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ COPY --chown=${CONTAINER_USER}:${CONTAINER_GROUP} manage.py ./
6666
ENV DEBUG=0
6767
RUN python ./manage.py collectstatic --noinput
6868

69+
# Remove later once we've set up an external DB
70+
RUN python ./manage.py migrate
71+
6972
EXPOSE 8000
7073

7174
ENTRYPOINT ["/app/.venv/bin/gunicorn", "--bind", "0.0.0.0:8000", "manage_breast_screening.config.wsgi"]

manage_breast_screening/config/settings.py

+37-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
https://docs.djangoproject.com/en/5.1/ref/settings/
1111
"""
1212

13+
import sys
1314
from os import environ
1415
from pathlib import Path
1516

@@ -45,13 +46,7 @@ def boolean_env(key, default=None):
4546
if allowed_hosts_except_localhost:
4647
CSRF_COOKIE_SECURE = True
4748
SESSION_COOKIE_SECURE = True
48-
SECURE_SSL_REDIRECT = True
49-
50-
# Strict transport security:
51-
# https://docs.djangoproject.com/en/5.1/ref/middleware/#http-strict-transport-security
52-
SECURE_HSTS_SECONDS = 60
53-
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
54-
SECURE_HSTS_PRELOAD = False
49+
SECURE_SSL_REDIRECT = False
5550

5651
# Application definition
5752

@@ -67,6 +62,7 @@ def boolean_env(key, default=None):
6762

6863
MIDDLEWARE = [
6964
"django.middleware.security.SecurityMiddleware",
65+
"whitenoise.middleware.WhiteNoiseMiddleware",
7066
"django.contrib.sessions.middleware.SessionMiddleware",
7167
"django.middleware.common.CommonMiddleware",
7268
"django.middleware.csrf.CsrfViewMiddleware",
@@ -115,6 +111,11 @@ def boolean_env(key, default=None):
115111
}
116112
}
117113

114+
STORAGES = {
115+
"staticfiles": {
116+
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
117+
},
118+
}
118119

119120
# Password validation
120121
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
@@ -160,3 +161,32 @@ def boolean_env(key, default=None):
160161
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
161162

162163
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
164+
165+
LOGGING = {
166+
"version": 1, # the dictConfig format version
167+
"disable_existing_loggers": False, # retain the default loggers
168+
"formatters": {
169+
"verbose": {
170+
"format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}",
171+
"style": "{",
172+
},
173+
},
174+
"handlers": {
175+
"console": {
176+
"class": "logging.StreamHandler",
177+
"formatter": "verbose",
178+
"stream": sys.stdout,
179+
},
180+
},
181+
"root": {
182+
"handlers": ["console"],
183+
"level": "DEBUG",
184+
},
185+
"loggers": {
186+
"django": {
187+
"level": "DEBUG",
188+
"handlers": ["console"],
189+
"propagate": False,
190+
},
191+
},
192+
}

manage_breast_screening/config/urls.py

-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,3 @@
2828
),
2929
path("", RedirectView.as_view(pattern_name="clinics:index")),
3030
]
31-
32-
if settings.DEBUG:
33-
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

poetry.lock

+154-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = [{ name = "Your Name", email = "[email protected]" }]
66
license = { text = "MIT" }
77
readme = "README.md"
88
requires-python = ">=3.13"
9-
dependencies = ["django (>=5.1.7,<6.0.0)", "dotenv (>=0.9.9,<0.10.0)", "gunicorn (>=23.0.0,<24.0.0)", "jinja2 (>=3.1.6,<4.0.0)"]
9+
dependencies = ["django (>=5.1.7,<6.0.0)", "dotenv (>=0.9.9,<0.10.0)", "gunicorn (>=23.0.0,<24.0.0)", "jinja2 (>=3.1.6,<4.0.0)", "whitenoise[brotli] (>=6.9.0,<7.0.0)"]
1010

1111
[tool.poetry]
1212
package-mode = false

scripts/copy_nhsuk_frontend.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

3-
cp -r node_modules/nhsuk-frontend/packages/{components,macros,assets} manage_breast_screening/templates/
4-
5-
cp -r node_modules/nhsuk-frontend/dist/nhsuk-* manage_breast_screening/static/
3+
cp -r node_modules/nhsuk-frontend/packages/{components,macros} manage_breast_screening/templates/
4+
cp -r node_modules/nhsuk-frontend/packages/assets manage_breast_screening/static/
5+
cp -r node_modules/nhsuk-frontend/dist/nhsuk-* manage_breast_screening/static/

0 commit comments

Comments
 (0)