本地部署:顶层 docker-compose/config,域名 agent.ai.foresh.com(nginx-proxy VIRTUAL_HOST + external my-app-network,仅内网 expose 8080,config 只读挂载);配置后缀统一 .yaml→.yml(文件与全部引用,含 Dockerfile/AGENT_CONFIG/config.js/smoke)。smoke 25/25 通过
This commit is contained in:
+2
-1
@@ -2,7 +2,8 @@
|
||||
/zed_agent/
|
||||
node_modules/
|
||||
app/test/tmp/
|
||||
app/config.yaml
|
||||
app/config.yml
|
||||
/config.yml
|
||||
app/data/
|
||||
data/
|
||||
*.log
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
### 2.1 模型池配置
|
||||
|
||||
配置文件(如 `config.yaml`)中定义模型列表:
|
||||
配置文件(如 `config.yml`)中定义模型列表:
|
||||
|
||||
```yaml
|
||||
models:
|
||||
@@ -954,25 +954,35 @@ function runAgent(session):
|
||||
|
||||
## 十三、Docker 部署
|
||||
|
||||
### 13.1 Docker Compose 示例
|
||||
### 13.1 Docker Compose(顶层 `docker-compose.yml`)
|
||||
|
||||
```yaml
|
||||
services:
|
||||
agent:
|
||||
build: .
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ./data:/workspace/tasks
|
||||
- ./config.yaml:/app/config.yaml
|
||||
environment:
|
||||
- AGENT_CONFIG=/app/config.yaml
|
||||
build: ./app
|
||||
restart: unless-stopped
|
||||
expose:
|
||||
- "8080" # 仅内网暴露,由 nginx-proxy 对外
|
||||
volumes:
|
||||
- ./data:/workspace/tasks # 持久化:任务目录 + SQLite
|
||||
- ./config.yml:/app/config.yml:ro
|
||||
environment:
|
||||
- PORT=8080
|
||||
- AGENT_CONFIG=/app/config.yml
|
||||
- VIRTUAL_HOST=agent.ai.foresh.com
|
||||
- VIRTUAL_PORT=8080
|
||||
- CERT_NAME=default
|
||||
networks:
|
||||
- my-app-network
|
||||
|
||||
networks:
|
||||
my-app-network:
|
||||
external: true
|
||||
```
|
||||
|
||||
### 13.2 nginx-proxy basic auth
|
||||
### 13.2 nginx-proxy 对外暴露
|
||||
|
||||
前置 nginx-proxy,配置 basic auth,多个用户共享同一认证,不做任务隔离。
|
||||
前置的 nginx-proxy 需与业务容器共用外部网络 `my-app-network`。compose 通过 `VIRTUAL_HOST`/`VIRTUAL_PORT`/`CERT_NAME` 接入;域名 `agent.ai.foresh.com` 的 DNS 指向 nginx-proxy 所在宿主机。多个用户共享同一认证,不做任务隔离;SSE 需关代理缓冲(`proxy_buffering off`),见 `docs/DEPLOY.md`。
|
||||
|
||||
---
|
||||
|
||||
|
||||
+2
-2
@@ -11,9 +11,9 @@ COPY package.json package-lock.json ./
|
||||
RUN npm install --omit=dev --no-audit --no-fund
|
||||
|
||||
COPY server ./server
|
||||
COPY config.example.yaml ./
|
||||
COPY config.example.yml ./
|
||||
|
||||
EXPOSE 8080
|
||||
ENV AGENT_CONFIG=/app/config.yaml
|
||||
ENV AGENT_CONFIG=/app/config.yml
|
||||
|
||||
CMD ["node", "server/server.js"]
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@
|
||||
app/
|
||||
├── server/
|
||||
│ ├── server.js # 入口:装配配置/DB/总线/路由/静态资源
|
||||
│ ├── config.js # config.yaml 加载与校验
|
||||
│ ├── config.js # config.yml 加载与校验
|
||||
│ ├── db.js # SQLite(better-sqlite3,WAL)
|
||||
│ ├── engine.js # 会话管理 + 模型池 FIFO 调度 + Agent 主循环
|
||||
│ ├── llm.js # OpenAI 兼容上游流式调用(SSE 解析/工具分片合并)
|
||||
@@ -24,7 +24,7 @@ app/
|
||||
│ └── public/ # H5 前端(Vanilla JS + SSE)
|
||||
├── test/ # mock 上游 + 端到端冒烟测试
|
||||
├── scripts(在上层仓库根目录)gen-from-readme.js # README → 提示词/工具 schema
|
||||
├── config.example.yaml
|
||||
├── config.example.yml
|
||||
├── Dockerfile / docker-compose.yml
|
||||
```
|
||||
|
||||
@@ -33,7 +33,7 @@ app/
|
||||
```bash
|
||||
cd app
|
||||
npm install
|
||||
cp config.example.yaml config.yaml # 修改 upstream_url / models
|
||||
cp config.example.yml config.yml # 修改 upstream_url / models
|
||||
npm start # http://localhost:8080
|
||||
```
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 自用通用 Agent 系统配置示例
|
||||
# 复制为 config.yaml 后按需修改;容器内通过 AGENT_CONFIG 指定路径。
|
||||
# 复制为 config.yml 后按需修改;容器内通过 AGENT_CONFIG 指定路径。
|
||||
|
||||
# 模型池:多个 ID 共用同一个上游 URL(cli-proxy-api 按 ID 路由到不同账号)。
|
||||
# 同时活跃会话数上限 = 模型数量。
|
||||
@@ -1,11 +0,0 @@
|
||||
services:
|
||||
agent:
|
||||
build: .
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ./data:/workspace/tasks
|
||||
- ./config.yaml:/app/config.yaml:ro
|
||||
environment:
|
||||
- AGENT_CONFIG=/app/config.yaml
|
||||
restart: unless-stopped
|
||||
@@ -1,4 +1,4 @@
|
||||
// 配置加载:AGENT_CONFIG 指向 config.yaml(见 config.example.yaml)
|
||||
// 配置加载:AGENT_CONFIG 指向 config.yml(见 config.example.yml)
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const YAML = require('yaml');
|
||||
@@ -33,7 +33,7 @@ function deepMerge(base, extra) {
|
||||
}
|
||||
|
||||
function loadConfig(configPath) {
|
||||
const p = configPath || process.env.AGENT_CONFIG || path.join(__dirname, '..', 'config.yaml');
|
||||
const p = configPath || process.env.AGENT_CONFIG || path.join(__dirname, '..', 'config.yml');
|
||||
let raw = {};
|
||||
if (fs.existsSync(p)) {
|
||||
raw = YAML.parse(fs.readFileSync(p, 'utf8')) || {};
|
||||
|
||||
@@ -619,7 +619,7 @@ function strip(s) { return s.replace(/<[^>]+>/g, ''); }
|
||||
// web_search:调用内网 MCP 服务(JSON-RPC over HTTP,无状态,响应为 SSE 帧包裹的 JSON)。
|
||||
async function toolWebSearch(ctx, args) {
|
||||
const ws = ctx.cfg.web_search || {};
|
||||
if (!ws.url) return 'web_search 未配置:请在 config.yaml 的 web_search.url 中填写 MCP 服务地址';
|
||||
if (!ws.url) return 'web_search 未配置:请在 config.yml 的 web_search.url 中填写 MCP 服务地址';
|
||||
const query = args.query;
|
||||
if (!query) return 'web_search 缺少参数 query';
|
||||
const callId = Date.now();
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ async function main() {
|
||||
const mock = spawn('node', [path.join(ROOT, 'test/mock-upstream.js')], { stdio: 'inherit' });
|
||||
const server = spawn('node', [path.join(ROOT, 'server/server.js')], {
|
||||
cwd: ROOT,
|
||||
env: Object.assign({}, process.env, { AGENT_CONFIG: path.join(ROOT, 'test/config.test.yaml') }),
|
||||
env: Object.assign({}, process.env, { AGENT_CONFIG: path.join(ROOT, 'test/config.test.yml') }),
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
let serverLog = '';
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
services:
|
||||
agent:
|
||||
build: ./app
|
||||
restart: unless-stopped
|
||||
expose:
|
||||
- "8080" # 仅内网暴露,由 nginx-proxy 对外
|
||||
volumes:
|
||||
- ./data:/workspace/tasks # 持久化:任务目录 + SQLite(.agent.db 在此目录内)
|
||||
- ./config.yml:/app/config.yml:ro
|
||||
environment:
|
||||
- PORT=8080
|
||||
- AGENT_CONFIG=/app/config.yml
|
||||
- VIRTUAL_HOST=agent.ai.foresh.com
|
||||
- VIRTUAL_PORT=8080
|
||||
- CERT_NAME=default
|
||||
networks:
|
||||
- my-app-network
|
||||
|
||||
networks:
|
||||
my-app-network:
|
||||
external: true
|
||||
+37
-52
@@ -1,74 +1,59 @@
|
||||
# 部署说明(Docker + nginx-proxy basic auth)
|
||||
# 部署说明(Docker + nginx-proxy,域名 agent.ai.foresh.com)
|
||||
|
||||
配置与编排文件都放在**仓库顶层**,方便直接调整:
|
||||
|
||||
| 宿主机路径 | 容器内路径 | 说明 |
|
||||
|---|---|---|
|
||||
| `./docker-compose.yml` | — | 编排(构建 `./app`,仅内网 expose 8080) |
|
||||
| `./config.yml` | `/app/config.yml` | 运行配置(AGENT_CONFIG 指向它;含密钥,已被 .gitignore 忽略) |
|
||||
| `./data/` | `/workspace/tasks` | 任务目录 + SQLite(`.agent.db` 在此目录内) |
|
||||
|
||||
## 1. 准备配置
|
||||
|
||||
```bash
|
||||
cd app
|
||||
cp config.example.yaml config.yaml
|
||||
vi config.yaml # 至少改 upstream_url 与 models
|
||||
cp app/config.example.yml config.yml
|
||||
vi config.yml # 至少改 upstream_url 与 models
|
||||
```
|
||||
|
||||
容器内运行时约定(docker-compose.yml 已按此挂载):
|
||||
|
||||
| 宿主机路径 | 容器内路径 | 说明 |
|
||||
|---|---|---|
|
||||
| `./config.yaml` | `/app/config.yaml` | 运行配置(AGENT_CONFIG 指向它) |
|
||||
| `./data/` | `/workspace/tasks` | 任务目录 + SQLite(`.agent.db` 在此目录内) |
|
||||
|
||||
> 注意:容器内运行时 `workspace_root` 请写 `/workspace/tasks`(宿主机直接运行则用默认 `./data/tasks` 即可)。
|
||||
> 容器内运行时 `workspace_root` 写 `/workspace/tasks`(docker-compose.yml 已把 `./data` 挂到这里)。
|
||||
> 本仓库 git 只跟踪示例 `app/config.example.yml`,真正的 `config.yml` 在顶层且被忽略,密钥不会进库。
|
||||
|
||||
## 2. 构建并启动
|
||||
|
||||
```bash
|
||||
cd app
|
||||
# 在仓库顶层(含 docker-compose.yml 的位置)执行
|
||||
docker compose up -d --build
|
||||
docker compose logs -f # 看到 "Agent server listening on 8080" 即成功
|
||||
docker compose logs -f # 看到 "Agent server listening on 8080" 即成功
|
||||
```
|
||||
|
||||
## 3. nginx-proxy + basic auth
|
||||
## 3. nginx-proxy 对外暴露(agent.ai.foresh.com)
|
||||
|
||||
多用户共享一套认证,不做任务隔离(见 README 8.1)。
|
||||
compose 已通过 `VIRTUAL_HOST` / `VIRTUAL_PORT` / `CERT_NAME` 接入 nginx-proxy:
|
||||
|
||||
生成密码文件(需 apache2-utils 提供的 htpasswd):
|
||||
|
||||
```bash
|
||||
apt-get install apache2-utils # 或任何能生成 htpasswd 的方式
|
||||
htpasswd -c ./deploy/.htpasswd admin
|
||||
htpasswd ./deploy/.htpasswd user2
|
||||
```
|
||||
|
||||
nginx 站点配置:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name agent.example.com;
|
||||
|
||||
location / {
|
||||
auth_basic "Agent";
|
||||
auth_basic_user_file /etc/nginx/.htpasswd;
|
||||
|
||||
proxy_pass http://agent:8080;
|
||||
proxy_http_version 1.1;
|
||||
proxy_buffering off; # SSE 必须关缓冲
|
||||
proxy_read_timeout 3600s; # 长连接不被掐断
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> SSE 关键点:`proxy_buffering off`,否则流式输出会被 nginx 攒着不发。
|
||||
|
||||
若不想用 nginx,也可直接启用内置认证:在 `config.yaml` 里配置
|
||||
`auth: {user: admin, password: ...}`(仅适合纯内网测试;上游仍建议 nginx TLS)。
|
||||
- 前置的 nginx-proxy 容器必须与业务容器共用同一个外部网络 `my-app-network`(compose 声明为 external),并监听 80/443。
|
||||
- 域名 `agent.ai.foresh.com` 的 DNS 指向 nginx-proxy 所在宿主机。
|
||||
- 若你的 nginx-proxy 未默认关闭代理缓冲,需额外配置 `proxy_buffering off`——**SSE 必须关缓冲**,否则流式输出会被攒住不发。可给 nginx-proxy 挂一个自定义 conf:
|
||||
```
|
||||
server {
|
||||
listen 80;
|
||||
server_name agent.ai.foresh.com;
|
||||
location / {
|
||||
proxy_pass http://agent:8080;
|
||||
proxy_http_version 1.1;
|
||||
proxy_buffering off; # SSE 关键
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
}
|
||||
```
|
||||
- 认证交给 nginx-proxy(htpasswd)或在此 config 里启用内置 `auth`(见 config.example.yml 注释),二选一即可。
|
||||
|
||||
## 4. 升级流程
|
||||
|
||||
```bash
|
||||
git pull
|
||||
cd app && docker compose up -d --build
|
||||
docker compose up -d --build # 仓库顶层执行
|
||||
```
|
||||
|
||||
数据库与任务目录都在 volume 内,升级不丢数据。进程重启时,原 active 会话
|
||||
会自动退回排队队列,待模型空闲后继续。
|
||||
数据库与任务目录都在 volume 内,升级不丢数据。进程重启时,原 active 会话会自动退回排队队列,待模型空闲后继续。
|
||||
Reference in New Issue
Block a user