-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·33 lines (30 loc) · 1.05 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
executable file
·33 lines (30 loc) · 1.05 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
#!/bin/sh
set -e
# Fix permissions if we're running as root (volume mounts often leave root-owned trees).
if [ "$(id -u)" = "0" ]; then
chown -R nextjs:nodejs /app/data 2>/dev/null || true
chmod 755 /app/data 2>/dev/null || true
mkdir -p /app/.next/cache 2>/dev/null || true
chown -R nextjs:nodejs /app/.next /app/public 2>/dev/null || true
fi
# If database doesn't exist in mounted volume, copy from image default
# Note: .default-stories.db must be outside /app/data to survive volume mount
if [ ! -f /app/data/stories.db ]; then
if [ -f /app/.default-stories.db ]; then
cp /app/.default-stories.db /app/data/stories.db
# Fix ownership if running as root
if [ "$(id -u)" = "0" ]; then
chown nextjs:nodejs /app/data/stories.db
chmod 644 /app/data/stories.db
fi
else
echo "ERROR: Pre-populated database not found at /app/.default-stories.db" >&2
exit 1
fi
fi
# Switch to nextjs user before starting server (if we're root)
if [ "$(id -u)" = "0" ]; then
exec su-exec nextjs node server.js
else
exec node server.js
fi