Files
microfish/backend/docker_entrypoint.sh
Kunthawat Greethong 42208c4f5a fix: run alembic migrations before starting services
Production image had no DB migration step, so a fresh container had an
empty database: the durable worker queried the 'jobs' table before it
existed and crash-looped with sqlalchemy OperationalError 'no such table:
jobs' (supervisor restart loop).

- Add backend/docker_entrypoint.sh: fail-fast if DATABASE_URL is unset,
  run 'alembic upgrade head' (idempotent), then exec supervisord.
- Dockerfile CMD now runs the entrypoint.
- supervisor: fix nodaemon typo, stream stdout/stderr to /dev/stdout +
  /dev/stderr so worker errors are visible in container logs, and give
  worker startsecs/startretries.

Verified locally: entrypoint bash syntax ok, alembic upgrade head
idempotent, jobs + 19 tables created, worker --once exits 0 after migrate
(previously exit 1 with no-such-table). Worker/schema tests 11 passed.
2026-08-31 15:16:59 +07:00

27 lines
901 B
Bash

#!/usr/bin/env bash
# Docker entrypoint for CrowdSight production image.
#
# Runs database migrations to head BEFORE starting any service, so that the
# backend (gunicorn) and the durable worker never query tables that do not
# exist yet (fixes worker crash-loop: "no such table: jobs").
#
# - Require DATABASE_URL to be set (fail fast with a clear message).
# - Run `alembic upgrade head` (idempotent; no-ops when already at head).
# - Then exec supervisord to run nginx + backend + worker.
set -euo pipefail
cd /app/backend
if [[ -z "${DATABASE_URL:-}" ]]; then
echo "[entrypoint] FATAL: DATABASE_URL is not set. Refusing to start." >&2
exit 1
fi
echo "[entrypoint] Running database migrations (alembic upgrade head)..."
uv run alembic upgrade head
echo "[entrypoint] Migrations complete."
echo "[entrypoint] Starting supervisord (nginx + backend + worker)..."
exec /usr/bin/supervisord -n