nex_buddy/docker/api-entrypoint.sh

39 lines
1.3 KiB
Bash
Raw Normal View History

2026-11-13 08:23:00 +00:00
#!/bin/sh
set -eu
2026-11-13 06:38:19 +00:00
DATA_DIR="${DATA_DIR:-/app/data}"
mkdir -p "$DATA_DIR/media" "$DATA_DIR/firmware"
2026-11-13 08:23:00 +00:00
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
2026-11-13 06:38:19 +00:00
# 首次使用空目录挂载时,把镜像内置的码表种子放进去。
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
2026-11-13 08:23:00 +00:00
echo ">> alembic upgrade head(失败时先检查 .env 的 DATABASE_URL)"
2026-11-13 06:38:19 +00:00
python -m alembic upgrade head
fi
2026-11-13 08:51:05 +00:00
echo ">> uvicorn :${BACKEND_PORT:-8000} (workers=${WEB_CONCURRENCY:-2})"
2026-11-13 06:38:19 +00:00
exec python -m uvicorn app.main:app \
--host 0.0.0.0 \
2026-11-13 08:51:05 +00:00
--port "${BACKEND_PORT:-8000}" \
2026-11-13 06:38:19 +00:00
--workers "${WEB_CONCURRENCY:-2}" \
--proxy-headers \
--forwarded-allow-ips "${FORWARDED_ALLOW_IPS:-*}"