Files
balikci/docker-entrypoint.sh

57 lines
1.8 KiB
Bash
Raw Normal View History

2025-11-11 07:31:43 +03:00
#!/bin/sh
set -e
echo "🚀 Starting Oltalama application..."
# Ensure database directory exists
mkdir -p database
# Run database migrations
echo "📊 Running database migrations..."
if node migrations/run-migrations.js; then
echo "✅ Migrations completed successfully"
else
echo "⚠️ Migration failed, but continuing..."
fi
# Check if we should seed the database
# Only seed if database is empty (no admin users)
if [ ! -f "database/oltalama.db" ] || [ ! -s "database/oltalama.db" ]; then
echo "🌱 Database is empty, seeding initial data..."
if node seeders/run-seeders.js; then
echo "✅ Seeding completed successfully"
else
echo "⚠️ Seeding failed, but continuing..."
fi
else
# Check if admin user exists
if command -v sqlite3 >/dev/null 2>&1; then
ADMIN_COUNT=$(sqlite3 database/oltalama.db "SELECT COUNT(*) FROM admin_user;" 2>/dev/null || echo "0")
if [ "$ADMIN_COUNT" = "0" ]; then
echo "🌱 Database exists but no admin user found. Running seeders..."
if node seeders/run-seeders.js; then
echo "✅ Seeding completed successfully"
else
echo "⚠️ Seeding failed, but continuing..."
fi
else
echo "✅ Database already initialized with admin user(s), skipping seeders."
fi
else
echo "⚠️ sqlite3 command not found, skipping admin user check."
fi
fi
2025-11-11 14:05:20 +03:00
# Ensure frontend build exists before starting server
FRONTEND_INDEX="src/public/dist/index.html"
if [ ! -f "$FRONTEND_INDEX" ]; then
echo "❌ Frontend build not found at $FRONTEND_INDEX"
echo " Please run 'npm run build' in the frontend (or rebuild the Docker image) so the dist assets are available."
exit 1
fi
2025-11-11 07:31:43 +03:00
# Start the application
echo "✨ Starting server..."
exec "$@"