#!/bin/sh set -e # Docker container entrypoint script # Handles database initialization on first startup echo "==========================================" echo "Quickawards - Docker Entrypoint" echo "==========================================" # Database location in volume mount DB_PATH="/data/award.db" TEMPLATE_DB="/app/award.db.template" APP_DB_PATH="/app/src/backend/award.db" # Check if database exists in the volume if [ ! -f "$DB_PATH" ]; then echo "" echo "📦 Database not found in volume mount." echo " Initializing from template database..." echo "" # Copy the template database (created during build with drizzle-kit push) cp "$TEMPLATE_DB" "$DB_PATH" # Ensure proper permissions chmod 644 "$DB_PATH" echo "✅ Database initialized at: $DB_PATH" echo " This database will persist in the Docker volume." else echo "" echo "✅ Existing database found at: $DB_PATH" echo " Using existing database from volume mount." fi # Create symlink from app's expected db location to volume mount # The app expects the database at src/backend/award.db # We create a symlink so it points to the volume-mounted database if [ -L "$APP_DB_PATH" ]; then # Symlink already exists, remove it to refresh rm "$APP_DB_PATH" elif [ -e "$APP_DB_PATH" ]; then # File or directory exists (shouldn't happen in production, but handle it) echo "⚠ Warning: Found existing database at $APP_DB_PATH, removing..." rm -f "$APP_DB_PATH" fi # Create symlink to the volume-mounted database ln -s "$DB_PATH" "$APP_DB_PATH" echo "✅ Created symlink: $APP_DB_PATH -> $DB_PATH" echo "" echo "==========================================" echo "Starting Quickawards application..." echo "Port: ${PORT:-3001}" echo "Environment: ${NODE_ENV:-production}" echo "==========================================" echo "" # Execute the main command (passed as CMD in Dockerfile) exec "$@"