kirche-einfach/backend/entrypoint.sh

29 lines
1 KiB
Bash

#!/bin/sh
# Backend entrypoint (dev + prod): migrate, then serve.
# APP_ENV=dev (set via devcontainer.json containerEnv, attached container
# only) enables autoreload. Anything else runs the plain production server.
set -e
cd /srv/kirche-einfach/backend
# Runtime SQLite file lives in the bind-mount: ensure the dir exists and is
# owned by vscode (the entrypoint runs as root, but the editor runs as
# vscode — a root-owned data/ dir made the DB unwritable).
mkdir -p data
if id vscode >/dev/null 2>&1; then
chown -R vscode:vscode data 2>/dev/null || true
fi
/opt/venv/bin/alembic upgrade head
# Migrate ran as root: hand the (possibly just created) DB files back to
# vscode so editor-run commands stay writable.
if id vscode >/dev/null 2>&1; then
chown -R vscode:vscode data 2>/dev/null || true
fi
if [ "${APP_ENV:-prod}" = "dev" ]; then
exec gosu vscode /opt/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload --proxy-headers
else
exec gosu vscode /opt/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000 --proxy-headers
fi