-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
229 lines (177 loc) · 8.17 KB
/
Makefile
File metadata and controls
229 lines (177 loc) · 8.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Reddit AI Curator - Makefile
# Supports both Docker and native installation
.PHONY: help setup setup-native setup-docker up down logs build restart clean test migrate lint format type-check status health
# Colors for output
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
NC = \033[0m # No Color
# Check if Docker is available
DOCKER_AVAILABLE := $(shell command -v docker-compose >/dev/null 2>&1 && echo "yes" || echo "no")
help: ## Show this help message
@echo -e "\n${GREEN}Reddit AI Curator - Available Commands${NC}\n"
@echo "Installation Mode: $(if $(filter yes,$(DOCKER_AVAILABLE)),Docker,native)"
@echo ""
@awk 'BEGIN {FS = ":.*##"; printf "Usage: make <target>\n\n"} /^[a-zA-Z_-]+:.*##/ { printf " ${GREEN}%-20s${NC} %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
@echo ""
@echo "Docker commands: up, down, logs, restart, build, status, health, shell-*"
@echo "Native commands: setup-native, run, test-native, lint-native"
@echo ""
# ============================================================================
# Installation Setup
# ============================================================================
setup: ## Detect and run appropriate setup (Docker or native)
@if [ "$(DOCKER_AVAILABLE)" = "yes" ]; then \
echo -e "${GREEN}Docker detected. Use 'make setup-docker' for Docker setup.${NC}"; \
echo -e "${YELLOW}For native setup, use 'make setup-native'${NC}"; \
else \
echo -e "${YELLOW}Docker not detected. Running native setup...${NC}"; \
make setup-native; \
fi
setup-native: ## Setup without Docker (local Python + dependencies)
@echo -e "\n${GREEN}=== Native Setup ===${NC}\n"
@echo "1. Creating Python virtual environment..."
@if [ ! -d ".venv" ]; then \
python3 -m venv .venv && echo " ✓ Virtual environment created"; \
else \
echo " ✓ Virtual environment already exists"; \
fi
@echo ""
@echo "2. Installing Python dependencies..."
@. .venv/bin/activate && pip install --upgrade pip -q
@. .venv/bin/activate && pip install -r requirements.txt -q && echo " ✓ Dependencies installed"
@echo ""
@echo "3. Creating directories..."
@mkdir -p scripts tests/unit tests/integration tests/fixtures init-scripts backups && echo " ✓ Directories created"
@echo ""
@echo "4. Creating .env file..."
@if [ ! -f ".env" ]; then \
cp .env.example .env && echo " ✓ .env created from template"; \
echo -e " ${YELLOW}⚠ Edit .env and add your API keys!${NC}"; \
else \
echo " ✓ .env already exists"; \
fi
@echo ""
@echo -e "${GREEN}=== Native Setup Complete ===${NC}\n"
@echo "Next steps:"
@echo " 1. Edit .env and add API keys (REDDIT_CLIENT_ID, MISTRAL_API_KEY, etc.)"
@echo " 2. Start PostgreSQL and Redis (or use Docker)"
@echo " 3. Run: . .venv/bin/activate && python app.py"
@echo ""
setup-docker: ## Setup with Docker Compose
@echo -e "\n${GREEN}=== Docker Setup ===${NC}\n"
@if [ "$(DOCKER_AVAILABLE)" = "no" ]; then \
echo -e "${RED}✗ docker-compose not found${NC}"; \
echo "Please install Docker first:"; \
echo " Ubuntu: sudo apt install docker.io docker-compose"; \
echo " macOS: brew install docker docker-compose"; \
echo ""; \
exit 1; \
fi
@echo "1. Building and starting containers..."
@docker-compose up -d --build
@echo ""
@echo "2. Waiting for services to be healthy..."
@sleep 5 && make health || echo " ⚠ Some services may still be starting"
@echo ""
@echo -e "${GREEN}=== Docker Setup Complete ===${NC}\n"
@echo "Access the application at: http://localhost:5000"
# ============================================================================
# Docker Compose commands (if available)
# ============================================================================
ifeq ($(DOCKER_AVAILABLE),yes)
up: ## Start all Docker services
docker-compose up -d
down: ## Stop all Docker services
docker-compose down
logs: ## View logs (follow by default)
docker-compose logs -f
logs-backend: ## View backend logs only
docker-compose logs -f backend
logs-frontend: ## View frontend logs only
docker-compose logs -f frontend
logs-db: ## View database logs only
docker-compose logs -f postgres
restart: ## Restart all services
docker-compose restart
build: ## Rebuild all containers
docker-compose build --no-cache
migrate: ## Run database migrations
docker-compose exec backend python scripts/migrate_json_to_postgres.py
migrate-status: ## Check migration status
docker-compose exec backend python -c "from scripts.migration_check import check_status; check_status()"
db-backup: ## Backup database
docker-compose exec postgres pg_dump -U curator reddit_curator > backups/db_ $$(date +%Y%m%d_%H%M%S).sql
db-restore: ## Restore database (usage: make db-restore file=backups/db_20240119_120000.sql)
docker-compose exec -T postgres psql -U curator -d reddit_curator < $(file)
test: ## Run tests (Docker)
docker-compose exec backend pytest tests/ -v --cov=app --cov-report=term-missing
test-unit: ## Run unit tests only (Docker)
docker-compose exec backend pytest tests/unit/ -v
test-integration: ## Run integration tests only (Docker)
docker-compose exec backend pytest tests/integration/ -v
lint: ## Lint Python code (Docker)
docker-compose exec backend ruff check .
format: ## Format Python code (Docker)
docker-compose exec backend ruff check --fix .
type-check: ## Type check Python code (Docker)
docker-compose exec backend mypy .
clean: ## Clean up containers, volumes, and cache
docker-compose down -v
docker system prune -af
rm -rf frontend-new/node_modules
rm -rf __pycache__
rm -rf .pytest_cache
rm -rf .ruff_cache
clean-images: ## Remove all Docker images
docker system prune -af --volumes
status: ## Show service status
docker-compose ps
health: ## Check service health
@echo -e "${YELLOW}Checking service health...${NC}"
@docker-compose exec -T backend curl -sf http://localhost:5000/health 2>/dev/null && echo -e " ${GREEN}Backend: Healthy${NC}" || echo -e " ${RED}Backend: Unhealthy${NC}"
@docker-compose exec -T redis redis-cli ping > /dev/null 2>&1 && echo -e " ${GREEN}Redis: Healthy${NC}" || echo -e " ${YELLOW}Redis: Not Available${NC}"
@docker-compose exec -T postgres pg_isready -U curator -d reddit_curator > /dev/null 2>&1 && echo -e " ${GREEN}PostgreSQL: Healthy${NC}" || echo -e " ${YELLOW}PostgreSQL: Not Available${NC}"
seed-subreddits: ## Seed default subreddits
docker-compose exec backend python scripts/seed_subreddits.py
shell-backend: ## Get shell access to backend
docker-compose exec backend bash
shell-db: ## Get shell access to database
docker-compose exec postgres bash
endif
# ============================================================================
# Native commands (always available)
# ============================================================================
run: ## Run the application (native)
@. .venv/bin/activate && python app.py
test-native: ## Run tests (native)
@. .venv/bin/activate && pytest tests/ -v --cov=app --cov-report=term-missing
test-unit-native: ## Run unit tests only (native)
@. .venv/bin/activate && pytest tests/unit/ -v
test-integration-native: ## Run integration tests only (native)
@. .venv/bin/activate && pytest tests/integration/ -v
lint-native: ## Lint Python code (native)
@. .venv/bin/activate && ruff check .
format-native: ## Format Python code (native)
@. .venv/bin/activate && ruff check --fix .
type-check-native: ## Type check Python code (native)
@. .venv/bin/activate && mypy .
# ============================================================================
# Frontend commands
# ============================================================================
frontend-install: ## Install frontend dependencies
cd frontend-new && npm install
frontend-build: ## Build frontend for production
cd frontend-new && npm run build
frontend-dev: ## Start frontend development server
cd frontend-new && npm run dev
frontend-lint: ## Lint frontend code
cd frontend-new && npm run lint
# ============================================================================
# Utility
# ============================================================================
verify: ## Verify frontend setup
@bash verify_frontend.sh
openapi-docs: ## Generate OpenAPI documentation
@echo "OpenAPI spec available at: openapi.yaml"
@echo "View at: https://editor.swagger.io/"