Fix club logo 404 in production and persist uploads

/media/* was only routed when DEBUG=True, so uploaded club logos
404d in production regardless of storage backend. Route it whenever
local-disk storage is in use instead, and give web a persistent
volume for MEDIA_ROOT so uploads survive a rebuild.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-06 20:41:33 +02:00
parent 30b464eb56
commit 5b8ab72982
4 changed files with 25 additions and 4 deletions

View File

@@ -34,9 +34,13 @@ Caddy terminates TLS, so without it Django believes every request is plain HTTP:
`header_up X-Forwarded-Proto`); don't remove either.
**4. Uploads must move to object storage before the second app server.**
Club logos go to `MEDIA_ROOT` on local disk. On one box that is fine. On two, a logo
uploaded to node A is a 404 on node B. Setting `AWS_STORAGE_BUCKET_NAME` switches the
default storage to S3 — do it *before* you scale, not during.
Club logos go to `MEDIA_ROOT` on local disk by default. `compose.yaml` mounts a `media_data`
volume so that survives a rebuild, and `rosterchief/urls.py` serves `/media/*` itself whenever
`AWS_STORAGE_BUCKET_NAME` is unset — Caddy only reverse-proxies, it never serves media on its
own, so without that route every logo 404s even on one box. On two boxes local disk stops
working regardless: a logo uploaded to node A is still a 404 on node B, since nothing shares
the volume between them. Setting `AWS_STORAGE_BUCKET_NAME` switches the default storage to S3
— do it *before* you scale, not during.
**5. PDF invoices need native libraries.**
WeasyPrint binds to pango/cairo. The image installs them; a bare-metal deploy would need

View File

@@ -19,6 +19,11 @@ services:
env_file: .env.production
ports:
- "127.0.0.1:${WEB_PORT:-8001}:8000"
volumes:
# Uploaded club logos, while storage is local disk (see rosterchief/urls.py). Without
# this, a rebuild or recreate wipes MEDIA_ROOT even though the container itself keeps
# running fine in between.
- media_data:/app/media
depends_on:
db:
condition: service_healthy
@@ -53,3 +58,4 @@ services:
volumes:
pgdata:
media_data:

View File

@@ -32,6 +32,11 @@ services:
build: .
restart: unless-stopped
env_file: .env.production
volumes:
# Uploaded club logos, while storage is local disk (see rosterchief/urls.py). Without
# this, a rebuild or recreate wipes MEDIA_ROOT even though the container itself keeps
# running fine in between.
- media_data:/app/media
depends_on:
db:
condition: service_healthy
@@ -70,3 +75,4 @@ volumes:
pgdata:
caddy_data:
caddy_config:
media_data:

View File

@@ -39,5 +39,10 @@ if settings.DEBUG:
if settings.BROWSER_RELOAD_AVAILABLE:
urlpatterns += [path("__reload__/", include("django_browser_reload.urls"))]
# Club logos are uploads: runserver has to serve MEDIA_ROOT itself.
if not settings.AWS_STORAGE_BUCKET_NAME:
# Gated on the storage backend, not on DEBUG: local disk is the default until a bucket is
# configured (see settings.STORAGES), and Caddy only reverse-proxies — it never serves
# /media/* itself — so without this route every uploaded club logo 404s in production too.
# Once AWS_STORAGE_BUCKET_NAME is set, club.logo.url points straight at the bucket and this
# route is simply never hit.
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)