Skip to content

Commit 38e389c

Browse files
committed
feat(deployment): 添加生产环境部署配置和文档
新增 docker-compose.prod.yml 生产环境配置 添加生产部署指南文档 更新 .gitignore 忽略 .env.prod 文件 优化 nginx 配置保持 /api/ 前缀 升级 Python 基础镜像到 3.12 添加 nginx 镜像到 Makefile 使用国内镜像源加速 pnpm 安装
1 parent 9410313 commit 38e389c

File tree

9 files changed

+321
-34
lines changed

9 files changed

+321
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ node_modules
1111
### common gitignore
1212
.DS_Store
1313
.env
14+
.env.prod
1415
.env.test
1516
.env.local
1617
.env.*.local

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pull:
1212
bash docker/pull_image.sh neo4j:5.26
1313
bash docker/pull_image.sh minio/minio:RELEASE.2023-03-20T20-16-18Z
1414
bash docker/pull_image.sh ghcr.io/astral-sh/uv:0.7.2
15+
bash docker/pull_image.sh nginx:alpine
1516

1617
start:
1718
@if [ ! -f .env ]; then \

docker-compose.prod.yml

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
services:
2+
api:
3+
build:
4+
context: .
5+
dockerfile: docker/api.Dockerfile
6+
image: yuxi-api:0.4.prod
7+
container_name: api-prod
8+
working_dir: /app
9+
networks:
10+
- app-network
11+
volumes:
12+
- ./saves:/app/saves
13+
extra_hosts:
14+
- "host.docker.internal:host-gateway"
15+
env_file:
16+
- .env.prod
17+
environment:
18+
- HOST_IP=${HOST_IP:-}
19+
- NEO4J_URI=${NEO4J_URI:-bolt://graph:7687}
20+
- NEO4J_USERNAME=${NEO4J_USERNAME:-neo4j}
21+
- NEO4J_PASSWORD=${NEO4J_PASSWORD:-0123456789}
22+
- MILVUS_URI=${MILVUS_URI:-http://milvus:19530}
23+
- MILVUS_TOKEN=${MILVUS_TOKEN:-}
24+
- MINERU_OCR_URI=${MINERU_OCR_URI:-http://mineru:30000}
25+
- PADDLEX_URI=${PADDLEX_URI:-http://paddlex:8080}
26+
- MINIO_URI=${MINIO_URI:-http://milvus-minio:9000}
27+
- MODEL_DIR_IN_DOCKER=/models
28+
- RUNNING_IN_DOCKER=true
29+
- NO_PROXY=localhost,127.0.0.1,milvus,graph,milvus-minio,milvus-etcd,etcd,minio,mineru,paddlex,api.siliconflow.cn
30+
- no_proxy=localhost,127.0.0.1,milvus,graph,milvus-minio,milvus-etcd,etcd,minio,mineru,paddlex,api.siliconflow.cn
31+
command: uv run --no-dev uvicorn server.main:app --host 0.0.0.0 --port 5050
32+
restart: unless-stopped
33+
healthcheck:
34+
test: ["CMD-SHELL", "curl -f http://localhost:5050/api/system/health || exit 1"]
35+
interval: 30s
36+
timeout: 15s
37+
retries: 8
38+
start_period: 180s
39+
depends_on:
40+
milvus:
41+
condition: service_healthy
42+
minio:
43+
condition: service_healthy
44+
45+
web:
46+
build:
47+
context: .
48+
dockerfile: docker/web.Dockerfile
49+
target: production
50+
image: yuxi-web:0.4.prod
51+
container_name: web-prod
52+
ports:
53+
- "80:80"
54+
depends_on:
55+
- api
56+
networks:
57+
- app-network
58+
environment:
59+
- NODE_ENV=production
60+
- VITE_API_URL=http://api:5050
61+
command: nginx -g "daemon off;"
62+
restart: unless-stopped
63+
64+
graph:
65+
image: neo4j:5.26
66+
container_name: graph
67+
volumes:
68+
- ./docker/volumes/neo4j/data:/data
69+
- ./docker/volumes/neo4j/logs:/var/lib/neo4j/logs
70+
healthcheck:
71+
test: ["CMD-SHELL", "curl -f http://localhost:7474 || exit 1"]
72+
interval: 20s
73+
timeout: 10s
74+
retries: 5
75+
start_period: 30s
76+
environment:
77+
- NEO4J_AUTH=${NEO4J_USERNAME:-neo4j}/${NEO4J_PASSWORD:-0123456789}
78+
- NEO4J_server_bolt_listen__address=0.0.0.0:7687
79+
- NEO4J_server_http_listen__address=0.0.0.0:7474
80+
- ENTITY_EMBEDDING=true
81+
networks:
82+
- app-network
83+
restart: unless-stopped
84+
85+
etcd:
86+
container_name: milvus-etcd
87+
image: quay.io/coreos/etcd:v3.5.5
88+
environment:
89+
- ETCD_AUTO_COMPACTION_MODE=revision
90+
- ETCD_AUTO_COMPACTION_RETENTION=1000
91+
- ETCD_QUOTA_BACKEND_BYTES=4294967296
92+
- ETCD_SNAPSHOT_COUNT=50000
93+
volumes:
94+
- ./docker/volumes/milvus/etcd:/etcd
95+
command: etcd -advertise-client-urls=http://etcd:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd
96+
healthcheck:
97+
test: ["CMD", "etcdctl", "endpoint", "health"]
98+
interval: 60s
99+
timeout: 30s
100+
retries: 5
101+
start_period: 30s
102+
networks:
103+
- app-network
104+
restart: unless-stopped
105+
106+
minio:
107+
container_name: milvus-minio
108+
image: minio/minio:RELEASE.2023-03-20T20-16-18Z
109+
environment:
110+
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY:-minioadmin}
111+
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY:-minioadmin}
112+
volumes:
113+
- ./docker/volumes/milvus/minio:/minio_data
114+
- ./docker/volumes/milvus/minio_config:/root/.minio
115+
command: minio server /minio_data --address 0.0.0.0:9000 --console-address 0.0.0.0:9001
116+
healthcheck:
117+
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
118+
interval: 60s
119+
timeout: 30s
120+
retries: 5
121+
start_period: 30s
122+
networks:
123+
- app-network
124+
restart: unless-stopped
125+
126+
milvus:
127+
image: milvusdb/milvus:v2.5.6
128+
container_name: milvus
129+
command: ["milvus", "run", "standalone"]
130+
security_opt:
131+
- seccomp:unconfined
132+
environment:
133+
ETCD_ENDPOINTS: etcd:2379
134+
MINIO_ADDRESS: minio:9000
135+
MILVUS_LOG_LEVEL: error
136+
volumes:
137+
- ./docker/volumes/milvus/milvus:/var/lib/milvus
138+
- ./docker/volumes/milvus/logs:/var/lib/milvus/logs
139+
healthcheck:
140+
test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"]
141+
interval: 60s
142+
start_period: 120s
143+
timeout: 30s
144+
retries: 5
145+
depends_on:
146+
- "etcd"
147+
- "minio"
148+
networks:
149+
- app-network
150+
restart: unless-stopped
151+
152+
mineru-vllm-server:
153+
build:
154+
context: .
155+
dockerfile: docker/mineru.Dockerfile
156+
image: mineru-vllm:latest
157+
container_name: mineru
158+
profiles:
159+
- all
160+
env_file:
161+
- .env
162+
environment:
163+
MINERU_MODEL_SOURCE: local
164+
entrypoint: mineru-vllm-server
165+
command:
166+
--host 0.0.0.0
167+
--port 30000
168+
ulimits:
169+
memlock: -1
170+
stack: 67108864
171+
ipc: host
172+
healthcheck:
173+
test: ["CMD-SHELL", "curl -f http://localhost:30000/health || exit 1"]
174+
deploy:
175+
resources:
176+
reservations:
177+
devices:
178+
- driver: nvidia
179+
device_ids: ["0"]
180+
capabilities: [gpu]
181+
networks:
182+
- app-network
183+
restart: unless-stopped
184+
185+
mineru-api:
186+
build:
187+
context: .
188+
dockerfile: docker/mineru.Dockerfile
189+
image: mineru-vllm:latest
190+
container_name: mineru-api
191+
profiles:
192+
- all
193+
env_file:
194+
- .env
195+
environment:
196+
MINERU_MODEL_SOURCE: local
197+
entrypoint: mineru-api
198+
command:
199+
--host 0.0.0.0
200+
--port 30001
201+
ulimits:
202+
memlock: -1
203+
stack: 67108864
204+
ipc: host
205+
deploy:
206+
resources:
207+
reservations:
208+
devices:
209+
- driver: nvidia
210+
device_ids: [ "0" ]
211+
capabilities: [ gpu ]
212+
restart: unless-stopped
213+
214+
paddlex:
215+
build:
216+
context: .
217+
dockerfile: docker/paddlex.Dockerfile
218+
image: paddlex:latest
219+
container_name: paddlex-ocr
220+
profiles:
221+
- all
222+
volumes:
223+
- ./docker/volumes/paddlex:/paddlex
224+
healthcheck:
225+
test: ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"]
226+
interval: 20s
227+
timeout: 10s
228+
retries: 5
229+
start_period: 60s
230+
deploy:
231+
resources:
232+
reservations:
233+
devices:
234+
- driver: nvidia
235+
device_ids: ['0']
236+
capabilities: [gpu]
237+
networks:
238+
- app-network
239+
restart: unless-stopped
240+
241+
networks:
242+
app-network:
243+
driver: bridge

docker-compose.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -81,34 +81,6 @@ services:
8181
command: pnpm run server
8282
restart: unless-stopped
8383

84-
# PostgreSQL 服务 - 基于官方推荐的 shangor/postgres-for-rag 镜像
85-
# 提供 KV store, VectorDB (pgvector) 和 GraphDB (Apache AGE) 功能
86-
# postgres:
87-
# image: shangor/postgres-for-rag:v1.0
88-
# container_name: postgres-lightrag
89-
# environment:
90-
# - POSTGRES_DATABASE=${POSTGRES_DATABASE:-lightrag}
91-
# - POSTGRES_USER=${POSTGRES_USER:-lightrag}
92-
# - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-lightrag}
93-
# - POSTGRES_HOST_AUTH_METHOD=md5
94-
# # 启用必要的扩展
95-
# - POSTGRES_INITDB_ARGS=--auth-host=md5
96-
# volumes:
97-
# - ./docker/volumes/postgres/data:/var/lib/postgresql/data
98-
# - ./docker/init-postgres.sh:/init-postgres.sh
99-
# ports:
100-
# - "5432:5432"
101-
# healthcheck:
102-
# test: ["CMD-SHELL", "PGPASSWORD=${POSTGRES_PASSWORD:-lightrag} psql -h localhost -U ${POSTGRES_USER:-lightrag} -d ${POSTGRES_DATABASE:-lightrag} -c \"SELECT ag_catalog.create_graph('test_ready');\" || PGPASSWORD=${POSTGRES_PASSWORD:-lightrag} psql -h localhost -U ${POSTGRES_USER:-lightrag} -d ${POSTGRES_DATABASE:-lightrag} -c 'SELECT 1'"]
103-
# interval: 30s
104-
# timeout: 15s
105-
# retries: 15
106-
# start_period: 120s
107-
# networks:
108-
# - app-network
109-
# restart: unless-stopped
110-
# command: ["bash", "/init-postgres.sh"]
111-
11284
# region neo4j
11385
graph:
11486
image: neo4j:5.26

docker/nginx/default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ server {
1111
}
1212

1313
location /api/ {
14-
proxy_pass http://api:5050/;
14+
proxy_pass http://api:5050/api/; # 保持 /api/ 前缀
1515
proxy_set_header Host $host;
1616
proxy_set_header X-Real-IP $remote_addr;
1717
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

docker/web.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ COPY ./web/package*.json ./
4141
COPY ./web/pnpm-lock.yaml* ./
4242

4343
# 安装依赖
44-
RUN pnpm install --frozen-lockfile
44+
RUN pnpm install --frozen-lockfile --registry=https://registry.npmmirror.com
4545

4646
# 复制源代码并构建
4747
COPY ./web .

docs/.vitepress/config.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export default defineConfig({
4444
{ text: '文档解析', link: '/latest/advanced/document-processing' },
4545
{ text: '智能体', link: '/latest/advanced/agents-config' },
4646
{ text: '品牌自定义', link: '/latest/advanced/branding' },
47-
{ text: '其他配置', link: '/latest/advanced/misc' }
47+
{ text: '其他配置', link: '/latest/advanced/misc' },
48+
{ text: '生产部署', link: '/latest/advanced/deployment' }
4849
]
4950
},
5051
{

docs/latest/advanced/deployment.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# 生产部署指南
2+
3+
本指南介绍了如何在生产环境中部署 Yuxi-Know。
4+
5+
## 前置要求
6+
7+
- **Docker Engine** (v24.0+)
8+
- **Docker Compose** (v2.20+)
9+
- **NVIDIA Container Toolkit** (如果在生产环境使用 GPU 服务)
10+
11+
注意事项:
12+
13+
1. 生产环境和开发环境最好是两台独立的机器,不然会存在端口和资源的冲突问题。
14+
2. 虽然名为“生产环境”,但实际上只是做了一些基本的配置而已,真要上线业务,需要根据实际情况进行调整。
15+
16+
## 部署步骤
17+
18+
### 1. 配置环境变量
19+
20+
为了避免与开发环境的冲突,建议在生产环境中使用 `.env.prod` 文件。请确保你已经从模板创建了该文件并填写了必要的密钥。
21+
22+
```bash
23+
cp .env.template .env.prod
24+
```
25+
26+
编辑 `.env.prod` 文件,设置强密码并配置必要的 API 密钥:
27+
28+
- `NEO4J_PASSWORD`: 修改默认密码
29+
- `MINIO_ACCESS_KEY` / `MINIO_SECRET_KEY`: 修改默认密钥
30+
- `SILICONFLOW_API_KEY` 等模型密钥
31+
32+
### 2. 启动服务
33+
34+
使用 `docker-compose.prod.yml` 文件启动生产环境:
35+
36+
```bash
37+
# 仅启动核心服务 (CPU 模式)
38+
docker compose -f docker-compose.prod.yml up -d --build
39+
40+
# 启动所有服务 (包含 GPU OCR 服务)
41+
docker compose -f docker-compose.prod.yml --profile all up -d --build
42+
```
43+
44+
### 3. 验证部署
45+
46+
- **Web 访问**: `http://localhost` (直接通过 80 端口访问,无需 :5173)
47+
- **API 健康检查**: `curl http://localhost/api/system/health`
48+
49+
## 维护与更新
50+
51+
### 更新代码并重新部署
52+
53+
```bash
54+
# 拉取最新代码
55+
git pull
56+
57+
# 重新构建并启动
58+
docker compose -f docker-compose.prod.yml up -d --build
59+
```
60+
61+
### 查看日志
62+
63+
```bash
64+
# 查看 API 日志
65+
docker logs -f api-prod
66+
67+
# 查看 Nginx 访问日志
68+
docker logs -f web-prod
69+
```

0 commit comments

Comments
 (0)