-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathdocker-compose.https.yml
More file actions
158 lines (151 loc) · 3.92 KB
/
docker-compose.https.yml
File metadata and controls
158 lines (151 loc) · 3.92 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
# Docker Compose 配置 - HTTPS 版本
# 适用于有 SSL 证书的场景
# 使用方式: docker compose -f docker-compose.https.yml up -d
services:
# 数据库服务
mysql:
image: mysql:8.0
container_name: sag_mysql
environment:
MYSQL_ROOT_PASSWORD: sag_root
MYSQL_DATABASE: sag
MYSQL_USER: sag
MYSQL_PASSWORD: sag_pass
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
networks:
- sag_network
elasticsearch:
build:
context: .
dockerfile: Dockerfile.elasticsearch
container_name: sag_elasticsearch
environment:
- discovery.type=single-node
- xpack.security.enabled=false
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ports:
- "9200:9200"
- "9300:9300"
volumes:
- es_data:/usr/share/elasticsearch/data
healthcheck:
test:
["CMD-SHELL", "curl -f http://localhost:9200/_cluster/health || exit 1"]
interval: 30s
timeout: 10s
retries: 5
networks:
- sag_network
# 后端 API 服务
api:
build:
context: .
dockerfile: Dockerfile.api
container_name: sag_api
environment:
- MYSQL_HOST=mysql
- MYSQL_PORT=3306
- MYSQL_USER=sag
- MYSQL_PASSWORD=sag_pass
- MYSQL_DATABASE=sag
- ES_HOST=elasticsearch
- ES_PORT=9200
- LLM_API_KEY=${LLM_API_KEY}
- LLM_MODEL=${LLM_MODEL:-sophnet/Qwen3-30B-A3B-Thinking-2507}
- LLM_BASE_URL=${LLM_BASE_URL}
- EMBEDDING_MODEL_NAME=${EMBEDDING_MODEL_NAME:-Qwen/Qwen3-Embedding-0.6B}
- EMBEDDING_BASE_URL=${EMBEDDING_BASE_URL}
- EMBEDDING_API_KEY=${EMBEDDING_API_KEY}
- API_HOST=0.0.0.0
- API_PORT=8000
- API_WORKERS=${API_WORKERS:-4} # 服务器生产环境默认 4 workers
expose:
- "8000"
volumes:
- ./uploads:/app/uploads
- ./migrations:/app/migrations
- ./alembic.ini:/app/alembic.ini
# 🆕 添加启动命令,先执行初始化再启动服务(多 worker 模式)
command: >
sh -c "
echo '🔧 开始初始化...' &&
echo '⏳ 等待数据库就绪...' &&
sleep 5 &&
echo '🔄 执行数据库迁移 (Alembic)...' &&
uv run alembic upgrade head &&
echo '✅ 数据库迁移完成' &&
echo '📊 插入默认实体类型...' &&
uv run python scripts/init_database.py &&
echo '🔍 初始化 Elasticsearch...' &&
uv run python scripts/init_elasticsearch.py &&
echo '🌐 启动 API 服务 (Workers: $${API_WORKERS:-4})...' &&
uv run python -m sag.api.main
"
depends_on:
mysql:
condition: service_healthy
elasticsearch:
condition: service_healthy
networks:
- sag_network
restart: unless-stopped
# 前端 Web 服务
web:
build:
context: ./web
dockerfile: Dockerfile
container_name: sag_web
expose:
- "3000"
depends_on:
- api
networks:
- sag_network
restart: unless-stopped
# Nginx 反向代理(HTTPS)
nginx:
image: nginx:alpine
container_name: sag_nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx-ssl.conf:/etc/nginx/conf.d/default.conf:ro
- ./certs:/etc/nginx/certs:ro
depends_on:
- web
- api
networks:
- sag_network
restart: unless-stopped
healthcheck:
test:
[
"CMD",
"wget",
"--quiet",
"--tries=1",
"--spider",
"https://localhost/health",
"--no-check-certificate",
]
interval: 30s
timeout: 10s
retries: 3
volumes:
mysql_data:
driver: local
es_data:
driver: local
networks:
sag_network:
driver: bridge