|
1 | 1 | #!/bin/sh |
2 | | -# docker-entrypoint.sh -- fix bind-mount permissions, then drop to non-root. |
| 2 | +# docker-entrypoint.sh -- fix bind-mount permissions, then run the server. |
3 | 3 | # |
4 | | -# When /app/data is a bind mount, the host directory's ownership may not match |
5 | | -# the container's "chronicle" user. This script runs as root to ensure the data |
6 | | -# directory is writable, then exec's the server as the unprivileged user. |
| 4 | +# When running as root (default), this script fixes /app/data ownership and |
| 5 | +# drops to the "chronicle" user via su-exec. |
| 6 | +# When running as non-root (e.g. Cosmos Cloud sets user: chronicle), it |
| 7 | +# creates subdirectories if writable and runs the server directly. |
| 8 | +# |
| 9 | +# For bind mounts with non-root user, ensure the host directory is owned by |
| 10 | +# the container's UID: chown -R $(id -u chronicle):$(id -g chronicle) /path/to/data |
7 | 11 |
|
8 | 12 | set -e |
9 | 13 |
|
10 | | -# Ensure the media subdirectory exists and is owned by chronicle. |
11 | | -mkdir -p /app/data/media |
12 | | -chown -R chronicle:chronicle /app/data |
13 | | - |
14 | | -# Drop privileges and exec the main process. |
15 | | -exec su-exec chronicle "$@" |
| 14 | +if [ "$(id -u)" = "0" ]; then |
| 15 | + # Running as root: ensure dirs exist, fix ownership, drop privileges. |
| 16 | + mkdir -p /app/data/media |
| 17 | + chown -R chronicle:chronicle /app/data |
| 18 | + exec su-exec chronicle "$@" |
| 19 | +else |
| 20 | + # Running as non-root (platform-enforced user). |
| 21 | + # Try to create media dir; if it fails, the bind mount host dir needs |
| 22 | + # its ownership fixed (see comment above). |
| 23 | + if ! mkdir -p /app/data/media 2>/dev/null; then |
| 24 | + echo "WARNING: Cannot create /app/data/media -- bind mount not writable by UID $(id -u)." >&2 |
| 25 | + echo "Fix: chown -R $(id -u):$(id -g) <host-data-dir>" >&2 |
| 26 | + fi |
| 27 | + exec "$@" |
| 28 | +fi |
0 commit comments