#!/bin/bash # Colors for output GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color echo -e "${GREEN}🚀 Photo Sharing Platform - Local Development Setup${NC}" echo "==================================================" # Check if Docker is installed if ! command -v docker &> /dev/null; then echo -e "${RED}❌ Docker is not installed. Please install Docker Desktop first.${NC}" echo " Visit: https://www.docker.com/products/docker-desktop" exit 1 fi # Check if Docker is running if ! docker info &> /dev/null; then echo -e "${RED}❌ Docker is not running. Please start Docker Desktop.${NC}" exit 1 fi # Create necessary directories echo -e "${YELLOW}📁 Creating directories...${NC}" mkdir -p storage/events/{active,archived} mkdir -p storage/thumbnails mkdir -p data mkdir -p logs mkdir -p backend/node_modules mkdir -p frontend/node_modules # Copy local environment file if it doesn't exist if [ ! -f .env ]; then echo -e "${YELLOW}📋 Setting up environment...${NC}" cp .env.local .env fi # Stop any existing containers echo -e "${YELLOW}🛑 Stopping existing containers...${NC}" docker-compose -f docker-compose.local.yml down 2>/dev/null || true # Build images echo -e "${YELLOW}🔨 Building Docker images...${NC}" docker-compose -f docker-compose.local.yml build # Start services echo -e "${YELLOW}🚀 Starting services...${NC}" docker-compose -f docker-compose.local.yml up -d # Wait for backend to be ready echo -e "${YELLOW}⏳ Waiting for backend to start...${NC}" max_attempts=30 attempt=1 while [ $attempt -le $max_attempts ]; do if curl -s http://localhost:3001/api/health > /dev/null 2>&1; then echo -e "${GREEN}✅ Backend is ready!${NC}" break fi echo -n "." sleep 2 attempt=$((attempt + 1)) done if [ $attempt -gt $max_attempts ]; then echo -e "${RED}❌ Backend failed to start. Check logs with: docker-compose -f docker-compose.local.yml logs backend${NC}" exit 1 fi # Build frontend for production-like testing echo -e "${YELLOW}📦 Building frontend...${NC}" docker-compose -f docker-compose.local.yml exec frontend-dev npm run build # Show status echo "" echo -e "${GREEN}✅ Local development environment is ready!${NC}" echo "" echo -e "${GREEN}🌐 Access Points:${NC}" echo " Frontend (Production Build): http://localhost:3000" echo " Frontend (Dev with Hot Reload): http://localhost:3002" echo " Backend API: http://localhost:3001/api" echo " Mailhog (Email Testing): http://localhost:8025" echo "" echo -e "${GREEN}🔑 Default Admin Credentials:${NC}" echo " Username: admin" echo " Password: admin123" echo "" echo -e "${GREEN}📝 Useful Commands:${NC}" echo " View logs: docker-compose -f docker-compose.local.yml logs -f" echo " Stop all: ./stop-local.sh" echo " Backend shell: docker-compose -f docker-compose.local.yml exec backend sh" echo " Reset database: docker-compose -f docker-compose.local.yml exec backend npm run migrate" echo "" echo -e "${GREEN}💡 Tips:${NC}" echo " - Frontend dev server (port 3002) has hot reload enabled" echo " - All emails are caught by Mailhog - check http://localhost:8025" echo " - SQLite database is stored in ./data/photo_sharing.db" echo " - Upload photos to ./storage/events/active/{event-name}/" echo "" # Open browser if command -v xdg-open &> /dev/null; then xdg-open http://localhost:3002 elif command -v open &> /dev/null; then open http://localhost:3002 fi # Show logs echo -e "${YELLOW}📋 Showing logs (Ctrl+C to exit)...${NC}" docker-compose -f docker-compose.local.yml logs -f