Files
watchman/docs/runbook.md
T
unknownandCursor 8fb16f4a4a feat(infra): 落地 M01 基础框架与本机开发环境
交付 FastAPI/Celery/Vue 薄壳、FORCE RLS、Compose 回环与 review 修复证据,关闭 M01 DONE_LOCAL。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-17 15:00:39 +08:00

108 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Watchman 本地开发手册(M01)
## 前置
- Python 通过 `uv` 使用 3.12
- Node.js + pnpm 12
- Docker Desktop(RabbitMQ)
- 本机 PostgreSQL(默认);Compose 可选库见下文
## 安装
```powershell
uv sync --group dev
cd web
pnpm install
```
## 本机数据库(默认)
1. 确认 `.env.local` 存在且含密码与 `DATABASE_*_URL`(勿提交)。
2. 建库与角色:
```powershell
uv run python services/watchman/scripts/bootstrap_local_db.py
uv run --directory services/watchman alembic upgrade head
```
## RabbitMQ(Compose,仅本机回环)
```powershell
docker compose -f deploy/compose.dev.yml --env-file .env.local up -d rabbitmq
docker compose -f deploy/compose.dev.yml --env-file .env.local ps
```
管理台:`http://127.0.0.1:15679`(默认 guest/guest,仅开发)。
停止:
```powershell
docker compose -f deploy/compose.dev.yml --env-file .env.local stop rabbitmq
```
## 启动 API / worker / beat(宿主机)
```powershell
uv run python -m watchman api
uv run python -m watchman worker
uv run python -m watchman beat
```
健康检查:`http://127.0.0.1:8000/health`
Windows 上 worker 自动使用 `--pool=solo`。
## 启动控制台壳
```powershell
cd web
pnpm --filter @watchman/console dev
```
打开:`http://127.0.0.1:5173`
## Compose 应用进程(可选 profile)
`.env.local` 需提供 `DATABASE_URL_DOCKER` / `DATABASE_MIGRATOR_URL_DOCKER` / `CELERY_BROKER_URL_DOCKER`。
```powershell
docker compose -f deploy/compose.dev.yml --env-file .env.local --profile app up -d --build
```
可选隔离 Postgres(端口 `127.0.0.1:54329`):
```powershell
docker compose -f deploy/compose.dev.yml --env-file .env.local --profile compose-db up -d postgres
```
## 测试
```powershell
uv run pytest services/watchman/tests -q
cd web
pnpm --filter @watchman/console test:unit
pnpm --filter @watchman/console typecheck
pnpm --filter @watchman/console test:e2e
```
Playwright 截图写入 `docs/evidence/M01/ui/`(相对仓库根,勿再多上一级)。`/_probe/*` 与 `/docs` 仅在 `ENV_NAME=dev|test` 暴露。
`.env.dev` 可选;缺失时加载顺序会跳过该文件。租户 id 放在 `.env.local`(见 D16)。
## 端口(仅开发,全部绑 127.0.0.1)
| 服务 | 地址 |
|---|---|
| API | 127.0.0.1:8000 |
| Console | 127.0.0.1:5173 |
| Postgres(本机) | 127.0.0.1:5432 |
| Postgres(Compose 可选) | 127.0.0.1:54329 |
| RabbitMQ | 127.0.0.1:56729 |
| RabbitMQ 管理台 | 127.0.0.1:15679 |
## 当前已知限制
- 正式 Casdoor 登录在 M02。
- Compose `app` profile 依赖 Docker 构建;日常开发可用宿主机进程 + 仅 RabbitMQ 容器。
- 容器内 `API_HOST=0.0.0.0` 仅开发监听(D18);宿主端口仍绑 `127.0.0.1`。