Files

49 lines
1.7 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# =============================================================================
# 追光AI APP 容器启动入口
# - 校验 .env
# - 跑 prisma migrate deploy(生产环境,安全前向迁移)
# - 启动 next start
# =============================================================================
set -e
cd /app
# Seed data volume if empty
if [ ! -f /app/data/bot-characters.json ] && [ -d /app/data-seed ]; then
echo "[entrypoint] Seeding data volume..."
cp -r /app/data-seed/* /app/data/
fi
# 1) .env 校验
if [ ! -f /app/.env ]; then
echo "[entrypoint-app] FATAL: /app/.env not found. Mount .env file into container."
exit 1
fi
# 让 .env 对 next start 可见(Next.js 14 在 production 下也会读 .env)
set -a
. /app/.env
set +a
# 移除 NODE_TLS_REJECT_UNAUTHORIZED 以消除警告(在 prisma 迁移之前)
unset NODE_TLS_REJECT_UNAUTHORIZED
# 2) 跑迁移(幂等;不阻塞启动)
echo "[entrypoint-app] Running prisma migrate deploy..."
npx prisma migrate deploy --schema=prisma/schema.prisma 2>&1 | tail -20 || {
echo "[entrypoint-app] WARN: migrate failed, continuing (DB schema may be ahead of migrations)"
}
# 3) 重新生成 Prisma client
# 防止持久卷(zhuiguang-ai_bot-prisma)中的旧 client 与 schema 不一致
# 导致运行时 "Unknown field xxx for select statement" 错误
echo "[entrypoint-app] Regenerating Prisma client..."
npx prisma generate --schema=prisma/schema.prisma 2>&1 | tail -5 || {
echo "[entrypoint-app] WARN: prisma generate failed, continuing with existing client"
}
# 4) 启动 Next.js
echo "[entrypoint-app] Starting next start on port ${PORT:-8301}..."
exec node_modules/.bin/next start --port ${PORT:-8301} --hostname 0.0.0.0