-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
290 lines (237 loc) · 9.32 KB
/
Makefile
File metadata and controls
290 lines (237 loc) · 9.32 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# =============================================================================
# Postal Inspector - Makefile
# =============================================================================
# AI-powered email security scanner
# Run 'make' or 'make help' for available targets
# =============================================================================
# -----------------------------------------------------------------------------
# Variables
# -----------------------------------------------------------------------------
SHELL := /bin/bash
.DEFAULT_GOAL := help
# Project settings
PROJECT_NAME := postal-inspector
PYTHON_VERSION := 3.12
# Docker settings
COMPOSE := docker compose
DOCKER_BUILDKIT ?= 1
# Paths
SRC_DIR := src
TEST_DIR := tests
COVERAGE_DIR := htmlcov
# UV settings
UV := uv
UV_RUN := $(UV) run
# Marker files for idempotency
VENV_MARKER := .venv/.installed
DEV_MARKER := .venv/.dev-installed
# -----------------------------------------------------------------------------
# Phony targets
# -----------------------------------------------------------------------------
.PHONY: help
.PHONY: install dev sync
.PHONY: test test-cov lint lint-fix format format-check type-check check
.PHONY: clean clean-all clean-docker
.PHONY: build build-no-cache up down logs restart status
.PHONY: logs-imap logs-processor logs-briefing logs-antivirus
.PHONY: shell-imap shell-processor shell-briefing
.PHONY: fetch-now test-briefing
.PHONY: briefing health
# =============================================================================
# Help
# =============================================================================
help:
@echo ""
@echo "Postal Inspector - AI-Powered Email Security Scanner"
@echo "====================================================="
@echo ""
@echo "Installation:"
@echo " make install Install production dependencies"
@echo " make dev Install dev dependencies (lint, test, etc.)"
@echo " make sync Force re-sync all dependencies"
@echo ""
@echo "Development:"
@echo " make test Run tests"
@echo " make test-cov Run tests with coverage report"
@echo " make lint Run ruff linter (check only)"
@echo " make lint-fix Run ruff linter with auto-fix"
@echo " make format Format code with ruff"
@echo " make format-check Check formatting without changes"
@echo " make type-check Run mypy type checker"
@echo " make check Run all quality checks (lint, type-check, test)"
@echo " make clean Remove build artifacts and caches"
@echo ""
@echo "Docker:"
@echo " make build Build all Docker images"
@echo " make build-no-cache Build images without cache"
@echo " make up Start all services (detached)"
@echo " make down Stop all services"
@echo " make restart Restart all services"
@echo " make status Show service status"
@echo " make logs Follow all service logs"
@echo ""
@echo "Docker Logs (individual):"
@echo " make logs-imap Follow IMAP server logs"
@echo " make logs-processor Follow mail processor logs"
@echo " make logs-briefing Follow daily briefing logs"
@echo " make logs-antivirus Follow antivirus logs"
@echo ""
@echo "Docker Shells:"
@echo " make shell-imap Shell into IMAP container"
@echo " make shell-processor Shell into mail processor container"
@echo " make shell-briefing Shell into briefing container"
@echo ""
@echo "Operations:"
@echo " make briefing Generate daily briefing now"
@echo " make health Check service health"
@echo " make fetch-now Trigger immediate mail fetch (in container)"
@echo " make test-briefing Test briefing generation (in container)"
@echo ""
@echo "Cleanup:"
@echo " make clean Remove Python build artifacts"
@echo " make clean-docker Remove Docker images and volumes"
@echo " make clean-all Remove all artifacts (Python + Docker)"
@echo ""
# =============================================================================
# Installation
# =============================================================================
# Production install - installs only runtime dependencies
install: $(VENV_MARKER)
$(VENV_MARKER): pyproject.toml uv.lock
@echo "Installing production dependencies..."
$(UV) sync --no-dev
@mkdir -p .venv
@touch $(VENV_MARKER)
@rm -f $(DEV_MARKER)
# Development install - includes dev dependencies (test, lint, type-check)
dev: $(DEV_MARKER)
$(DEV_MARKER): pyproject.toml uv.lock
@echo "Installing development dependencies..."
$(UV) sync --all-groups
@mkdir -p .venv
@touch $(DEV_MARKER)
@rm -f $(VENV_MARKER)
# Force re-sync (useful when lock file changes or for troubleshooting)
sync:
@echo "Force syncing all dependencies..."
$(UV) sync --all-groups
@mkdir -p .venv
@touch $(DEV_MARKER)
@rm -f $(VENV_MARKER)
# =============================================================================
# Development - Testing
# =============================================================================
test: dev
$(UV_RUN) pytest $(TEST_DIR)/ -v
test-cov: dev
$(UV_RUN) pytest $(TEST_DIR)/ --cov=postal_inspector --cov-report=term-missing --cov-report=html:$(COVERAGE_DIR)
@echo "Coverage report generated in $(COVERAGE_DIR)/index.html"
# =============================================================================
# Development - Code Quality
# =============================================================================
# Lint check only (does not modify files)
lint: dev
$(UV_RUN) ruff check $(SRC_DIR)/ $(TEST_DIR)/
# Lint with auto-fix
lint-fix: dev
$(UV_RUN) ruff check --fix $(SRC_DIR)/ $(TEST_DIR)/
# Format code
format: dev
$(UV_RUN) ruff format $(SRC_DIR)/ $(TEST_DIR)/
# Check formatting without modifying (useful for CI)
format-check: dev
$(UV_RUN) ruff format --check $(SRC_DIR)/ $(TEST_DIR)/
# Type checking
type-check: dev
$(UV_RUN) mypy $(SRC_DIR)/
# Run all quality checks
check: lint format-check type-check test
@echo ""
@echo "All checks passed!"
# =============================================================================
# Cleanup
# =============================================================================
clean:
@echo "Cleaning Python build artifacts..."
rm -rf .pytest_cache
rm -rf .mypy_cache
rm -rf .ruff_cache
rm -rf .coverage
rm -rf $(COVERAGE_DIR)
rm -rf dist
rm -rf build
rm -rf *.egg-info
rm -rf $(SRC_DIR)/*.egg-info
rm -f $(VENV_MARKER) $(DEV_MARKER)
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete 2>/dev/null || true
@echo "Clean complete."
clean-docker:
@echo "Cleaning Docker artifacts..."
$(COMPOSE) down --rmi local --volumes --remove-orphans 2>/dev/null || true
@echo "Docker clean complete."
clean-all: clean clean-docker
@echo "Full cleanup complete."
# =============================================================================
# Docker - Build
# =============================================================================
build:
@echo "Building Docker images..."
DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) $(COMPOSE) build
build-no-cache:
@echo "Building Docker images (no cache)..."
DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) $(COMPOSE) build --no-cache
# =============================================================================
# Docker - Services
# =============================================================================
up:
@echo "Starting services..."
$(COMPOSE) up -d
@echo ""
@echo "Services started. Run 'make logs' to follow logs or 'make status' to check status."
down:
@echo "Stopping services..."
$(COMPOSE) down
restart:
@echo "Restarting services..."
$(COMPOSE) restart
status:
$(COMPOSE) ps
# =============================================================================
# Docker - Logs
# =============================================================================
logs:
$(COMPOSE) logs -f
logs-imap:
$(COMPOSE) logs -f imap
logs-processor:
$(COMPOSE) logs -f mail-processor
logs-briefing:
$(COMPOSE) logs -f daily-briefing
logs-antivirus:
$(COMPOSE) logs -f antivirus
# =============================================================================
# Docker - Shells
# =============================================================================
shell-imap:
$(COMPOSE) exec imap /bin/sh
shell-processor:
$(COMPOSE) exec mail-processor /bin/bash
shell-briefing:
$(COMPOSE) exec daily-briefing /bin/bash
# =============================================================================
# Docker - Operations
# =============================================================================
fetch-now:
@echo "Triggering immediate mail fetch..."
$(COMPOSE) exec mail-processor postal-inspector scanner --once
test-briefing:
@echo "Testing briefing generation..."
$(COMPOSE) exec daily-briefing postal-inspector briefing --now
# =============================================================================
# Operations (Local)
# =============================================================================
briefing: dev
$(UV_RUN) postal-inspector briefing --now
health: dev
$(UV_RUN) postal-inspector health