#!/bin/bash # Project Setup & Deployment Script # Automates common tasks for Job Info application set -e PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Functions print_header() { echo -e "${BLUE}╔════════════════════════════════════════════════════╗${NC}" echo -e "${BLUE}║${NC} $1" echo -e "${BLUE}╚════════════════════════════════════════════════════╝${NC}" } print_success() { echo -e "${GREEN}✓${NC} $1" } print_error() { echo -e "${RED}✗${NC} $1" } print_warning() { echo -e "${YELLOW}!${NC} $1" } # Main menu main_menu() { print_header "Job Info - Project Setup & Deployment" echo "" echo "Select an option:" echo " 1) Start Local Development (Backend + Frontend)" echo " 2) Start Docker Compose (Containerized)" echo " 3) Build Docker Images" echo " 4) Deploy to Kubernetes" echo " 5) Run Tests" echo " 6) Build Production Bundle" echo " 7) View Documentation" echo " 8) Check System Status" echo " 9) Clean Up (Remove containers/build artifacts)" echo " 0) Exit" echo "" read -p "Enter your choice [0-9]: " choice } # Option 1: Start Local Development start_local_dev() { print_header "Starting Local Development" # Check if Node.js and Bun are installed if ! command -v bun &> /dev/null; then print_error "Bun not found. Install from https://bun.sh" return 1 fi if ! command -v npm &> /dev/null; then print_error "npm not found. Install Node.js" return 1 fi echo "" echo "Starting backend and frontend servers..." echo "Backend will run on http://localhost:3005" echo "Frontend will run on http://localhost:5173" echo "" print_warning "You need TWO terminals for this" echo "" echo "Terminal 1 - Backend:" echo " cd $PROJECT_DIR/Mode3Test" echo " bun run dev" echo "" echo "Terminal 2 - Frontend:" echo " cd $PROJECT_DIR/frontend" echo " npm run dev" echo "" echo "Then open browser to: http://localhost:5173" echo "" read -p "Press Enter to open instructions in your default browser..." } # Option 2: Start Docker Compose start_docker_compose() { print_header "Starting Docker Compose" if ! command -v docker-compose &> /dev/null; then print_error "Docker Compose not found. Install from https://docs.docker.com/" return 1 fi echo "" cd "$PROJECT_DIR" echo "Building containers..." docker-compose build echo "" echo "Starting services..." docker-compose up -d print_success "Services started" echo "" echo "Checking status..." docker-compose ps echo "" print_success "Application ready at http://localhost:5173" echo "" echo "To stop services: docker-compose down" echo "To view logs: docker-compose logs -f" } # Option 3: Build Docker Images build_docker_images() { print_header "Building Docker Images" if ! command -v docker &> /dev/null; then print_error "Docker not found. Install from https://docs.docker.com/" return 1 fi echo "" cd "$PROJECT_DIR" echo "Building backend image..." docker build -f Dockerfile.backend -t job-info-backend:latest . print_success "Backend image built" echo "" echo "Building frontend image..." docker build -f Dockerfile.frontend -t job-info-frontend:latest . print_success "Frontend image built" echo "" echo "Images ready:" docker images | grep job-info } # Option 4: Deploy to Kubernetes deploy_kubernetes() { print_header "Deploy to Kubernetes" if ! command -v kubectl &> /dev/null; then print_error "kubectl not found. Install from https://kubernetes.io/docs/" return 1 fi echo "" read -p "Is your Kubernetes cluster configured? (y/n) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then print_warning "Configure kubectl first" return 1 fi echo "" cd "$PROJECT_DIR" echo "Creating namespace and configs..." kubectl apply -f k8s-config.yaml print_success "Namespace and configs created" echo "" echo "Deploying backend..." kubectl apply -f k8s-backend-deployment.yaml print_success "Backend deployed" echo "" echo "Deploying frontend..." kubectl apply -f k8s-frontend-deployment.yaml print_success "Frontend deployed" echo "" echo "Checking deployment status..." kubectl rollout status deployment/job-info-backend -n job-info kubectl rollout status deployment/job-info-frontend -n job-info echo "" print_success "Deployment complete" echo "" echo "Get service IP:" echo " kubectl get svc job-info-frontend -n job-info" } # Option 5: Run Tests run_tests() { print_header "Running Tests" echo "" echo "See PHASE_8_QUICK_START.md for detailed testing procedures" echo "" echo "23 Test scenarios covering:" echo " 1. OAuth2 Flow (6 tests)" echo " 2. Token Management (4 tests)" echo " 3. API Error Handling (3 tests)" echo " 4. Data Storage (2 tests)" echo " 5. UI Components (2 tests)" echo " 6. Performance (2 tests)" echo " 7. Security (2 tests)" echo " 8. Accessibility (2 tests)" echo "" echo "Estimated time: 2 hours 45 minutes" } # Option 6: Build Production Bundle build_production() { print_header "Building Production Bundle" echo "" cd "$PROJECT_DIR/frontend" echo "Installing dependencies..." npm ci echo "" echo "Building frontend..." npm run build print_success "Production build complete" echo "" echo "Output directory: frontend/dist/" du -sh dist/ } # Option 7: View Documentation view_documentation() { print_header "Documentation Available" echo "" echo "Quick References:" echo " • QUICK_START.md - Get running in 2 minutes" echo " • DELIVERABLES.md - Complete deliverables checklist" echo "" echo "Detailed Guides:" echo " • PROJECT_COMPLETION_FINAL.md - Full project overview" echo " • PHASE_8_QUICK_START.md - Testing procedures" echo " • DEPLOYMENT_GUIDE.md - Deployment instructions" echo "" echo "Reference:" echo " • TESTING_GUIDE.md - Complete test guide" echo " • SVELTE_DEVELOPMENT_SYSTEM.md - Development standards" echo "" read -p "Open documentation? (y/n) " -n 1 -r echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then if command -v xdg-open &> /dev/null; then xdg-open PROJECT_COMPLETION_FINAL.md elif command -v open &> /dev/null; then open PROJECT_COMPLETION_FINAL.md else echo "Open manually: less PROJECT_COMPLETION_FINAL.md" fi fi } # Option 8: Check System Status check_status() { print_header "System Status" echo "" echo "Checking requirements:" if command -v node &> /dev/null; then print_success "Node.js: $(node --version)" else print_error "Node.js not found" fi if command -v bun &> /dev/null; then print_success "Bun: $(bun --version)" else print_error "Bun not found" fi if command -v docker &> /dev/null; then print_success "Docker: $(docker --version)" else print_warning "Docker not found (optional)" fi if command -v kubectl &> /dev/null; then print_success "kubectl: $(kubectl version --client --short 2>/dev/null || echo 'installed')" else print_warning "kubectl not found (optional)" fi echo "" echo "Checking project structure:" [ -d "frontend" ] && print_success "frontend/" || print_error "frontend/ not found" [ -d "Mode3Test" ] && print_success "Mode3Test/" || print_error "Mode3Test/ not found" [ -f "docker-compose.yml" ] && print_success "docker-compose.yml" || print_error "docker-compose.yml not found" [ -f "k8s-config.yaml" ] && print_success "k8s-config.yaml" || print_error "k8s-config.yaml not found" } # Option 9: Clean Up cleanup() { print_header "Clean Up" echo "" read -p "Remove Docker containers and volumes? (y/n) " -n 1 -r echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then docker-compose down -v print_success "Docker containers and volumes removed" fi echo "" read -p "Remove build artifacts? (y/n) " -n 1 -r echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then rm -rf frontend/dist/ rm -rf frontend/node_modules/ rm -rf Mode3Test/node_modules/ print_success "Build artifacts removed" fi } # Main loop while true; do main_menu case $choice in 1) start_local_dev ;; 2) start_docker_compose ;; 3) build_docker_images ;; 4) deploy_kubernetes ;; 5) run_tests ;; 6) build_production ;; 7) view_documentation ;; 8) check_status ;; 9) cleanup ;; 0) print_success "Goodbye!"; exit 0 ;; *) print_error "Invalid option" ;; esac echo "" read -p "Press Enter to continue..." echo "" done