docs: add t-403 deployment guide

This commit is contained in:
QiuSW
2026-07-03 17:53:49 +08:00
parent 3fdb25945b
commit 3a661afaa5
15 changed files with 436 additions and 25 deletions
+6 -1
View File
@@ -24,7 +24,7 @@
| 充值对接 | 自助扫码:微信 V3 native + 支付宝当面付;下单取二维码 + 服务端回调(验签 + 幂等) | 已定 | T-304/T-305 已落地回调、扫码下单、状态轮询、HMAC mock 联调与 SDK 模式入口;生产需安装并配置 `wechatpayv3` / `python-alipay-sdk` 与真实商户密钥/证书 |
| 生成返回方式 | 同步 HTTP(无任务队列) | 已定 | MVP 简化;图片接口需调大网关/服务超时 |
| 任务队列 | 暂不引入(Celery/RQ) | 待定 | V2 异步化时再评估 |
| 部署方式 | Docker + Gunicorn(gthread) + Nginx,单体 | 待定 | MVP 先 `runserver`;生产 Nginx 按路径把 `/api/generate/*`(图片长请求)与用户端页面**分流到不同 gunicorn/worker 池**,避免图片阻塞拖慢页面(见 `04-architecture.md` 5.1) |
| 部署方式 | VPS / 宝塔 + Nginx + Gunicorn(gthread) + systemd,Django 单体 | 已定(MVP) | 生产按 `deployment.md` 执行;Nginx 按路径把 `/api/v1/generate/*`(图片长请求)分流到独立 Gunicorn 池,用户端 / admin / 余额 / 充值走普通池;`/static/` 托管 `STATIC_ROOT`,`/media/` 托管本地媒体或后续换对象存储;DRF 限流生产必须使用共享 Django cache |
| 测试 | Django 自带 `manage.py test`(unittest)/ 可选 pytest-django | 已定 | 先用内置 test runner,重点覆盖计费与回调;涉及 `select_for_update` 的并发扣点测试必须在 MySQL 上跑,SQLite 会忽略行锁导致假绿 |
| 依赖管理 | 系统 Python 3.12 + pip + `requirements.txt` + `pyproject.toml` | 已定 | 不使用虚拟环境;Windows 用 `py -3.12`,Unix/WSL 用 `python3.12`;运行依赖仍由 `requirements.txt` 管理,`pyproject.toml` 只落地 `requires-python` 元数据;init 会显式校验解释器版本在 `>=3.12,<3.14` |
@@ -51,12 +51,17 @@
| --- | --- |
| 安装依赖(Windows) | `py -3.12 -m pip install -r requirements.txt` |
| 安装依赖(Unix/WSL) | `python3.12 -m pip install -r requirements.txt` |
| 安装生产依赖(Linux) | `python3.12 -m pip install -r requirements-production.txt` |
| 基础检查(Windows) | `py -3.12 manage.py check` |
| 基础检查(Unix/WSL) | `python3.12 manage.py check` |
| 测试(Windows) | `py -3.12 manage.py test` |
| 本地开发(Windows) | `py -3.12 manage.py runserver` |
| 创建后台管理员 | T-003 后执行 `py -3.12 manage.py createsuperuser` |
| 数据库迁移 | T-002 接入 MySQL 后执行 `makemigrations` / `migrate` |
| 生产静态文件收集 | `python3.12 manage.py collectstatic --noinput` |
| 生产共享 cache 表 | `python3.12 manage.py createcachetable cmhub_cache` |
| 生产 Gunicorn 普通池 | `gunicorn config.wsgi:application --bind 127.0.0.1:8001 --workers 2 --worker-class gthread --threads 4 --timeout 120` |
| 生产 Gunicorn 生成池 | `gunicorn config.wsgi:application --bind 127.0.0.1:8002 --workers 1 --worker-class gthread --threads 4 --timeout 360` |
| 导入 cmbot AI 模型配置 | `py -3.12 manage.py import_ai_models path\to\ai_models.json --create-default-aliases` |
| AI 生成 smoke(录制标题) | `py -3.12 manage.py smoke_ai_generation title --recorded` |
| AI 生成 smoke(录制图片) | `py -3.12 manage.py smoke_ai_generation image --recorded` |