-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
57 lines (45 loc) · 2.3 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
57 lines (45 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
set -e
cd /app
node ./scripts/install-banner.cjs --startup
# Next.js standalone uses process.env.HOSTNAME for bind(). Docker injects a non-empty HOSTNAME (container id),
# so we must set this here — not only in the image ENV — so it wins over the runtime default.
export HOSTNAME=0.0.0.0
export HEKOTI_ENFORCE_PROD_SECRETS=1
# Auto-generate WEBHOOK_SECRET / AUTH_PENDING_SECRET / HEKOTI_TOTP_ENCRYPTION_KEY when unset
# (persisted under uploads volume — see scripts/ensure-prod-secrets.cjs). Set HEKOTI_AUTO_SECRETS=0 to require manual .env.
eval "$(node ./scripts/ensure-prod-secrets.cjs --export)"
# If Compose (or .env) did not set DATABASE_URL, build it from POSTGRES_* (same defaults as postgres service).
if [ -z "${DATABASE_URL:-}" ]; then
u="${POSTGRES_USER:-hekoti_user}"
p="${POSTGRES_PASSWORD:-hekoti_password}"
d="${POSTGRES_DB:-hekoti_db}"
h="${POSTGRES_HOST:-hekoti-postgres}"
export DATABASE_URL="postgresql://${u}:${p}@${h}:5432/${d}?schema=public"
fi
if [ "${HEKOTI_SKIP_MIGRATE:-0}" = "1" ]; then
echo "HEKOTI_SKIP_MIGRATE=1: skipping prisma migrate deploy"
exec env HOSTNAME=0.0.0.0 PORT="${PORT:-3310}" node server.js
fi
if [ ! -f prisma/schema.prisma ]; then
echo "ERROR: /app/prisma/schema.prisma is missing in the image."
echo "Rebuild the image from the current repo Dockerfile (it must COPY prisma/ into the runner stage)."
exit 1
fi
if [ ! -f prisma.config.ts ]; then
echo "ERROR: /app/prisma.config.ts is missing in the image (required for Prisma 7 migrate + datasource URL)."
exit 1
fi
if [ -z "${DATABASE_URL:-}" ]; then
echo "ERROR: DATABASE_URL is empty. Set DATABASE_URL or POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB (see docker-compose.yml)."
exit 1
fi
echo "Checking migrations for destructive SQL (DROP*/TRUNCATE)..."
node ./scripts/check-prisma-migrations-destructive.cjs
echo "Applying database migrations (prisma migrate deploy)..."
# Do not use `npx prisma`: standalone images omit `node_modules/.bin`, so npx falls back to PATH (`sh: prisma: not found`).
node ./node_modules/prisma/build/index.js migrate deploy
echo "Ensuring admin user (scripts/ensure-admin.ts)..."
node ./node_modules/tsx/dist/cli.mjs ./scripts/ensure-admin.ts
echo "Starting Next.js (HOSTNAME=0.0.0.0 PORT=${PORT:-3310})..."
exec env HOSTNAME=0.0.0.0 PORT="${PORT:-3310}" node server.js