-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
166 lines (133 loc) · 4.83 KB
/
Copy pathMakefile
File metadata and controls
166 lines (133 loc) · 4.83 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
# ============================================
# Makefile - 常用命令
# ============================================
.PHONY: help build up down logs ps clean test deploy restart up-f down-v rebuild \
test-backend test-frontend backup restore shell-backend shell-db shell-redis \
update version health logs-backend logs-frontend logs-db \
audit audit-api audit-web audit-web-crud audit-web-crud-students \
audit-web-crud-rooms audit-web-workflow-repairs
# 默认目标
help:
@echo "Available commands:"
@echo " make build - Build all Docker images"
@echo " make up - Start all services (background)"
@echo " make down - Stop all services"
@echo " make restart - Restart all services"
@echo " make logs - Tail all logs"
@echo " make logs-backend - Tail backend logs only"
@echo " make logs-frontend - Tail frontend logs only"
@echo " make logs-db - Tail postgres logs only"
@echo " make ps - List running containers"
@echo " make clean - Remove containers + volumes + images"
@echo " make test - Run backend + frontend tests"
@echo " make audit - Run full E2E baseline (audit_api + 4 audit_web_* + 工作流)"
@echo " make backup - Dump postgres database"
@echo " make restore - Restore postgres database (file=...)"
# 构建镜像
build:
docker compose build
# 启动服务(后台)
up:
docker compose up -d
# 启动服务(前台,调试用)
up-f:
docker compose up
# 停止服务
down:
docker compose down
# 停止并删除数据卷
down-v:
docker compose down -v
# 重启服务
restart:
docker compose restart
# 查看日志
logs:
docker compose logs -f
# 查看后端日志
logs-backend:
docker compose logs -f backend
# 查看前端日志
logs-frontend:
docker compose logs -f frontend
# 查看数据库日志
logs-db:
docker compose logs -f postgres
# 列出运行中的容器
ps:
docker compose ps
# 清理
clean:
docker compose down -v --rmi all --remove-orphans
docker system prune -f
# 重新构建并启动
rebuild: down build up
# 运行测试
test: test-backend test-frontend
# 后端测试
test-backend:
cd UniDormManagerServer && go test -v ./...
# 前端测试
test-frontend:
cd UniDormManagerWeb && npm test -- --run
# ─────────────── 全栈 baseline E2E harness ───────────────
# 预置:vite preview :3000(npm run build && npm run preview)+ 后端 :8082 + admin/admin123
# 任何一个 fail 立即停止后续(set -e via && 链);最终汇总 baseline 通过项
audit: audit-api audit-web audit-web-crud audit-web-crud-students audit-web-crud-rooms audit-web-workflow-repairs
@echo ""
@echo "============================================"
@echo "✅ baseline 全栈 E2E harness 全绿"
@echo "============================================"
audit-api:
@echo "── audit_api (后端 API 38 项) ──"
BASE=$${BASE:-http://localhost:8082} python3 tests/audit_api.py
audit-web:
@echo "── audit_web (Web 导航 17 项) ──"
WEB_BASE=$${WEB_BASE:-http://localhost:3000} node tests/audit_web.js
audit-web-crud:
@echo "── audit_web_crud (Buildings UI CRUD 14 项) ──"
ADMIN_PASS=$${ADMIN_PASS:-admin123} node tests/audit_web_crud.js
audit-web-crud-students:
@echo "── audit_web_crud_students (Students UI CRUD 10 项) ──"
ADMIN_PASS=$${ADMIN_PASS:-admin123} node tests/audit_web_crud_students.js
audit-web-crud-rooms:
@echo "── audit_web_crud_rooms (Rooms UI CRUD 13 项) ──"
ADMIN_PASS=$${ADMIN_PASS:-admin123} node tests/audit_web_crud_rooms.js
audit-web-workflow-repairs:
@echo "── audit_web_workflow_repairs (Repairs status workflow 13 项) ──"
ADMIN_PASS=$${ADMIN_PASS:-admin123} node tests/audit_web_workflow_repairs.js
# 数据库备份
backup:
@mkdir -p backups
@FILE=backups/unidorm_$$(date +%Y%m%d_%H%M%S).sql; \
docker compose exec -T postgres pg_dump -U $${POSTGRES_USER:-postgres} $${POSTGRES_DB:-unidorm} > $$FILE; \
echo "Backup completed: $$FILE"
# 数据库恢复(需要指定文件)
restore:
@if [ -z "$(file)" ]; then \
echo "Usage: make restore file=backups/unidorm_20260528_120000.sql"; \
exit 1; \
fi
docker compose exec -T postgres psql -U $${POSTGRES_USER:-postgres} -d $${POSTGRES_DB:-unidorm} < $(file)
@echo "Restore completed from $(file)"
# 进入后端容器
shell-backend:
docker compose exec backend sh
# 进入数据库
shell-db:
docker compose exec postgres psql -U $${POSTGRES_USER:-postgres} -d $${POSTGRES_DB:-unidorm}
# 进入 Redis
shell-redis:
docker compose exec redis redis-cli -a $${REDIS_PASSWORD}
# 更新(拉取最新代码并重启)
update:
git pull
docker compose pull
docker compose up -d
# 健康检查
health:
@echo "Service health:"
@docker compose ps
@echo ""
@echo "Backend /health:"
@curl -fsS http://localhost:8080/health || echo "Backend not responding"