fix(media): refuse local disk when a NAS share is configured
CI / build (push) Has been cancelled

A bind-mounted host directory made the app report storage as ready while
media landed on the container host's local filesystem, so the NFS export was
never actually used. mediaStorage() now reads the mount table: a share written
as host:/export is only accepted when the media root is on a network
filesystem, otherwise uploads, edits and filing are blocked with the real
device and the fix. Settings and the Media page show the detected filesystem
and host-mount steps, README section 9 documents the OS-level mount (including
Docker-in-LXC) with docker-compose.nfs.yml as the alternative, and the E2E
suites use path-style shares for local test directories.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-21 00:45:36 +00:00
parent 2fc71883d7
commit 982f9048e1
14 changed files with 439 additions and 33 deletions
+47 -6
View File
@@ -459,21 +459,43 @@ The daily job runs instances → slots → complete in that order. Run the scrip
Original event photos and videos are stored **only** on the configured media storage share — it is their primary home, not a backup. Without a named share and a writable mounted path, the uploader and the photo editor are disabled with a warning; the app never falls back to storing media inside the container or on the `archive-data` volume. Photos live in `<share>/<folder>/events/<eventId>/`, and each video keeps its original, renditions, poster and sidecar together in `<share>/<folder>/videos/<eventId>/<videoId>/`.
A bind-mounted host directory works too — set `MEDIA_ARCHIVE_DIR` to any local path and name it in Settings. To store media on a NAS:
Mounting is the deployment's job; **the app never mounts anything** and never writes event media inside the container. The recommended setup is a normal OS-level mount of the export on the Docker host, bind-mounted into the container at `/archive`.
**Step 1 — mount the export on the host (as root):**
```bash
sudo apt-get install -y nfs-common
sudo apt-get install -y nfs-common # nfs client
sudo mkdir -p /mnt/glenloch-media
sudo mount -t nfs nas.example.org:/export /mnt/glenloch-media
```
Persist it in `/etc/fstab`:
Persist it across reboots in `/etc/fstab`:
```fstab
nas.example.org:/export /mnt/glenloch-media nfs defaults,_netdev,nofail 0 0
```
Set the host path in `.env`, recreate the app, and verify write access as the container user (UID 100):
Running this stack inside a Proxmox LXC container (Docker in LXC) needs one extra step on the Proxmox host, because a plain container may not mount NFS itself:
```bash
# either allow NFS mounts inside the container, then mount there as above
pct set <ctid> -features mount=nfs,nesting=1
pct restart <ctid>
# or mount on the Proxmox host and pass the directory into the container
# (no extra capability needed; the mount must exist first)
pct set <ctid> -mp0 /mnt/glenloch-media,mp=/mnt/glenloch-media
```
**Step 2 — confirm the mount and write access:**
```bash
findmnt -T /mnt/glenloch-media -o TARGET,SOURCE,FSTYPE # SOURCE nas…:/export, FSTYPE nfs/nfs4
sudo chown 100:100 /mnt/glenloch-media # or fix the export's ID mapping
sudo -u '#100' test -w /mnt/glenloch-media && echo writable
```
**Step 3 — bind it into the app and restart.** In `.env`, point `MEDIA_ARCHIVE_DIR` at the host mount:
```dotenv
MEDIA_ARCHIVE_DIR=/mnt/glenloch-media
@@ -481,10 +503,28 @@ MEDIA_ARCHIVE_DIR=/mnt/glenloch-media
```bash
docker compose up -d app
docker compose exec app sh -c 'test -w /archive && echo "archive writable"'
docker compose exec app grep ' /archive ' /proc/self/mounts
# nfs4 nas.example.org:/export /archive nfs4 rw,... ← good
# zfs ssd-main/subvol-125-disk-0 /archive … ← still local disk
```
Adjust NFS export ownership or ID mapping so UID 100 can write. Then, in Settings → Media storage, enter the share name (for example `nas.example.org:/export`) and the storage subfolder, and save. Uploads unlock only after that check succeeds.
Order matters: bind mounts are resolved when the container starts, so mount the export **before** `docker compose up -d app`. A mount added afterwards is invisible inside the app until it is recreated, and a missing host path makes Docker create an empty local directory — which is why the app checks the filesystem rather than trusting the path.
**Step 4 — save it in Settings → Media storage:** enter the share name (for example `nas.example.org:/export`), keep the container path `/archive`, set the subfolder, and save. The panel shows the detected filesystem and free space. Uploads, photo editing and video processing stay blocked — with the exact reason — while the saved share reads like `host:/export` but `/archive` is on a local filesystem; the app never writes media to local disk under a NAS-style share name. A path-style share such as `/archive` is treated as local storage on purpose, for deployments without a NAS.
**Alternative — let Docker mount the export.** `docker-compose.nfs.yml` asks the Docker daemon to mount NFS as the volume behind `/archive`, with no host `/etc/fstab` entry:
```dotenv
NFS_ADDR=nas.example.org
NFS_EXPORT=/export # exported path only, without the server prefix
NFS_VERSION=4 # set 3 for older exports
```
```bash
docker compose -f docker-compose.yml -f docker-compose.nfs.yml up -d
```
This needs the daemon to be allowed to mount NFS (full root, or Docker in an LXC with `mount=nfs`). In an unprivileged container it fails with `operation not permitted`; use the host mount above instead.
### 10. Email delivery
@@ -536,6 +576,7 @@ git switch main
| Wrong links in email | Set `PUBLIC_ORIGIN`; otherwise links derive from the request Host header. |
| Video upload/encode fails | Free disk space on the media storage share and `docker compose logs app` for FFmpeg errors. |
| Uploads/editing are disabled | Settings → Media storage needs a share name and a mounted path that UID 100 can write to; the banner states the exact failure. |
| Uploads are blocked with "not a network mount" | The export is not actually mounted: either add `docker-compose.nfs.yml` (`NFS_ADDR`/`NFS_EXPORT`) or mount it on the host and point `MEDIA_ARCHIVE_DIR` at that mount. `docker compose exec app grep ' /archive ' /proc/self/mounts` shows what the container really has. |
| Cron returns 401 | `CRON_SECRET` is set in `.env` and matches the value read by `/usr/local/bin/media-hub-cron`. |
| Disk filling up | Docker log rotation is capped at 10 MB × 3 per service; remove old backups, exports, and unused media. |