91 lines
3.5 KiB
Markdown
91 lines
3.5 KiB
Markdown
# iAOP · FBA 基础设施部署(Epic #159 · Phase 0)
|
||
|
||
将 [fastapi-best-architecture](https://github.com/fastapi-practices/fastapi-best-architecture)
|
||
(下称 FBA)作为 iAOP 的统一认证 / 用户角色权限基座,以 Docker 方式与现有 iAOP
|
||
服务并行部署,由宿主机现有 nginx 以 `/fba/` 前缀统一反代。
|
||
|
||
## 架构位置
|
||
|
||
```
|
||
浏览器
|
||
│ http://39.101.182.167:8090
|
||
▼
|
||
宿主机 nginx(现有 iAOP 站点)
|
||
├── / → iAOP 前端(web/ 静态)
|
||
├── /api/v1/ → iAOP 后端(现有 FastAPI,业务接口)
|
||
└── /fba/ → 127.0.0.1:8001 → fba_server(FBA 后端,认证/RBAC)
|
||
├── fba_postgres(PG16)
|
||
└── fba_redis
|
||
```
|
||
|
||
> iAOP 自身也使用 `/api/v1` 前缀,因此 FBA 必须通过 `/fba/` 前缀隔离,
|
||
> 两者不能共用路径。
|
||
|
||
## 前置条件
|
||
|
||
1. 服务器已安装 Docker 与 Docker Compose 插件(`docker compose version` 可查)。
|
||
2. 获取 FBA 源码,放到本仓库同级目录:
|
||
|
||
```bash
|
||
cd /opt/apps # 假设 iAOP 在 /opt/apps/iAOP
|
||
git clone https://github.com/fastapi-practices/fastapi-best-architecture fba-backend
|
||
```
|
||
|
||
若放在其他位置,修改 `compose.env` 中的 `FBA_SRC`。
|
||
|
||
## 部署步骤
|
||
|
||
```bash
|
||
cd /opt/apps/iAOP/deploy/fba
|
||
|
||
# 1. 修改密钥与密码(生产必做)
|
||
# - compose.env: FBA_PG_PASSWORD
|
||
# - fba.env: DATABASE_PASSWORD(与上一致)、TOKEN_SECRET_KEY
|
||
python3 -c "import secrets; print(secrets.token_urlsafe(32))" # 生成 TOKEN_SECRET_KEY
|
||
|
||
# 2. 构建并启动
|
||
docker compose --env-file compose.env up -d --build
|
||
|
||
# 3. 初始化数据库表结构 + 内置数据(菜单/角色/管理员)
|
||
docker exec -it fba_server fba init
|
||
# 若 fba 命令不可用,改用:docker exec -it fba_server python backend/cli.py init
|
||
|
||
# 4. 验证服务
|
||
curl -s http://127.0.0.1:8001/api/v1/auth/captcha | head -c 200
|
||
|
||
# 5. 合并 nginx 片段(见 nginx-fba.conf 头部说明),然后 reload
|
||
nginx -t && nginx -s reload
|
||
|
||
# 6. 通过外部入口验证
|
||
curl -s http://39.101.182.167:8090/fba/api/v1/auth/captcha | head -c 200
|
||
```
|
||
|
||
FBA 默认管理员账号:`admin / 123456`(登录后请立即修改)。
|
||
|
||
## 常用运维命令
|
||
|
||
```bash
|
||
docker compose --env-file compose.env logs -f fba_server # 看日志
|
||
docker compose --env-file compose.env restart fba_server # 重启
|
||
docker compose --env-file compose.env down # 停止(数据保留在卷中)
|
||
docker exec -it fba_postgres psql -U postgres -d fba # 进数据库
|
||
```
|
||
|
||
## 与 iAOP 代码侧的关系(后续 Phase)
|
||
|
||
- **Phase 1**:iAOP 前端 `web/shared/session.js` 改为调用
|
||
`/fba/api/v1/auth/login`(JSON 登录)与 `/fba/api/v1/auth/codes`
|
||
(授权码)做登录与鉴权,现有 `core/auth` 退役。
|
||
- **Phase 2**:Sider 菜单由 FBA `sys_menu` 接口驱动,替代前端硬编码菜单。
|
||
- **Phase 3**:FBA UI(Vue3 + AntDV)构建时设置
|
||
`VITE_GLOB_API_URL=http://<域名>/fba`,产物由 nginx 挂在 `/fba-admin/`,
|
||
作为用户/角色/菜单管理界面。
|
||
|
||
## 注意事项
|
||
|
||
- `fba_postgres` / `fba_redis` 不映射宿主端口,仅容器网络内可达;
|
||
`fba_server` 仅绑定 `127.0.0.1:8001`。
|
||
- iAOP 现有数据(SQLite 业务库)与 FBA 的 PG 库完全独立,Phase 0 不迁移任何数据。
|
||
- FBA 源码目录(`fba-backend`)不属于本仓库,升级 FBA 时在
|
||
`fba-backend` 目录内 `git pull` 后重新 `--build` 即可。
|