fix: serve collected static files with whitenoise
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 37s
CI/CD Pipeline / Build and Push Images (push) Successful in 18s
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 32s

This commit is contained in:
2026-07-16 15:42:35 +02:00
parent 007cecc8d5
commit 63f59b3799
3 changed files with 33 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ esac
/app/docker/scripts/check-deps.sh /app/docker/scripts/check-deps.sh
python src/manage.py migrate --noinput python src/manage.py migrate --noinput
python src/manage.py collectstatic --noinput
exec gunicorn core.wsgi:application \ exec gunicorn core.wsgi:application \
--bind "0.0.0.0:${PORT:-8000}" \ --bind "0.0.0.0:${PORT:-8000}" \

View File

@@ -284,6 +284,7 @@ USE_TZ = True
STATIC_URL = "/static/" STATIC_URL = "/static/"
STATIC_ROOT = PROJECT_ROOT / "staticfiles" STATIC_ROOT = PROJECT_ROOT / "staticfiles"
STATICFILES_DIRS = [BASE_DIR / "static"] STATICFILES_DIRS = [BASE_DIR / "static"]
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
# Media files # Media files
MEDIA_URL = "/media/" MEDIA_URL = "/media/"

View File

@@ -0,0 +1,31 @@
"""Regression checks for production static-file delivery."""
from pathlib import Path
from django.core.management import call_command
from django.test import Client, override_settings
from settings import base
def test_whitenoise_uses_compressed_manifest_storage():
assert (
base.STATICFILES_STORAGE
== "whitenoise.storage.CompressedManifestStaticFilesStorage"
)
def test_web_startup_collects_static_files_before_gunicorn():
script_path = Path(__file__).parents[1] / "docker" / "scripts" / "start-web.sh"
script = script_path.read_text(encoding="utf-8")
assert "python src/manage.py collectstatic --noinput" in script
assert script.index("collectstatic --noinput") < script.index("exec gunicorn")
def test_whitenoise_serves_collected_swagger_asset(tmp_path):
with override_settings(STATIC_ROOT=tmp_path):
call_command("collectstatic", interactive=False, verbosity=0)
response = Client().get("/static/drf-yasg/style.css")
assert response.status_code == 200
assert response["Content-Type"].startswith("text/css")