#!/bin/sh set -eu DATA_DIR="${DATA_DIR:-/app/data}" mkdir -p "$DATA_DIR/media" "$DATA_DIR/firmware" echo ">> data dir: $DATA_DIR" warn_localhost() { case "$1" in *@127.0.0.1:*|*@localhost:*|redis://127.0.0.1:*|redis://localhost:*) echo "!! $2 指向 127.0.0.1/localhost;容器内这是容器自己,不是宿主机。" >&2 echo " 宿主机服务请用 host.docker.internal(需 extra_hosts)或宿主机局域网 IP;" >&2 echo " Compose 服务请用服务名(如 postgres / redis)。" >&2 ;; esac } warn_localhost "${DATABASE_URL:-}" DATABASE_URL warn_localhost "${REDIS_URL:-}" REDIS_URL # 首次使用空目录挂载时,把镜像内置的码表种子放进去。 if [ ! -f "$DATA_DIR/regions.json" ] && [ -f /app/seed/regions.json ]; then cp /app/seed/regions.json "$DATA_DIR/regions.json" fi cd /app/server if [ "${RUN_MIGRATIONS:-1}" = "1" ]; then echo ">> alembic upgrade head(失败时先检查 .env 的 DATABASE_URL)" python -m alembic upgrade head fi echo ">> uvicorn :${BACKEND_PORT:-8000} (workers=${WEB_CONCURRENCY:-2})" exec python -m uvicorn app.main:app \ --host 0.0.0.0 \ --port "${BACKEND_PORT:-8000}" \ --workers "${WEB_CONCURRENCY:-2}" \ --proxy-headers \ --forwarded-allow-ips "${FORWARDED_ALLOW_IPS:-*}"