diff --git a/.gitignore b/.gitignore index 59b22a7..86bebfa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ prototype/node_modules/ prototype/dist/ +infra/otari/.env +infra/otari/config.yml +infra/otari/service_account.json diff --git a/README.md b/README.md index f29f835..be713c3 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,8 @@ MaaS 模型服务与应用开发 阶段 2 的可交互 Vue 原型位于 `prototype/`,包含用户控制台、模型广场、Playground、API Key、任务中心、用量与账单、接入文档和运营后台。 +Otari 本地网关基座位于 `infra/otari/`,仅用于后续联调和开发环境,不包含真实供应商密钥。 + ```bash cd prototype pnpm install diff --git a/docs/04-open-source-baseline-and-development-nodes.md b/docs/04-open-source-baseline-and-development-nodes.md index 25a3884..71298d6 100644 --- a/docs/04-open-source-baseline-and-development-nodes.md +++ b/docs/04-open-source-baseline-and-development-nodes.md @@ -112,7 +112,7 @@ POST /v1/tasks |---|---|---|---| | D0 原型基线 | 固化品牌、用户端、管理端和认证流程 | Vue 可交互原型 | 已完成,提交 `bebff16` | | D1 网关适配契约 | 固化开源边界和前端网关接口 | 本文档、类型化 Gateway Client、演示适配器 | 类型检查和前端构建通过 | -| D2 Otari 本地基座 | 运行锁定版本的 Otari 与持久化数据库 | Compose、环境模板、健康检查、许可证清单 | 重启后配置和用量可持久化 | +| D2 Otari 本地基座 | 运行锁定版本的 Otari 与持久化数据库 | Compose、环境模板、健康检查、启动说明 | 重启后配置和用量可持久化 | | D3 身份与权限 | 实现邀请码、登录、会话、角色与管理端守卫 | Control Plane 认证 API、数据库迁移、前端真实登录 | 普通用户无法访问管理 API | | D4 密钥与模型目录 | 打通 MOYI Key、网关 Key、模型目录和权限 | Key API、模型 Schema、Otari 映射、管理页面 | 创建 Key 后可完成一次真实调用 | | D5 调用与计量 | 打通同步、流式、用量事件和额度账本 | 代理链路、SSE、幂等计量、用量页面 | 调用量与额度变更可追溯且不重复扣减 | diff --git a/infra/otari/.env.example b/infra/otari/.env.example new file mode 100644 index 0000000..9c739ee --- /dev/null +++ b/infra/otari/.env.example @@ -0,0 +1,11 @@ +OTARI_IMAGE=mzdotai/otari:v0.4.0 +OTARI_PORT=8000 +OTARI_SECRET_KEY=replace-with-a-long-random-secret + +POSTGRES_PORT=5433 +POSTGRES_USER=otari +POSTGRES_PASSWORD=replace-with-a-long-random-password +POSTGRES_DB=otari + +OPENAI_API_KEY= +ANTHROPIC_API_KEY= diff --git a/infra/otari/README.md b/infra/otari/README.md new file mode 100644 index 0000000..d397599 --- /dev/null +++ b/infra/otari/README.md @@ -0,0 +1,57 @@ +# Otari 本地基座 + +这是 D2 的本地开发基座,使用 Otari `v0.4.0` 和 PostgreSQL。它只负责为后续 MOYI 控制面提供可复现的网关与用量基础,不替代 MOYI 用户端或管理端。 + +## 目录 + +- `docker-compose.yml`:Otari 与 PostgreSQL 服务、持久化卷和健康检查。 +- `config.yml.example`:本地网关配置模板。 +- `.env.example`:端口、数据库和密钥变量模板。 +- `service_account.json.example`:Vertex AI 配置占位文件,不包含真实凭证。 + +## 启动 + +PowerShell: + +```powershell +cd infra/otari +Copy-Item .env.example .env +Copy-Item config.yml.example config.yml +Copy-Item service_account.json.example service_account.json +``` + +编辑 `.env` 和 `config.yml`,至少替换: + +- `OTARI_SECRET_KEY` +- `POSTGRES_PASSWORD` +- `master_key` +- 一个真实供应商 Key,或先保持空值只启动管理界面 + +启动服务: + +```powershell +docker compose up -d +docker compose ps +Invoke-WebRequest http://localhost:8000/health +``` + +预期健康响应:`{"status":"healthy"}`。首次启动后打开 `http://localhost:8000/`,使用 `master_key` 进入 Otari 管理界面。 + +## 停止与数据 + +```powershell +docker compose down +``` + +不要使用 `docker compose down -v`,除非明确要删除本地数据库。PostgreSQL 数据保存在 Docker 卷 `moyi-otari_otari_postgres_data` 中。 + +## 安全边界 + +- `.env`、`config.yml` 和 `service_account.json` 不提交到 Git。 +- `master_key` 用于网关管理接口,不能作为普通用户调用 Key。 +- 供应商 Key 只通过本地环境变量或 Otari 管理界面配置。 +- 生产部署必须固定镜像 digest,并重新审计 Otari 及其依赖许可证。 + +## 版本依据 + +本节点按 Otari `v0.4.0` 的官方发布说明和官方 Compose/config 示例建立。正式联调前仍需用固定 digest 验证镜像内容和 API 行为。 diff --git a/infra/otari/config.yml.example b/infra/otari/config.yml.example new file mode 100644 index 0000000..3d3eefa --- /dev/null +++ b/infra/otari/config.yml.example @@ -0,0 +1,13 @@ +database_url: "postgresql://otari:change-me@postgres:5432/otari" +host: "0.0.0.0" +port: 8000 +master_key: "change-me-in-local-config" +enable_metrics: true + +providers: + openai: + api_key: "" + api_base: "https://api.openai.com/v1" + +model_discovery: false +aliases: {} diff --git a/infra/otari/docker-compose.yml b/infra/otari/docker-compose.yml new file mode 100644 index 0000000..a2962b1 --- /dev/null +++ b/infra/otari/docker-compose.yml @@ -0,0 +1,46 @@ +name: moyi-otari + +services: + otari: + image: ${OTARI_IMAGE:-mzdotai/otari:v0.4.0} + restart: unless-stopped + ports: + - "${OTARI_PORT:-8000}:8000" + volumes: + - ./config.yml:/app/config.yml:ro + - ./service_account.json:/app/service_account.json:ro + environment: + OTARI_CONFIG_PATH: /app/config.yml + OTARI_SECRET_KEY: ${OTARI_SECRET_KEY:?Set OTARI_SECRET_KEY in infra/otari/.env} + OPENAI_API_KEY: ${OPENAI_API_KEY:-} + ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-} + command: ["otari", "serve", "--config", "/app/config.yml"] + depends_on: + postgres: + condition: service_healthy + healthcheck: + test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 15s + + postgres: + image: postgres:16-alpine + restart: unless-stopped + ports: + - "${POSTGRES_PORT:-5433}:5432" + environment: + POSTGRES_USER: ${POSTGRES_USER:-otari} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in infra/otari/.env} + POSTGRES_DB: ${POSTGRES_DB:-otari} + volumes: + - otari_postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] + interval: 10s + timeout: 5s + retries: 10 + +volumes: + otari_postgres_data: diff --git a/infra/otari/service_account.json.example b/infra/otari/service_account.json.example new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/infra/otari/service_account.json.example @@ -0,0 +1 @@ +{}