# ============================================================================== # INFRASTRUCTURE (Docker: Postgres, Redis, RabbitMQ) # ============================================================================== .PHONY: infra-up infra-down wait-for-infra wait-for-services db-shell redis-shell db-migrate infra-up: ## [MID] Start Docker Infra (with health checks) @$(ECHO_CMD) "${BLUE}🐳 Starting Infrastructure...${NC}" @docker compose -f $(COMPOSE_FILE) up -d @$(MAKE) -s wait-for-infra infra-down: ## [MID] Stop Docker Infra @$(ECHO_CMD) "${BLUE}🛑 Stopping Infrastructure...${NC}" @docker compose -f $(COMPOSE_FILE) down wait-for-infra: ## [LOW] Wait for infrastructure to be ready @printf "${BLUE}⏳ Waiting for services...${NC}" @until docker compose -f $(COMPOSE_FILE) exec -T postgres pg_isready -U $(DB_USER) > /dev/null 2>&1; do printf "."; sleep 1; done @until docker compose -f $(COMPOSE_FILE) exec -T redis redis-cli ping > /dev/null 2>&1; do printf "."; sleep 1; done @$(ECHO_CMD) " ${GREEN}OK${NC}" wait-for-services: ## [LOW] Wait for all application services @printf "${BLUE}⏳ Waiting for services...${NC}" @for service in backend-api chat-server stream-server web; do \ until docker compose -f $(COMPOSE_PROD) exec -T $$service echo "ready" > /dev/null 2>&1; do \ printf "."; sleep 1; \ done; \ done @$(ECHO_CMD) " ${GREEN}OK${NC}" db-shell: ## [MID] Connect to Postgres shell @docker compose -f $(COMPOSE_FILE) exec postgres psql -U $(DB_USER) -d $(DB_NAME) redis-shell: ## [MID] Connect to Redis shell @docker compose -f $(COMPOSE_FILE) exec redis redis-cli db-migrate: infra-up ## [MID] Run all database migrations @$(ECHO_CMD) "${BLUE}🔄 Running Migrations...${NC}" @$(ECHO_CMD) " -> [Go] Migrating..." @(cd $(ROOT)/$(SERVICE_DIR_backend-api) && go run cmd/migrate_tool/main.go up || $(ECHO_CMD) "${YELLOW}Warning: Go migration failed${NC}") @$(ECHO_CMD) " -> [Chat] Migrating..." @(cd $(ROOT)/$(SERVICE_DIR_chat-server) && sqlx migrate run || $(ECHO_CMD) "${YELLOW}Warning: Chat migration failed${NC}") @$(ECHO_CMD) " -> [Stream] Migrating..." @(cd $(ROOT)/$(SERVICE_DIR_stream-server) && sqlx migrate run || $(ECHO_CMD) "${YELLOW}Warning: Stream migration failed${NC}") @$(ECHO_CMD) "${GREEN}✅ Migrations done.${NC}"