Added entrypoint script to handle database permissions on fresh deployments. The issue occurred because Docker creates the ./data directory with root permissions when it doesn't exist, preventing the nextjs user (uid 1001) from writing to it. Changes: - Add entrypoint.sh that runs as root, fixes permissions, then switches to nextjs user - Install gosu for safe privilege dropping - Initialize database on first run with proper permissions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
29 lines
835 B
Bash
Executable File
29 lines
835 B
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
# This script runs as root first to fix permissions, then switches to nextjs user
|
|
|
|
DB_PATH="${DATABASE_PATH:-/app/data/caddy-proxy-manager.db}"
|
|
DB_DIR=$(dirname "$DB_PATH")
|
|
|
|
echo "Setting up database directory permissions..."
|
|
|
|
# Ensure the data directory is owned by nextjs user
|
|
chown -R nextjs:nodejs "$DB_DIR"
|
|
|
|
# Switch to nextjs user and initialize database if needed
|
|
gosu nextjs sh -c '
|
|
DB_PATH="'"$DB_PATH"'"
|
|
|
|
if [ ! -f "$DB_PATH" ]; then
|
|
echo "Database not found, initializing..."
|
|
npx prisma db push --skip-generate
|
|
echo "Database initialized successfully"
|
|
else
|
|
echo "Database exists, applying any schema changes..."
|
|
npx prisma db push --skip-generate --accept-data-loss 2>/dev/null || true
|
|
fi
|
|
|
|
echo "Starting application..."
|
|
exec node server.js
|
|
' |