|
| 1 | +# ============================================================================= |
| 2 | +# PostBot - Docker Development Commands |
| 3 | +# ============================================================================= |
| 4 | +# |
| 5 | +# Usage: make <command> |
| 6 | +# |
| 7 | +# Run `make help` to see all available commands. |
| 8 | +# |
| 9 | +# Prerequisites: |
| 10 | +# - Docker & Docker Compose installed |
| 11 | +# - .env file configured (copy from .env.example) |
| 12 | +# |
| 13 | +# ============================================================================= |
| 14 | + |
| 15 | +.PHONY: help up down logs restart build worker-logs beat-logs migrate test shell clean prune redis-cli status |
| 16 | + |
| 17 | +.DEFAULT_GOAL := help |
| 18 | + |
| 19 | +# Colors for terminal output |
| 20 | +CYAN := \033[36m |
| 21 | +GREEN := \033[32m |
| 22 | +YELLOW := \033[33m |
| 23 | +RED := \033[31m |
| 24 | +RESET := \033[0m |
| 25 | + |
| 26 | +# ============================================================================= |
| 27 | +# HELP |
| 28 | +# ============================================================================= |
| 29 | + |
| 30 | +help: ## Show this help message |
| 31 | + @echo "" |
| 32 | + @echo "$(CYAN)PostBot - Docker Development Commands$(RESET)" |
| 33 | + @echo "=======================================" |
| 34 | + @echo "" |
| 35 | + @echo "$(GREEN)Quick Start:$(RESET)" |
| 36 | + @echo " 1. Copy .env.example to .env and configure" |
| 37 | + @echo " 2. Run: make up" |
| 38 | + @echo " 3. Open: http://localhost:3000" |
| 39 | + @echo "" |
| 40 | + @echo "$(GREEN)Available Commands:$(RESET)" |
| 41 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(CYAN)%-15s$(RESET) %s\n", $$1, $$2}' |
| 42 | + @echo "" |
| 43 | + |
| 44 | +# ============================================================================= |
| 45 | +# DOCKER COMPOSE COMMANDS |
| 46 | +# ============================================================================= |
| 47 | + |
| 48 | +up: ## Start the entire stack (detached mode) |
| 49 | + @echo "$(GREEN)Starting PostBot stack...$(RESET)" |
| 50 | + docker-compose up -d |
| 51 | + @echo "" |
| 52 | + @echo "$(GREEN)✓ Stack started!$(RESET)" |
| 53 | + @echo " Frontend: http://localhost:3000" |
| 54 | + @echo " Backend: http://localhost:8000" |
| 55 | + @echo " API Docs: http://localhost:8000/docs" |
| 56 | + @echo "" |
| 57 | + @echo "$(YELLOW)Tip: Run 'make logs' to see output$(RESET)" |
| 58 | + |
| 59 | +down: ## Stop the entire stack |
| 60 | + @echo "$(RED)Stopping PostBot stack...$(RESET)" |
| 61 | + docker-compose down |
| 62 | + @echo "$(GREEN)✓ Stack stopped$(RESET)" |
| 63 | + |
| 64 | +restart: ## Restart all services |
| 65 | + @echo "$(YELLOW)Restarting PostBot stack...$(RESET)" |
| 66 | + docker-compose restart |
| 67 | + @echo "$(GREEN)✓ Stack restarted$(RESET)" |
| 68 | + |
| 69 | +build: ## Rebuild all Docker images (use after requirements.txt changes) |
| 70 | + @echo "$(YELLOW)Rebuilding Docker images...$(RESET)" |
| 71 | + docker-compose build --no-cache |
| 72 | + @echo "$(GREEN)✓ Images rebuilt$(RESET)" |
| 73 | + |
| 74 | +status: ## Show status of all containers |
| 75 | + @echo "$(CYAN)Container Status:$(RESET)" |
| 76 | + docker-compose ps |
| 77 | + |
| 78 | +# ============================================================================= |
| 79 | +# LOGS |
| 80 | +# ============================================================================= |
| 81 | + |
| 82 | +logs: ## Tail logs for all services |
| 83 | + docker-compose logs -f |
| 84 | + |
| 85 | +worker-logs: ## Tail Celery worker logs (for debugging background tasks) |
| 86 | + @echo "$(CYAN)Tailing Celery worker logs...$(RESET)" |
| 87 | + docker-compose logs -f worker |
| 88 | + |
| 89 | +beat-logs: ## Tail Celery beat scheduler logs |
| 90 | + @echo "$(CYAN)Tailing Celery beat logs...$(RESET)" |
| 91 | + docker-compose logs -f beat |
| 92 | + |
| 93 | +backend-logs: ## Tail backend API logs |
| 94 | + docker-compose logs -f backend |
| 95 | + |
| 96 | +frontend-logs: ## Tail frontend logs |
| 97 | + docker-compose logs -f frontend |
| 98 | + |
| 99 | +# ============================================================================= |
| 100 | +# DATABASE & MIGRATIONS |
| 101 | +# ============================================================================= |
| 102 | + |
| 103 | +migrate: ## Run Alembic migrations inside the backend container |
| 104 | + @echo "$(YELLOW)Running database migrations...$(RESET)" |
| 105 | + docker-compose exec backend alembic upgrade head |
| 106 | + @echo "$(GREEN)✓ Migrations complete$(RESET)" |
| 107 | + |
| 108 | +migrate-create: ## Create a new migration (usage: make migrate-create MSG="add user table") |
| 109 | + @echo "$(YELLOW)Creating new migration...$(RESET)" |
| 110 | + docker-compose exec backend alembic revision --autogenerate -m "$(MSG)" |
| 111 | + @echo "$(GREEN)✓ Migration created$(RESET)" |
| 112 | + |
| 113 | +migrate-history: ## Show migration history |
| 114 | + docker-compose exec backend alembic history |
| 115 | + |
| 116 | +# ============================================================================= |
| 117 | +# TESTING |
| 118 | +# ============================================================================= |
| 119 | + |
| 120 | +test: ## Run backend tests (pytest) |
| 121 | + @echo "$(CYAN)Running backend tests...$(RESET)" |
| 122 | + docker-compose exec backend pytest -v |
| 123 | + @echo "$(GREEN)✓ Tests complete$(RESET)" |
| 124 | + |
| 125 | +test-cov: ## Run tests with coverage report |
| 126 | + @echo "$(CYAN)Running tests with coverage...$(RESET)" |
| 127 | + docker-compose exec backend pytest --cov=. --cov-report=term-missing |
| 128 | + |
| 129 | +# ============================================================================= |
| 130 | +# SHELL ACCESS |
| 131 | +# ============================================================================= |
| 132 | + |
| 133 | +shell: ## Open a bash shell inside the backend container |
| 134 | + @echo "$(CYAN)Opening shell in backend container...$(RESET)" |
| 135 | + docker-compose exec backend /bin/bash |
| 136 | + |
| 137 | +shell-frontend: ## Open a shell inside the frontend container |
| 138 | + docker-compose exec frontend /bin/sh |
| 139 | + |
| 140 | +redis-cli: ## Open Redis CLI |
| 141 | + @echo "$(CYAN)Opening Redis CLI...$(RESET)" |
| 142 | + docker-compose exec redis redis-cli |
| 143 | + |
| 144 | +# ============================================================================= |
| 145 | +# CLEANUP |
| 146 | +# ============================================================================= |
| 147 | + |
| 148 | +clean: ## Stop stack and remove volumes (WARNING: deletes data) |
| 149 | + @echo "$(RED)Stopping stack and removing volumes...$(RESET)" |
| 150 | + docker-compose down -v |
| 151 | + @echo "$(GREEN)✓ Stack stopped and volumes removed$(RESET)" |
| 152 | + |
| 153 | +prune: ## Remove unused Docker resources |
| 154 | + @echo "$(YELLOW)Pruning unused Docker resources...$(RESET)" |
| 155 | + docker system prune -f |
| 156 | + @echo "$(GREEN)✓ Cleanup complete$(RESET)" |
| 157 | + |
| 158 | +# ============================================================================= |
| 159 | +# DEVELOPMENT SHORTCUTS |
| 160 | +# ============================================================================= |
| 161 | + |
| 162 | +dev-backend: ## Start only backend services (redis + backend + worker + beat) |
| 163 | + docker-compose up -d redis backend worker beat |
| 164 | + |
| 165 | +dev-frontend: ## Start only frontend (assumes backend is running elsewhere) |
| 166 | + docker-compose up -d frontend |
| 167 | + |
| 168 | +# ============================================================================= |
| 169 | +# HEALTH CHECKS |
| 170 | +# ============================================================================= |
| 171 | + |
| 172 | +health: ## Check health of all services |
| 173 | + @echo "$(CYAN)Checking service health...$(RESET)" |
| 174 | + @echo "" |
| 175 | + @echo "Backend API:" |
| 176 | + @curl -s http://localhost:8000/health | python -m json.tool 2>/dev/null || echo " $(RED)✗ Not responding$(RESET)" |
| 177 | + @echo "" |
| 178 | + @echo "Redis:" |
| 179 | + @docker-compose exec -T redis redis-cli ping 2>/dev/null || echo " $(RED)✗ Not responding$(RESET)" |
| 180 | + @echo "" |
| 181 | + @echo "Frontend:" |
| 182 | + @curl -s -o /dev/null -w " Status: %{http_code}\n" http://localhost:3000 2>/dev/null || echo " $(RED)✗ Not responding$(RESET)" |
0 commit comments