#!/bin/bash # CMC Sales Development Environment Setup Script set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}🚀 Starting CMC Sales Development Environment${NC}" echo "" # Function to check if command exists command_exists() { command -v "$1" >/dev/null 2>&1 } # Check prerequisites echo -e "${YELLOW}📋 Checking prerequisites...${NC}" if ! command_exists docker; then echo -e "${RED}❌ Docker is not installed${NC}" exit 1 fi if ! command_exists docker-compose; then echo -e "${RED}❌ Docker Compose is not installed${NC}" exit 1 fi echo -e "${GREEN}✅ Prerequisites satisfied${NC}" echo "" # Check Docker Compose version for watch support DOCKER_COMPOSE_VERSION=$(docker compose version --short 2>/dev/null || echo "unknown") SUPPORTS_WATCH=false if [[ "$DOCKER_COMPOSE_VERSION" != "unknown" ]]; then # Check if version is 2.22.0 or higher (when watch was introduced) if docker compose version 2>/dev/null | grep -q "Docker Compose version v2\.\([2-9][2-9]\|[3-9][0-9]\)"; then SUPPORTS_WATCH=true fi fi echo "" echo -e "${YELLOW}đŸ—ī¸ Building and starting services...${NC}" # Ask user about watch mode if [[ "$SUPPORTS_WATCH" == "true" ]]; then echo -e "${BLUE}💡 Docker Compose watch mode is available for automatic rebuilds on file changes.${NC}" read -p "Would you like to enable watch mode? (Y/n): " enable_watch if [[ ! $enable_watch =~ ^[Nn]$ ]]; then USE_WATCH=true else USE_WATCH=false fi else echo -e "${YELLOW}âš ī¸ Docker Compose watch mode not available (requires v2.22.0+)${NC}" USE_WATCH=false fi if [[ "$USE_WATCH" == "true" ]]; then echo -e "${GREEN}🔄 Starting services with watch mode enabled...${NC}" echo -e "${BLUE} 📁 Watching for changes in: go/, php/app/webroot/css/, php/app/webroot/js/${NC}" echo -e "${BLUE} 🔄 Services will automatically rebuild on file changes${NC}" echo -e "${BLUE} âšī¸ Press Ctrl+C to stop all services${NC}" echo "" # Start with watch mode (this will run in foreground) docker compose up --build --watch else # Traditional mode docker compose up --build -d echo "" echo -e "${YELLOW}âŗ Waiting for services to be ready...${NC}" sleep 10 # Check service health echo -e "${YELLOW}đŸĨ Checking service health...${NC}" # Check database if docker compose exec -T db mariadb-admin ping -h localhost -u cmc -p'xVRQI&cA?7AU=hqJ!%au' --silent; then echo -e "${GREEN}✅ Database is ready${NC}" else echo -e "${RED}❌ Database is not ready${NC}" fi # Check Go app if curl -s http://localhost:8080/api/v1/health > /dev/null; then echo -e "${GREEN}✅ Go application is ready${NC}" else echo -e "${YELLOW}âš ī¸ Go application might still be starting...${NC}" fi echo "" echo -e "${GREEN}🎉 Development environment is running!${NC}" echo "" echo -e "${BLUE}📱 Access your applications:${NC}" echo -e " đŸ›ī¸ CakePHP (Legacy): ${GREEN}http://cmclocal${NC} (add to /etc/hosts: 127.0.0.1 cmclocal)" echo -e " 🚀 Go (Modern): ${GREEN}http://localhost:8080${NC}" echo -e " đŸ—„ī¸ Database: ${GREEN}localhost:3306${NC} (user: cmc, pass: xVRQI&cA?7AU=hqJ!%au)" echo "" echo -e "${BLUE}🔧 Useful commands:${NC}" echo -e " View logs: ${YELLOW}docker compose logs -f${NC}" echo -e " Stop services: ${YELLOW}docker compose down${NC}" echo -e " Restart Go app: ${YELLOW}docker compose restart cmc-go${NC}" echo -e " Restart PHP app: ${YELLOW}docker compose restart cmc-php${NC}" echo -e " Enable watch mode: ${YELLOW}docker compose up --watch${NC}" echo "" echo -e "${BLUE}📚 Documentation:${NC}" echo -e " Go app README: ${YELLOW}go/README.md${NC}" echo -e " Project guide: ${YELLOW}CLAUDE.md${NC}" echo "" # Optional: Follow logs read -p "Would you like to follow the logs? (y/N): " follow_logs if [[ $follow_logs =~ ^[Yy]$ ]]; then echo -e "${YELLOW}📝 Following logs (Ctrl+C to exit)...${NC}" docker compose logs -f fi fi