Skip to content

Commit 3c856ab

Browse files
committed
feat: improve docker setup
- mount files for development and enable streamlit live reloading - add multi-stage builds to dockerfile - separate supervisord configs for prod and dev - correctly load env vars - use data and log volumes for production setup - optimize docker build by effectively using layer cache
1 parent fc8a607 commit 3c856ab

File tree

8 files changed

+95
-20
lines changed

8 files changed

+95
-20
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.venv
2+
data
3+
log

.env.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#服务端口
22
SERVER_PORT=5001
33

4+
#Timezone
5+
TZ=Asia/Shanghai
6+
47
#大模型供应商配置,支持 zhipuai , openai , deepseek or ollama
58
LLM_PROVIDER=deepseek
69

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ test/
55
docker
66

77
log/*
8-
!log/
8+
!log/.gitkeep
99
data/*
10-
!data/
10+
!data/.gitkeep
1111

1212
.env
1313
.pyc

Dockerfile

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
# 使用官方的 Python 基础镜像
2-
FROM python:3.10-slim
2+
FROM python:3.10-slim AS base
33

44
# 设置工作目录
55
WORKDIR /app
66

7-
# 复制项目文件&创建必要的文件夹
8-
COPY requirements.txt .
9-
COPY biz /app/biz
10-
COPY core /app/core
11-
COPY api.py /app/api.py
12-
COPY ui.py /app/ui.py
13-
COPY prompt_templates.yml /app/prompt_templates.yml
14-
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
15-
RUN mkdir -p /app/log /app/data
16-
177
# 安装 supervisord 作为进程管理工具
188
RUN apt-get update && apt-get install -y --no-install-recommends supervisor && rm -rf /var/lib/apt/lists/*
199

10+
# 复制项目文件&创建必要的文件夹
11+
COPY requirements.txt .
12+
2013
# 安装依赖
2114
RUN pip install --no-cache-dir -r requirements.txt
2215

16+
COPY biz .
17+
COPY core .
18+
COPY api.py .
19+
COPY ui.py .
20+
COPY prompt_templates.yml .
21+
RUN mkdir -p log data
22+
2323
# 暴露 Flask 和 Streamlit 的端口
2424
EXPOSE 5001 5002
2525

2626
# 使用 supervisord 作为启动命令
27-
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
27+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
28+
29+
FROM base AS dev
30+
COPY supervisord.dev.conf /etc/supervisor/conf.d/supervisord.conf
31+
32+
FROM base AS prod
33+
COPY supervisord.prod.conf /etc/supervisor/conf.d/supervisord.conf

docker-compose.prod.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
target: prod
7+
image: sunmh207/ai-codereview-gitlab:1.2.2
8+
ports:
9+
- "5001:5001"
10+
- "5002:5002"
11+
volumes:
12+
- data:/app/data
13+
- log:/app/log
14+
env_file:
15+
- .env
16+
restart: unless-stopped
17+
18+
volumes:
19+
data:
20+
log:

docker-compose.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
services:
2-
flask-app:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
target: dev
37
image: sunmh207/ai-codereview-gitlab:1.2.2
48
ports:
59
- "5001:5001"
610
- "5002:5002"
711
volumes:
8-
- ./.env:/app/.env
9-
- ./log:/app/log
12+
- ./biz:/app/biz
13+
- ./core:/app/core
1014
- ./data:/app/data
11-
environment:
12-
- TZ=Asia/Shanghai
15+
- ./log:/app/log
16+
- ./api.py:/app/api.py
17+
- ./prompt_templates.yml:/app/prompt_templates.yml
18+
- ./requirements.txt:/app/requirements.txt
19+
- ./supervisord.dev.conf:/etc/supervisor/conf.d/supervisord.conf
20+
- ./ui.py:/app/ui.py
21+
env_file:
22+
- .env
1323
restart: unless-stopped

supervisord.dev.conf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[supervisord]
2+
nodaemon=true
3+
user=root
4+
5+
[program:flask]
6+
command=python /app/api.py
7+
autostart=true
8+
autorestart=true
9+
numprocs=1
10+
stdout_logfile=/dev/stdout
11+
stderr_logfile=/dev/stderr
12+
stdout_maxbytes=0
13+
stderr_maxbytes=0
14+
stdout_logfile_maxbytes = 0
15+
stderr_logfile_maxbytes = 0
16+
17+
[program:streamlit]
18+
command=streamlit run /app/ui.py --server.port=5002 --server.address=0.0.0.0 --server.headless true --server.fileWatcherType=poll
19+
autostart=true
20+
autorestart=true
21+
numprocs=1
22+
stdout_logfile=/dev/stdout
23+
stderr_logfile=/dev/stderr
24+
stdout_maxbytes=0
25+
stderr_maxbytes=0
26+
stdout_logfile_maxbytes = 0
27+
stderr_logfile_maxbytes = 0

supervisord.conf renamed to supervisord.prod.conf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ user=root
44

55
[program:flask]
66
command=python /app/api.py
7+
autostart=true
8+
autorestart=true
9+
numprocs=1
710
stdout_logfile=/dev/stdout
811
stderr_logfile=/dev/stderr
912
stdout_maxbytes=0
@@ -12,7 +15,10 @@ stdout_logfile_maxbytes = 0
1215
stderr_logfile_maxbytes = 0
1316

1417
[program:streamlit]
15-
command=streamlit run /app/ui.py --server.port=5002 --server.address=0.0.0.0
18+
command=streamlit run /app/ui.py --server.port=5002 --server.address=0.0.0.0 --server.headless true
19+
autostart=true
20+
autorestart=true
21+
numprocs=1
1622
stdout_logfile=/dev/stdout
1723
stderr_logfile=/dev/stderr
1824
stdout_maxbytes=0

0 commit comments

Comments
 (0)