You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iTi-Flask/docs/TESTING_DEPLOYMENT.md

79 lines
1.6 KiB
Markdown

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 测试与部署方案
本轮开发验证不依赖 Docker不依赖真实 MySQL。
真实 MySQL 和 Docker Compose 属于集成验证阶段。
## 本地轻量验证
```bash
cd <workspace>/iTi-Flask
uv run pytest -q
cd <workspace>/iTi-System
uv run pytest -q
cd <workspace>/my-business-app
uv run pytest -q
```
这些测试允许使用 SQLite 内存库,只验证框架行为、路由契约和模块组装。
## MySQL 集成验证
准备独立测试库:
```sql
CREATE DATABASE iti_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE DATABASE my_business_app_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```
执行:
```bash
export DATABASE_URL='mysql+pymysql://root:password@127.0.0.1:3306/iti_test?charset=utf8mb4'
uv run alembic upgrade head
uv run iti-system migrations sync --target migrations/versions
uv run iti-system seed system app:app
uv run uvicorn app:app --reload
```
验证:
```bash
curl http://127.0.0.1:8000/health
curl http://127.0.0.1:8000/ready
```
如启用 `ready_check_db=True``/ready` 会执行 `SELECT 1`
## Docker Compose 健康检查
服务容器可使用:
```yaml
healthcheck:
test: ["CMD", "curl", "-f", "http://127.0.0.1:8000/health"]
interval: 10s
timeout: 3s
retries: 3
```
依赖数据库就绪的服务可检查 `/ready`
## 生产运行
简单部署:
```bash
uv run uvicorn app:app --host 0.0.0.0 --port 8000
```
多 worker
```bash
uv run gunicorn app:app -k uvicorn.workers.UvicornWorker -w 4 -b 0.0.0.0:8000
```
`tasks_enabled=True` 时不要在多个 worker 同时启用调度。
轻量任务只保证单进程内正常运行。