Files
balikci/docker-entrypoint.sh
salvacybersec 7582813f20 mesela yani
2025-11-11 14:05:20 +03:00

57 lines
1.8 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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
# 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
# Start the application
echo "✨ Starting server..."
exec "$@"