feat: add Docker support with single-port deployment
Add complete Docker configuration for containerized deployment: - Multi-stage Dockerfile using official Bun runtime - docker-compose.yml for single-port stack orchestration - Host-mounted database volume with auto-initialization - Custom database init script using bun:sqlite - Entrypoint script for seamless database setup - Environment configuration template - Comprehensive DOCKER.md documentation Key features: - Single exposed port (3001) serving both API and frontend - Database persists in ./data directory on host - Auto-creates database from template on first startup - Health checks for monitoring - Architecture-agnostic (works on x86 and ARM64) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
62
docker-entrypoint.sh
Normal file
62
docker-entrypoint.sh
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/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 "$@"
|
||||
Reference in New Issue
Block a user