-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
76 lines (63 loc) · 2.22 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
76 lines (63 loc) · 2.22 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
#!/bin/sh
set -e
SECRETS_FILE="/app/data/.secrets"
DB_FILE="/app/data/paste.db"
chown -R nextjs:nodejs /app/data 2>/dev/null || true
# ============================================
# 1. Generate or load secrets
# ============================================
if [ -f "$SECRETS_FILE" ]; then
echo "[entrypoint] Loading existing secrets from $SECRETS_FILE"
. "$SECRETS_FILE"
else
echo "[entrypoint] First run - generating secrets..."
# Generate ENCRYPTION_KEY (64 hex chars = 32 bytes)
ENCRYPTION_KEY=$(openssl rand -hex 32)
# Generate SESSION_SECRET (32 bytes base64)
SESSION_SECRET=$(openssl rand -base64 32)
# Save to secrets file
cat > "$SECRETS_FILE" << EOF
ENCRYPTION_KEY=$ENCRYPTION_KEY
SESSION_SECRET=$SESSION_SECRET
EOF
chmod 600 "$SECRETS_FILE"
echo "[entrypoint] Secrets saved to $SECRETS_FILE"
fi
export ENCRYPTION_KEY
export SESSION_SECRET
# ============================================
# 2. Handle admin password
# ============================================
if [ -z "$ADMIN_PASSWORD_HASH" ]; then
if [ -z "$ADMIN_PASSWORD" ]; then
echo "[entrypoint] ERROR: ADMIN_PASSWORD is required"
echo "[entrypoint] Set ADMIN_PASSWORD environment variable in docker-compose.yaml"
exit 1
fi
echo "[entrypoint] Generating bcrypt hash from ADMIN_PASSWORD..."
ADMIN_PASSWORD_HASH=$(node -e "
const bcrypt = require('bcryptjs');
console.log(bcrypt.hashSync(process.env.ADMIN_PASSWORD, 10));
")
if [ -z "$ADMIN_PASSWORD_HASH" ]; then
echo "[entrypoint] ERROR: Failed to generate password hash"
exit 1
fi
fi
export ADMIN_PASSWORD_HASH
# ============================================
# 3. Initialize database if needed
# ============================================
if [ ! -f "$DB_FILE" ]; then
echo "[entrypoint] Initializing database..."
node /app/scripts/migrate.js
echo "[entrypoint] Database initialized"
else
echo "[entrypoint] Database exists, checking migrations..."
node /app/scripts/migrate.js
fi
# ============================================
# 4. Start the application
# ============================================
echo "[entrypoint] Starting application..."
exec su-exec nextjs "$@"