-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMakefile
More file actions
160 lines (128 loc) · 4.64 KB
/
Copy pathMakefile
File metadata and controls
160 lines (128 loc) · 4.64 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
.PHONY: help install install-dev dev test selftest lint format type-check security-scan \
migrate migrate-new migrate-down migrate-history db-reset db-seed \
build build-no-cache up up-recreate down down-volumes restart logs logs-backend logs-frontend ps \
health-check clean clean-docker clean-all
PYTHON ?= python3
PYTEST ?= pytest
# 优先 v2 插件(docker compose),无插件时回退 v1(docker-compose);可用 make up COMPOSE=... 覆盖
COMPOSE ?= $(shell docker compose version >/dev/null 2>&1 && echo docker compose || echo docker-compose)
BACKEND_PORT ?= 3001
PYTHONPATH_BACKEND := src/backend
help:
@echo "HugAgentOS Makefile Commands:"
@echo ""
@echo "Development:"
@echo " make install - Install runtime dependencies"
@echo " make install-dev - Install project with dev extras"
@echo " make dev - Start backend in local dev mode"
@echo " make test - Run backend test suite with coverage"
@echo " make selftest - Run backend self-tests (fail fast)"
@echo ""
@echo "Quality:"
@echo " make lint - Run format checks"
@echo " make format - Format code"
@echo " make type-check - Run mypy"
@echo " make security-scan - Run bandit and safety checks"
@echo ""
@echo "Database:"
@echo " make migrate - Apply latest migrations"
@echo " make migrate-new - Create migration (msg='description')"
@echo " make migrate-down - Rollback one migration"
@echo " make migrate-history - Show migration history"
@echo " make db-reset - Reset DB to latest (destructive)"
@echo " make db-seed - Seed sample data"
@echo ""
@echo "Docker:"
@echo " make build - Build images"
@echo " make build-no-cache - Build images without cache"
@echo " make up - Start containers"
@echo " make up-recreate - Recreate containers"
@echo " make down - Stop containers"
@echo " make down-volumes - Stop and remove volumes"
@echo " make restart - Restart containers"
@echo " make logs - Tail all container logs"
@echo " make logs-backend - Tail backend logs"
@echo " make logs-frontend - Tail frontend logs"
@echo " make ps - Show container status"
@echo ""
@echo "Utilities:"
@echo " make health-check - Check /health and /ready"
@echo " make clean - Remove local caches/artifacts"
@echo " make clean-docker - Remove docker volumes and dangling data"
@echo " make clean-all - clean + clean-docker"
install:
$(PYTHON) -m pip install -r requirements.txt
install-dev:
$(PYTHON) -m pip install -e ".[dev]"
dev:
PYTHONPATH=$(PYTHONPATH_BACKEND) uvicorn api.app:app --reload --host 0.0.0.0 --port $(BACKEND_PORT)
test:
PYTHONPATH=$(PYTHONPATH_BACKEND) $(PYTEST) src/backend/tests/ -v --cov=src/backend --cov-report=html --cov-report=term
selftest:
PYTHONPATH=$(PYTHONPATH_BACKEND) $(PYTEST) src/backend/tests/ -v -x -q
lint:
black . --line-length=100 --check
isort . --profile black --check
format:
black . --line-length=100
isort . --profile black
type-check:
mypy src/backend --ignore-missing-imports
security-scan:
bandit -r . -ll -i -x src/backend/tests,venv
safety check
migrate:
alembic upgrade head
migrate-new:
@if [ -z "$(msg)" ]; then \
echo "Error: Please provide a message: make migrate-new msg='your message'"; \
exit 1; \
fi
alembic revision --autogenerate -m "$(msg)"
migrate-down:
alembic downgrade -1
migrate-history:
alembic history --verbose
db-reset:
@echo "WARNING: This will delete all data. Press Ctrl+C to cancel, or Enter to continue."
@read confirm
alembic downgrade base
alembic upgrade head
db-seed:
PYTHONPATH=$(PYTHONPATH_BACKEND) $(PYTHON) src/backend/scripts/seed_data.py
build:
$(COMPOSE) build
build-no-cache:
$(COMPOSE) build --no-cache
up:
$(COMPOSE) up -d
up-recreate:
$(COMPOSE) up -d --force-recreate
down:
$(COMPOSE) down
down-volumes:
$(COMPOSE) down -v
restart:
$(COMPOSE) restart
logs:
$(COMPOSE) logs -f
logs-backend:
$(COMPOSE) logs -f backend
logs-frontend:
$(COMPOSE) logs -f frontend
ps:
$(COMPOSE) ps
health-check:
@echo "Checking backend health on :$(BACKEND_PORT)..."
@curl -fsS http://localhost:$(BACKEND_PORT)/health >/dev/null && echo "health: ok" || echo "health: failed"
@curl -fsS http://localhost:$(BACKEND_PORT)/ready >/dev/null && echo "ready: ok" || echo "ready: failed"
clean:
find . -type f -name '*.pyc' -delete
find . -type d -name '__pycache__' -delete
find . -type d -name '*.egg-info' -exec rm -rf {} +
find . -type f -name '.coverage' -delete
rm -rf htmlcov/ .pytest_cache/ .mypy_cache/ dist/ build/
clean-docker:
$(COMPOSE) down -v
docker system prune -f
clean-all: clean clean-docker