#!/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}🔄 Updating Photo Sharing Platform - Local Development${NC}" echo "====================================================" # 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 # Stop all containers echo -e "${YELLOW}🛑 Stopping all containers...${NC}" docker-compose -f docker-compose.local.yml down # Remove old images to force rebuild echo -e "${YELLOW}🗑️ Removing old images...${NC}" docker-compose -f docker-compose.local.yml rm -f # Pull latest base images echo -e "${YELLOW}📥 Pulling latest base images...${NC}" docker-compose -f docker-compose.local.yml pull # Build frontend production files echo -e "${YELLOW}📦 Building frontend production files...${NC}" cd frontend npm install --legacy-peer-deps npm run build cd .. # Rebuild all images with no cache echo -e "${YELLOW}🔨 Rebuilding Docker images (no cache)...${NC}" docker-compose -f docker-compose.local.yml build --no-cache # Start all 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 # Wait a bit more for frontend to be ready echo -e "${YELLOW}⏳ Waiting for frontend to be ready...${NC}" sleep 5 # Show status echo "" echo -e "${GREEN}✅ Local development environment has been updated!${NC}" echo "" echo -e "${GREEN}🌐 Access Points:${NC}" echo " Frontend (Nginx): http://localhost:3005" echo " Frontend (Dev): http://localhost:3002" echo " Backend API: http://localhost:3001" echo " Mailhog: http://localhost:8025" echo "" echo -e "${GREEN}📝 Container Status:${NC}" docker-compose -f docker-compose.local.yml ps echo "" echo -e "${GREEN}💡 Tips:${NC}" echo " - View logs: docker-compose -f docker-compose.local.yml logs -f" echo " - View specific service logs: docker-compose -f docker-compose.local.yml logs -f [service-name]" echo " - Stop all: ./stop-local.sh" echo "" # Open browser if command -v xdg-open &> /dev/null; then xdg-open http://localhost:3005 elif command -v open &> /dev/null; then open http://localhost:3005 fi echo -e "${GREEN}✨ Update complete! The browser should open automatically.${NC}"