-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
95 lines (81 loc) · 2.47 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
95 lines (81 loc) · 2.47 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/sh
set -e
cd /app
export HOST=0.0.0.0
export HOSTNAME=0.0.0.0
mkdir -p /app/data
# Persist JWT when unset: stable across restarts with the same named volume.
if [ -z "${JWT_SECRET:-}" ]; then
if [ -f /app/data/.jwt_secret ]; then
JWT_SECRET=$(tr -d '\n\r' < /app/data/.jwt_secret)
else
node -e "require('fs').writeFileSync('/app/data/.jwt_secret', require('crypto').randomBytes(32).toString('hex'))"
chmod 600 /app/data/.jwt_secret
JWT_SECRET=$(tr -d '\n\r' < /app/data/.jwt_secret)
fi
export JWT_SECRET
fi
if [ "$(id -u)" = 0 ]; then
chown -R nextjs:nodejs /app/data
fi
export DATABASE_URL="${DATABASE_URL:-file:/app/data/dev.db}"
export REDIS_INTERNAL_ENABLED="${REDIS_INTERNAL_ENABLED:-1}"
export REDIS_PORT="${REDIS_PORT:-6379}"
export REDIS_URL="${REDIS_URL:-redis://127.0.0.1:${REDIS_PORT}}"
export REDIS_CACHE_TTL_SECONDS="${REDIS_CACHE_TTL_SECONDS:-3600}"
# Config lives under /app but CLI deps are in /app/tools; TS config imports `drizzle-kit`.
export NODE_PATH=/app/tools/node_modules
export DRIZZLE_KIT_CLI=/app/tools/node_modules/drizzle-kit/bin.cjs
case "$DATABASE_URL" in
postgres:*|postgresql:*)
export DRIZZLE_CONFIG=drizzle.config.pg.ts
;;
*)
export DRIZZLE_CONFIG=drizzle.config.sqlite.ts
;;
esac
start_internal_redis() {
[ "${REDIS_INTERNAL_ENABLED}" = "1" ] || return 0
mkdir -p /app/data/redis
if [ "$(id -u)" = 0 ]; then
chown -R nextjs:nodejs /app/data/redis
gosu nextjs redis-server \
--bind 127.0.0.1 \
--port "${REDIS_PORT}" \
--save 60 1 \
--appendonly yes \
--loglevel warning \
--dir /app/data/redis \
--dbfilename dump.rdb \
--daemonize yes
else
redis-server \
--bind 127.0.0.1 \
--port "${REDIS_PORT}" \
--save 60 1 \
--appendonly yes \
--loglevel warning \
--dir /app/data/redis \
--dbfilename dump.rdb \
--daemonize yes
fi
}
start_app() {
node /app/scripts/startup-banner.mjs start
node "$DRIZZLE_KIT_CLI" push --config "$DRIZZLE_CONFIG"
exec node server.js
}
start_internal_redis
if [ "$(id -u)" = 0 ]; then
export PORT="${PORT:-3000}"
export NODE_ENV="${NODE_ENV:-production}"
export HOST=0.0.0.0
export HOSTNAME=0.0.0.0
export HOME=/tmp
export USER=nextjs
export LOGNAME=nextjs
export SHELL=/bin/sh
exec gosu nextjs sh -ec 'cd /app && node /app/scripts/startup-banner.mjs start && node "$DRIZZLE_KIT_CLI" push --config "$DRIZZLE_CONFIG" && exec node server.js'
else
start_app
fi