#!/bin/bash # 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 Automated Development Pipeline - Phase 1${NC}" echo "==================================================" # Check if we're in the right directory if [ ! -f "docker-compose.yml" ]; then echo -e "${RED}โŒ Error: docker-compose.yml not found. Please run from project root directory.${NC}" exit 1 fi # Check if Docker is running if ! docker info > /dev/null 2>&1; then echo -e "${RED}โŒ Docker is not running. Please start Docker Desktop first.${NC}" exit 1 fi # Check if docker compose is available (try both modern and legacy) if command -v "docker" &> /dev/null && docker compose version &> /dev/null; then DOCKER_COMPOSE="docker compose" echo -e "${GREEN}โœ… Using modern Docker Compose${NC}" elif command -v docker-compose &> /dev/null; then DOCKER_COMPOSE="docker-compose" echo -e "${YELLOW}โš ๏ธ Using legacy docker-compose${NC}" else echo -e "${RED}โŒ Docker Compose is not available. Please install Docker Compose.${NC}" exit 1 fi # Create necessary directories echo -e "${BLUE}๐Ÿ“ Creating necessary directories...${NC}" mkdir -p logs generated_projects mkdir -p services/{requirement-processor,tech-stack-selector,architecture-designer,code-generator,test-generator,deployment-manager}/logs touch generated_projects/.gitkeep # Load environment variables if [ -f .env ]; then echo -e "${BLUE}๐Ÿ“‹ Loading environment variables...${NC}" export $(cat .env | grep -v '^#' | grep -v '^$' | xargs) else echo -e "${YELLOW}โš ๏ธ .env file not found. Using default values.${NC}" fi # Clean up any existing containers echo -e "${BLUE}๐Ÿงน Cleaning up existing containers...${NC}" $DOCKER_COMPOSE down > /dev/null 2>&1 # Remove orphaned containers $DOCKER_COMPOSE down --remove-orphans > /dev/null 2>&1 # Pull/build required images echo -e "${BLUE}๐Ÿ“ฅ Building and pulling Docker images...${NC}" $DOCKER_COMPOSE build --no-cache rabbitmq $DOCKER_COMPOSE pull postgres redis mongodb echo -e "${BLUE}๐Ÿ”„ Starting core infrastructure services...${NC}" $DOCKER_COMPOSE up -d postgres redis mongodb rabbitmq # Function to check service health check_service_health() { local service_name=$1 local check_command=$2 local max_attempts=30 local attempt=1 echo -n -e "${BLUE}โณ Waiting for $service_name to be ready${NC}" while [ $attempt -le $max_attempts ]; do if eval "$check_command" > /dev/null 2>&1; then echo -e " ${GREEN}โœ…${NC}" return 0 fi echo -n "." sleep 2 ((attempt++)) done echo -e " ${RED}โŒ Failed after $max_attempts attempts${NC}" return 1 } # Wait for services to be ready with individual health checks echo -e "${BLUE}โณ Waiting for infrastructure services to be ready...${NC}" # PostgreSQL health check check_service_health "PostgreSQL" "$DOCKER_COMPOSE exec -T postgres pg_isready -U pipeline_admin -d dev_pipeline" # Redis health check check_service_health "Redis" "$DOCKER_COMPOSE exec -T redis redis-cli -a redis_secure_2024 ping | grep -q PONG" # MongoDB health check check_service_health "MongoDB" "$DOCKER_COMPOSE exec -T mongodb mongosh --eval 'db.runCommand(\"ping\")' --quiet" # RabbitMQ health check (needs more time) check_service_health "RabbitMQ" "$DOCKER_COMPOSE exec -T rabbitmq rabbitmq-diagnostics ping" echo "" echo -e "${BLUE}๐Ÿ” Running comprehensive service health checks...${NC}" # Detailed health check function detailed_health_check() { local service=$1 local check_cmd=$2 local port=$3 echo -n -e "${BLUE}๐Ÿ” $service:${NC} " # Check if container is running if ! $DOCKER_COMPOSE ps $service | grep -q "Up"; then echo -e "${RED}โŒ Container not running${NC}" return 1 fi # Check if port is accessible if [ ! -z "$port" ]; then if ! nc -z localhost $port 2>/dev/null; then echo -e "${YELLOW}โš ๏ธ Port $port not accessible${NC}" return 1 fi fi # Run health check command if eval "$check_cmd" > /dev/null 2>&1; then echo -e "${GREEN}โœ… Healthy${NC}" return 0 else echo -e "${RED}โŒ Health check failed${NC}" echo -e " ${YELLOW}Checking logs:${NC}" $DOCKER_COMPOSE logs --tail=5 $service | sed 's/^/ /' return 1 fi } # Run detailed health checks detailed_health_check "postgres" "$DOCKER_COMPOSE exec -T postgres pg_isready -U pipeline_admin -d dev_pipeline" "5432" detailed_health_check "redis" "$DOCKER_COMPOSE exec -T redis redis-cli -a redis_secure_2024 ping | grep -q PONG" "6379" detailed_health_check "mongodb" "$DOCKER_COMPOSE exec -T mongodb mongosh --eval 'db.runCommand(\"ping\").ok' --quiet" "27017" detailed_health_check "rabbitmq" "$DOCKER_COMPOSE exec -T rabbitmq rabbitmq-diagnostics ping" "15672" echo "" echo -e "${BLUE}๐Ÿงช Running database initialization tests...${NC}" # Test database connections echo -n -e "${BLUE}๐Ÿ“Š Testing PostgreSQL connection:${NC} " if $DOCKER_COMPOSE exec -T postgres psql -U pipeline_admin -d dev_pipeline -c "SELECT version();" > /dev/null 2>&1; then echo -e "${GREEN}โœ… Connected${NC}" else echo -e "${RED}โŒ Connection failed${NC}" fi echo -n -e "${BLUE}๐Ÿ“Š Testing Redis connection:${NC} " if $DOCKER_COMPOSE exec -T redis redis-cli -a redis_secure_2024 ping 2>/dev/null | grep -q PONG; then echo -e "${GREEN}โœ… Connected${NC}" else echo -e "${RED}โŒ Connection failed${NC}" fi echo -n -e "${BLUE}๐Ÿ“Š Testing MongoDB connection:${NC} " if $DOCKER_COMPOSE exec -T mongodb mongosh --eval "db.runCommand('ping')" --quiet > /dev/null 2>&1; then echo -e "${GREEN}โœ… Connected${NC}" else echo -e "${RED}โŒ Connection failed${NC}" fi # Test RabbitMQ management interface echo -n -e "${BLUE}๐Ÿ“Š Testing RabbitMQ management:${NC} " if curl -s -u pipeline_admin:rabbit_secure_2024 http://localhost:15672/api/overview > /dev/null 2>&1; then echo -e "${GREEN}โœ… Management UI accessible${NC}" else echo -e "${YELLOW}โš ๏ธ Management UI not ready yet${NC}" fi echo "" echo -e "${BLUE}๐Ÿ“Š Infrastructure Status Summary:${NC}" echo "============================================" # Show container status echo -e "${BLUE}๐Ÿณ Container Status:${NC}" $DOCKER_COMPOSE ps --format "table {{.Service}}\t{{.State}}\t{{.Status}}" echo "" echo -e "${BLUE}๐Ÿ’พ Volume Usage:${NC}" docker system df --format "table {{.Type}}\t{{.TotalCount}}\t{{.Size}}\t{{.Reclaimable}}" echo "" echo -e "${BLUE}๐ŸŒ Service URLs:${NC}" echo " ๐Ÿ“Š RabbitMQ Management: http://localhost:15672" echo " Username: pipeline_admin" echo " Password: rabbit_secure_2024" echo " ๐Ÿ˜ PostgreSQL: localhost:5432" echo " ๐Ÿ”ด Redis: localhost:6379" echo " ๐Ÿƒ MongoDB: localhost:27017" echo "" echo -e "${BLUE}๏ฟฝ๏ฟฝ Quick Connection Tests:${NC}" echo " PostgreSQL: $DOCKER_COMPOSE exec postgres psql -U pipeline_admin -d dev_pipeline -c 'SELECT version();'" echo " Redis: $DOCKER_COMPOSE exec redis redis-cli -a redis_secure_2024 ping" echo " MongoDB: $DOCKER_COMPOSE exec mongodb mongosh --eval 'db.runCommand(\"ping\")'" echo " RabbitMQ Queues: python3 scripts/rabbitmq/test-queues.py" echo "" echo -e "${GREEN}โœ… Phase 1 Foundation Infrastructure is running!${NC}" echo "" echo -e "${BLUE}๐Ÿ“ Next Steps:${NC}" echo " 1. Test database connections using the commands above" echo " 2. Check RabbitMQ management UI at http://localhost:15672" echo " 3. Review logs with: $DOCKER_COMPOSE logs [service-name]" echo " 4. Stop services with: ./scripts/setup/stop.sh" echo " 5. Check status with: ./scripts/setup/status.sh" echo "" echo -e "${YELLOW}๐ŸŽฏ Ready to proceed to Phase 2: AI Services Integration!${NC}"