forked from bulolo/CatWiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.dev.yml
More file actions
441 lines (430 loc) · 11.2 KB
/
docker-compose.dev.yml
File metadata and controls
441 lines (430 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
services:
# PostgreSQL 数据库服务
postgres:
image: pgvector/pgvector:pg18
pull_policy: if_not_present
command: postgres -c "log_statement=none" -c "log_min_messages=error" -c "log_min_error_statement=error"
container_name: catwiki-postgres-dev
env_file:
- ./backend/.env
environment:
PGDATA: /var/lib/postgresql/data/pgdata
LANG: C.UTF-8
TZ: Asia/Shanghai
ports:
# 使用 5433 端口避免与本地 PostgreSQL 冲突
# 如果需要使用 5432,请先停止本地 PostgreSQL 服务
- "5433:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- catwiki-network
# 资源限制(可选,防止数据库占用过多资源)
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
reservations:
cpus: '0.25'
memory: 256M
# 日志配置
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
restart: unless-stopped
# Redis 缓存服务
redis:
image: redis:8.4.2
pull_policy: if_not_present
container_name: catwiki-redis-dev
command: redis-server
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
ports:
- "6379:6379"
volumes:
- redis_data:/data
networks:
- catwiki-network
# 资源限制
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.1'
memory: 128M
# 日志配置
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
restart: unless-stopped
# RustFS 对象存储服务
rustfs:
image: rustfs/rustfs:1.0.0-alpha.76
pull_policy: if_not_present
container_name: catwiki-rustfs-dev
env_file:
- ./backend/.env
environment:
TZ: Asia/Shanghai
ports:
# RustFS API 端口
- "9000:9000"
# RustFS Console 端口
- "9001:9001"
volumes:
# RustFS 数据存储(使用命名卷避免权限问题)
- rustfs_data:/data
# RustFS 日志
- rustfs_logs:/logs
# 时区配置(Linux only,Windows/Mac 会自动忽略)
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
networks:
- catwiki-network
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:9000/health || exit 1"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
# 资源限制
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
reservations:
cpus: '0.25'
memory: 256M
# 日志配置
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
restart: unless-stopped
# 后端初始化服务(只在首次启动或手动触发时运行)
# 负责:
# 1. 运行数据库迁移(alembic upgrade heads)
# 2. 创建初始管理员用户
# 3. 创建 Demo 站点(医学科普)和初始化医学知识文档
# 4. 初始化 RustFS 对象存储
backend-init:
image: catwiki-backend-dev
container_name: catwiki-backend-init
env_file:
- ./backend/.env
environment:
- UV_CACHE_DIR=/root/.cache/uv
volumes:
# 挂载代码目录以访问脚本
- ./backend:/app:delegated
# 排除不需要同步的目录
- /app/.venv
- /app/__pycache__
- /app/.pytest_cache
depends_on:
postgres:
condition: service_started
rustfs:
condition: service_healthy
redis:
condition: service_started
networks:
- catwiki-network
command: >
sh -c "
echo '==========================================' &&
echo '🚀 开始初始化 CatWiki...' &&
echo '==========================================' &&
echo '' &&
echo '📦 运行数据库迁移...' &&
uv run alembic upgrade heads &&
echo '✅ 数据库迁移完成' &&
echo '' &&
echo '📦 执行系统资源初始化 (知识库 / 对象存储)...' &&
uv run python scripts/init.py &&
echo '' &&
echo '==========================================' &&
echo '🎉 CatWiki 初始化完成!' &&
echo '==========================================' &&
echo '' &&
echo '📋 默认账号请查看登录页面提示' &&
echo '' &&
echo ' 管理后台:' &&
echo ' 🔗 访问: http://localhost:8001' &&
echo '' &&
echo '📖 API 文档:' &&
echo ' 🔗 访问: http://localhost:3000/docs' &&
echo '' &&
echo '📚 文档站点:' &&
echo ' 🔗 访问: http://localhost:8003' &&
echo '' &&
echo '🌐 Client 前端:' &&
echo ' 🔗 访问: http://localhost:8002' &&
echo '' &&
echo '==========================================' &&
echo ''
"
# 初始化服务只运行一次,成功后不重启
restart: "no"
# 日志配置
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "2"
# 后端 API 服务(支持热更新)
backend:
build:
context: ./backend
dockerfile: Dockerfile.dev
image: catwiki-backend-dev
container_name: catwiki-backend-dev
env_file:
- ./backend/.env
ports:
- "3000:3000"
volumes:
# 挂载代码目录以支持热更新
- ./backend:/app:delegated
# 排除不需要同步的目录(保留容器内的虚拟环境)
- /app/.venv
- /app/__pycache__
- /app/.git
- /app/.pytest_cache
depends_on:
postgres:
condition: service_started
rustfs:
condition: service_healthy
redis:
condition: service_started
backend-init:
condition: service_completed_successfully
networks:
- catwiki-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/v1/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
# 资源限制
deploy:
resources:
limits:
cpus: '2.0'
memory: 2G
reservations:
cpus: '0.5'
memory: 512M
# 日志配置
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "3"
stdin_open: true
tty: true
restart: unless-stopped
# 后端 Worker 服务(处理异步任务:解析、向量化等)
worker:
image: catwiki-backend-dev
container_name: catwiki-worker-dev
env_file:
- ./backend/.env
volumes:
- ./backend:/app:delegated
- /app/.venv
- /app/__pycache__
depends_on:
postgres:
condition: service_started
redis:
condition: service_started
backend-init:
condition: service_completed_successfully
networks:
- catwiki-network
# 启动 Arq Worker (使用 watchfiles 支持开发环境热更新)
command: uv run watchfiles --filter python "arq app.core.queue.worker_config.WorkerSettings" app
healthcheck:
test: ["CMD-SHELL", "pgrep -f arq || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "3"
restart: unless-stopped
# Admin 前端服务(管理后台,支持热更新)
admin-frontend:
build:
context: ./frontend/admin
dockerfile: Dockerfile.dev
image: catwiki-admin-frontend-dev
container_name: catwiki-admin-frontend-dev
environment:
NODE_ENV: development
TZ: Asia/Shanghai
NEXT_PUBLIC_API_URL: /api-proxy
NEXT_PUBLIC_CLIENT_URL: http://localhost:8002
NEXT_PUBLIC_DOCS_URL: http://localhost:8003
NEXT_PUBLIC_DEBUG: true
PROXY_API_URL: http://backend:3000
ports:
- "8001:8001"
volumes:
# 挂载代码目录以支持热更新
- ./frontend/admin:/app:delegated
- admin_node_modules:/app/node_modules
- admin_next_cache:/app/.next
- pnpm_store:/root/.local/share/pnpm/store
depends_on:
- backend
networks:
- catwiki-network
# 资源限制(适当提高以加速 Next.js 编译)
deploy:
resources:
limits:
cpus: '2.0'
memory: 2G
reservations:
cpus: '0.5'
memory: 512M
# 日志配置
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "3"
stdin_open: true
tty: true
restart: unless-stopped
# Client 前端服务(客户端,支持热更新)
client-frontend:
build:
context: ./frontend/client
dockerfile: Dockerfile.dev
image: catwiki-client-frontend-dev
container_name: catwiki-client-frontend-dev
environment:
NODE_ENV: development
TZ: Asia/Shanghai
NEXT_PUBLIC_API_URL: http://localhost:3000
NEXT_PUBLIC_DOCS_URL: http://localhost:8003
NEXT_PUBLIC_ADMIN_URL: http://localhost:8001
NEXT_PUBLIC_DEBUG: true
# PROXY_API_URL: http://localhost:3000
ports:
- "8002:8002"
volumes:
# 挂载代码目录以支持热更新
- ./frontend/client:/app:delegated
- client_node_modules:/app/node_modules
- client_next_cache:/app/.next
- pnpm_store:/root/.local/share/pnpm/store
depends_on:
- backend
networks:
- catwiki-network
# 资源限制(适当提高以加速 Next.js 编译)
deploy:
resources:
limits:
cpus: '2.0'
memory: 2G
reservations:
cpus: '0.5'
memory: 512M
# 日志配置
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "3"
stdin_open: true
tty: true
restart: unless-stopped
# Docs 文档站点服务(VitePress,支持热更新)
docs-frontend:
build:
context: ./frontend/docs
dockerfile: Dockerfile.dev
image: catwiki-docs-frontend-dev
container_name: catwiki-docs-frontend-dev
environment:
NODE_ENV: development
TZ: Asia/Shanghai
ports:
- "8003:8003"
volumes:
# 挂载代码目录以支持热更新
- ./frontend/docs:/app:delegated
- docs_node_modules:/app/node_modules
- pnpm_store:/root/.local/share/pnpm/store
networks:
- catwiki-network
# 资源限制
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
reservations:
cpus: '0.25'
memory: 256M
# 日志配置
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "3"
stdin_open: true
tty: true
restart: unless-stopped
volumes:
postgres_data:
driver: local
rustfs_data:
driver: local
redis_data:
driver: local
rustfs_logs:
driver: local
pnpm_store:
driver: local
admin_node_modules:
driver: local
admin_next_cache:
driver: local
client_node_modules:
driver: local
client_next_cache:
driver: local
docs_node_modules:
driver: local
networks:
catwiki-network:
driver: bridge