# MCP ComfyUI Flux - Makefile for Optimized Production Setup
# Usage: make [target]
# Default: make help
# Configuration
PROJECT_NAME ?= mcp-comfyui-flux
COMPOSE := docker compose -p $(PROJECT_NAME)
DOCKER_BUILDKIT := 1
SHELL := /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
# Default target
.DEFAULT_GOAL := help
# Help target - must be first
.PHONY: help
help: ## Show this help message
@echo -e "$(BLUE)╔══════════════════════════════════════════════════════════╗$(NC)"
@echo -e "$(BLUE)║ MCP ComfyUI Flux - Makefile Commands ║$(NC)"
@echo -e "$(BLUE)╚══════════════════════════════════════════════════════════╝$(NC)"
@echo ""
@echo -e "$(GREEN)Available commands:$(NC)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " $(YELLOW)%-15s$(NC) %s\n", $$1, $$2}'
@echo ""
@echo -e "$(GREEN)Quick start:$(NC)"
@echo " make install # First time setup"
@echo " make start # Start services"
@echo " make logs # View logs"
@echo ""
@echo -e "$(GREEN)Variables:$(NC)"
@echo " PROJECT_NAME=$(PROJECT_NAME)"
@echo " COMPOSE='$(COMPOSE)'"
# ============================================================================
# Installation & Setup
# ============================================================================
.PHONY: install
install: ## Run full installation with models
@echo -e "$(GREEN)[Installing]$(NC) Running installation script..."
@./install.sh
.PHONY: install-minimal
install-minimal: ## Install with minimal models only
@echo -e "$(GREEN)[Installing]$(NC) Running minimal installation..."
@./install.sh --models=minimal
.PHONY: install-cpu
install-cpu: ## Install for CPU-only mode
@echo -e "$(GREEN)[Installing]$(NC) Running CPU-only installation..."
@./install.sh --cpu-only
# ============================================================================
# Docker Operations
# ============================================================================
.PHONY: build
build: ## Build Docker images with BuildKit optimizations
@echo -e "$(GREEN)[Building]$(NC) Building optimized containers..."
@export DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) && ./build.sh
.PHONY: build-nocache
build-nocache: ## Build Docker images without cache
@echo -e "$(YELLOW)[Building]$(NC) Building without cache..."
@export DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) && ./build.sh --no-cache
.PHONY: start
start: ## Start all containers
@echo -e "$(GREEN)[Starting]$(NC) Starting containers..."
@$(COMPOSE) up -d
@echo -e "$(GREEN)✓$(NC) Services started"
@echo " ComfyUI: http://localhost:8188"
@$(MAKE) -s status
.PHONY: stop
stop: ## Stop all containers
@echo -e "$(YELLOW)[Stopping]$(NC) Stopping containers..."
@$(COMPOSE) down
@echo -e "$(GREEN)✓$(NC) Services stopped"
.PHONY: restart
restart: ## Restart all containers
@echo -e "$(YELLOW)[Restarting]$(NC) Restarting containers..."
@$(COMPOSE) restart
@echo -e "$(GREEN)✓$(NC) Services restarted"
.PHONY: down
down: ## Stop and remove containers, networks
@echo -e "$(YELLOW)[Down]$(NC) Removing containers and networks..."
@$(COMPOSE) down --remove-orphans
@echo -e "$(GREEN)✓$(NC) Cleaned up"
# ============================================================================
# Monitoring & Logs
# ============================================================================
.PHONY: status
status: ## Show container status
@echo -e "$(BLUE)[Status]$(NC) Container status:"
@$(COMPOSE) ps
.PHONY: logs
logs: ## Follow container logs (all services)
@echo -e "$(BLUE)[Logs]$(NC) Following all logs (Ctrl+C to exit)..."
@$(COMPOSE) logs -f
.PHONY: logs-comfyui
logs-comfyui: ## Follow ComfyUI logs only
@echo -e "$(BLUE)[Logs]$(NC) Following ComfyUI logs..."
@$(COMPOSE) logs -f comfyui
.PHONY: logs-mcp
logs-mcp: ## Follow MCP server logs only
@echo -e "$(BLUE)[Logs]$(NC) Following MCP server logs..."
@$(COMPOSE) logs -f mcp-server
.PHONY: health
health: ## Check system health and GPU status
@echo -e "$(GREEN)[Health]$(NC) Running health check..."
@./scripts/health-check.sh
.PHONY: gpu
gpu: ## Check GPU status in container
@echo -e "$(BLUE)[GPU]$(NC) Checking GPU status..."
@$(COMPOSE) exec comfyui nvidia-smi || echo "GPU not available or container not running"
# ============================================================================
# Development & Testing
# ============================================================================
.PHONY: shell
shell: ## Open shell in ComfyUI container
@echo -e "$(BLUE)[Shell]$(NC) Opening ComfyUI shell..."
@$(COMPOSE) exec comfyui bash
.PHONY: shell-mcp
shell-mcp: ## Open shell in MCP server container
@echo -e "$(BLUE)[Shell]$(NC) Opening MCP server shell..."
@$(COMPOSE) exec mcp-server sh
.PHONY: test
test: ## Run MCP server tests
@echo -e "$(GREEN)[Test]$(NC) Running tests..."
@$(COMPOSE) exec mcp-server npm test
.PHONY: test-generate
test-generate: ## Test image generation via MCP
@echo -e "$(GREEN)[Test]$(NC) Testing image generation..."
@$(COMPOSE) exec mcp-server node examples/example.js
# ============================================================================
# Maintenance & Cleanup
# ============================================================================
.PHONY: backup
backup: ## Backup configurations and models inventory
@echo -e "$(GREEN)[Backup]$(NC) Creating backup..."
@./scripts/backup.sh
.PHONY: clean
clean: ## Clean up containers, volumes, and dangling images
@echo -e "$(YELLOW)[Clean]$(NC) Cleaning up Docker resources..."
@$(COMPOSE) down -v
@docker image prune -f
@echo -e "$(GREEN)✓$(NC) Cleanup complete"
.PHONY: clean-all
clean-all: ## Deep clean including all images and build cache
@echo -e "$(RED)[Clean]$(NC) Deep cleaning (this will remove all images)..."
@read -p "Are you sure? This will remove all project images and cache. (y/N): " confirm && \
if [ "$$confirm" = "y" ]; then \
$(COMPOSE) down -v --rmi all; \
docker builder prune -af; \
echo -e "$(GREEN)✓$(NC) Deep clean complete"; \
else \
echo -e "$(YELLOW)Cancelled$(NC)"; \
fi
.PHONY: prune
prune: ## Prune Docker system (safe cleanup)
@echo -e "$(YELLOW)[Prune]$(NC) Pruning Docker system..."
@docker system prune -f
@echo -e "$(GREEN)✓$(NC) Prune complete"
# ============================================================================
# Updates & Version Info
# ============================================================================
.PHONY: update
update: ## Update code and rebuild
@echo -e "$(GREEN)[Update]$(NC) Updating repository..."
@git pull
@echo -e "$(GREEN)[Update]$(NC) Rebuilding containers..."
@$(MAKE) build
@echo -e "$(GREEN)✓$(NC) Update complete"
.PHONY: version
version: ## Show version information
@echo -e "$(BLUE)Version Information:$(NC)"
@echo -n "Docker: " && docker --version
@echo -n "Compose: " && docker compose version
@echo -n "Python: " && $(COMPOSE) exec comfyui python3.11 --version 2>/dev/null || echo "Container not running"
@echo -n "PyTorch: " && $(COMPOSE) exec comfyui python3.11 -c "import torch; print(torch.__version__)" 2>/dev/null || echo "Container not running"
@echo -n "Node: " && $(COMPOSE) exec mcp-server node --version 2>/dev/null || echo "Container not running"
.PHONY: info
info: ## Show project information
@echo -e "$(BLUE)╔══════════════════════════════════════════════════════════╗$(NC)"
@echo -e "$(BLUE)║ MCP ComfyUI Flux - Project Info ║$(NC)"
@echo -e "$(BLUE)╚══════════════════════════════════════════════════════════╝$(NC)"
@echo ""
@echo "Project: $(PROJECT_NAME)"
@echo "Directory: $$(pwd)"
@echo ""
@echo -e "$(GREEN)Images:$(NC)"
@docker images | grep -E "($(PROJECT_NAME)|REPOSITORY)" | head -5
@echo ""
@echo -e "$(GREEN)Volumes:$(NC)"
@docker volume ls | grep -E "($(PROJECT_NAME)|DRIVER)" | head -5
@echo ""
@echo -e "$(GREEN)Disk Usage:$(NC)"
@du -sh models/ 2>/dev/null || echo " models/: Not found"
@du -sh output/ 2>/dev/null || echo " output/: Not found"
# ============================================================================
# Advanced Operations
# ============================================================================
.PHONY: exec
exec: ## Execute command in ComfyUI container (use with CMD="...")
@if [ -z "$(CMD)" ]; then \
echo "Usage: make exec CMD='your command'"; \
else \
echo -e "$(BLUE)[Exec]$(NC) Running: $(CMD)"; \
$(COMPOSE) exec comfyui bash -c "$(CMD)"; \
fi
.PHONY: pull
pull: ## Pull latest base images
@echo -e "$(GREEN)[Pull]$(NC) Pulling latest base images..."
@docker pull nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu22.04
@docker pull node:20-alpine
@docker pull alpine/git:2.43.0
@echo -e "$(GREEN)✓$(NC) Images updated"
.PHONY: push
push: ## Push images to registry (configure REGISTRY first)
@if [ -z "$(REGISTRY)" ]; then \
echo "Error: REGISTRY not set. Use: make push REGISTRY=your-registry.com"; \
else \
echo -e "$(GREEN)[Push]$(NC) Pushing to $(REGISTRY)..."; \
docker tag $(PROJECT_NAME)-comfyui $(REGISTRY)/$(PROJECT_NAME)-comfyui:latest; \
docker tag $(PROJECT_NAME)-mcp-server $(REGISTRY)/$(PROJECT_NAME)-mcp-server:latest; \
docker push $(REGISTRY)/$(PROJECT_NAME)-comfyui:latest; \
docker push $(REGISTRY)/$(PROJECT_NAME)-mcp-server:latest; \
echo -e "$(GREEN)✓$(NC) Push complete"; \
fi
# ============================================================================
# MCP Integration
# ============================================================================
.PHONY: mcp-config
mcp-config: ## Show MCP client configuration
@echo -e "$(BLUE)MCP Client Configuration:$(NC)"
@echo ""
@echo '{'
@echo ' "mcpServers": {'
@echo ' "comfyui-flux": {'
@echo ' "command": "docker",'
@echo ' "args": ['
@echo ' "compose", "-p", "$(PROJECT_NAME)",'
@echo ' "exec", "-T", "mcp-server",'
@echo ' "node", "/app/src/index.js"'
@echo ' ]'
@echo ' }'
@echo ' }'
@echo '}'
.PHONY: mcp-test
mcp-test: ## Test MCP connection
@echo -e "$(GREEN)[MCP]$(NC) Testing MCP connection..."
@$(COMPOSE) exec mcp-server node -e "console.log('MCP server is accessible')"
@echo -e "$(GREEN)✓$(NC) MCP test passed"
# ============================================================================
# Development Helpers
# ============================================================================
.PHONY: watch
watch: ## Watch logs with timestamps
@watch -n 2 "$(COMPOSE) ps && echo '' && $(COMPOSE) logs --tail=10"
.PHONY: monitor
monitor: ## Monitor resource usage
@docker stats --no-stream $$($(COMPOSE) ps -q)
.PHONY: validate
validate: ## Validate configuration files
@echo -e "$(BLUE)[Validate]$(NC) Checking configuration..."
@docker compose -f docker-compose.yml config > /dev/null && \
echo -e "$(GREEN)✓$(NC) docker-compose.yml is valid" || \
echo -e "$(RED)✗$(NC) docker-compose.yml has errors"
@[ -f .env ] && echo -e "$(GREEN)✓$(NC) .env exists" || echo -e "$(YELLOW)!$(NC) .env not found"
@[ -f requirements.txt ] && echo -e "$(GREEN)✓$(NC) requirements.txt exists" || echo -e "$(RED)✗$(NC) requirements.txt not found"
# Catch-all target for undefined targets
%:
@echo -e "$(RED)Error:$(NC) Unknown target '$@'"
@echo "Run 'make help' to see available commands"
@exit 1