#!/bin/bash # Run local development server set -e echo "🚀 Starting IRT Bank Soal Local Dev Server" echo "==========================================" # Check if Docker is available if ! command -v docker &> /dev/null; then echo "❌ Docker not found. Please install Docker first." exit 1 fi # Check if docker-compose is available if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then echo "❌ Docker Compose not found. Please install Docker Compose first." exit 1 fi # Use docker compose command (Docker Desktop includes it as a plugin) DOCKER_COMPOSE="docker compose" # Start databases echo "📦 Starting PostgreSQL and Redis..." $DOCKER_COMPOSE -f docker-compose.dev.yml up -d postgres redis # Wait for PostgreSQL to be ready echo "⏳ Waiting for PostgreSQL..." for i in {1..60}; do if docker exec yellow-bank-soal-postgres-1 pg_isready -U irt_user -d irt_bank_soal &> /dev/null 2>&1; then echo "✅ PostgreSQL is ready!" break fi if [ $i -eq 60 ]; then echo "❌ PostgreSQL failed to start" docker logs yellow-bank-soal-postgres-1 exit 1 fi sleep 1 done # Check if venv exists, create if not if [ ! -d "venv" ]; then echo "📦 Creating Python virtual environment..." python3 -m venv venv fi # Activate venv and install dependencies echo "📦 Installing dependencies..." source venv/bin/activate pip install -r requirements.txt -q # Run migrations echo "🔄 Running database migrations..." alembic upgrade head # Start the dev server echo "" echo "🎉 Starting FastAPI dev server..." echo " Admin UI: http://localhost:8000/admin" echo " API Docs: http://localhost:8000/docs" echo " Login: admin / admin123" echo "" echo "==========================================" exec uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload