leonsimon23 commited on
Commit
102d5e1
·
verified ·
1 Parent(s): 5c4f7f7

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -41
Dockerfile CHANGED
@@ -1,59 +1,40 @@
1
  # 使用官方Python 3.10 slim镜像
2
  FROM python:3.10-slim
3
 
4
- # --- 1. 安装系统依赖 ---
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
  git \
7
- git-lfs \
8
- build-essential \
9
- libgomp1 \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- # --- 2. 设置工作目录 ---
13
- WORKDIR /src
14
-
15
- # --- 3. 关键步骤:克隆私有仓库 ---
16
- RUN git lfs install
17
-
18
- # 使用Secrets来安全地克隆(修复:添加错误处理和验证)
19
- RUN --mount=type=secret,id=GH_USER \
20
- --mount=type=secret,id=GH_TOKEN \
21
- GH_USER=$(cat /run/secrets/GH_USER) && \
22
- GH_TOKEN=$(cat /run/secrets/GH_TOKEN) && \
23
- echo "Cloning with user: $GH_USER" && \
24
- git clone https://${GH_USER}:${GH_TOKEN}@github.com/leoncool23/tcm_expert_builder.git || \
25
- (echo "Git clone failed!" && exit 1)
26
-
27
- # --- 4. 验证克隆成功并切换工作目录 ---
28
- RUN ls -la /src/tcm_expert_builder && \
29
- ls -la /src/tcm_expert_builder/requirements.txt
30
- WORKDIR /src/tcm_expert_builder
31
-
32
- # --- 5. 安装Python依赖 ---
33
- # 先复制requirements.txt以利用Docker缓存
34
- COPY --from=/src/tcm_expert_builder/requirements.txt requirements.txt
35
  RUN pip install --no-cache-dir --upgrade pip && \
36
  pip install --no-cache-dir -r requirements.txt
37
 
38
- # --- 6. 配置NLTK和ChromaDB环境 ---
39
  ENV NLTK_DATA=/usr/local/share/nltk_data
40
  ENV ANONYMIZED_TELEMETRY=false
41
- RUN python -m nltk.downloader -d $NLTK_DATA punkt stopwords
42
 
43
- # --- 7. 创建用户和设置权限 ---
44
- RUN useradd --create-home --shell /bin/bash appuser && \
45
- chown -R appuser:appuser /src
46
- USER appuser
47
 
48
- # --- 8. 创建必要目录 ---
49
- RUN mkdir -p ./uploads ./data/vector_db ./data
50
 
51
- # --- 9. 健康检查 ---
52
- HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
53
- CMD curl -f http://localhost:7860/health || exit 1
54
 
55
- # --- 10. 运行应用 ---
56
  EXPOSE 7860
57
 
58
- # 修复:使用更合适的启动配置
59
- CMD ["gunicorn", "--workers", "1", "--bind", "0.0.0.0:7860", "--timeout", "120", "--preload", "--log-level", "info", "app:app"]
 
1
  # 使用官方Python 3.10 slim镜像
2
  FROM python:3.10-slim
3
 
4
+ # --- 安装系统依赖 ---
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
  git \
7
+ curl \
 
 
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
+ # --- 设置工作目录 ---
11
+ WORKDIR /app
12
+
13
+ # --- 克隆代码仓库 ---
14
+ ARG GH_USER
15
+ ARG GH_TOKEN
16
+ RUN git clone https://${GH_USER}:${GH_TOKEN}@github.com/leoncool23/tcm_expert_builder.git . && \
17
+ ls -la
18
+
19
+ # --- 安装Python依赖 ---
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  RUN pip install --no-cache-dir --upgrade pip && \
21
  pip install --no-cache-dir -r requirements.txt
22
 
23
+ # --- 配置环境变量 ---
24
  ENV NLTK_DATA=/usr/local/share/nltk_data
25
  ENV ANONYMIZED_TELEMETRY=false
 
26
 
27
+ # --- 下载NLTK数据 ---
28
+ RUN python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"
 
 
29
 
30
+ # --- 创建必要目录 ---
31
+ RUN mkdir -p uploads data/vector_db data
32
 
33
+ # --- 添加健康检查端点到你的Flask应用 ---
34
+ # 在app.py中添加: @app.route('/health') def health(): return {'status': 'ok'}
 
35
 
36
+ # --- 暴露端口 ---
37
  EXPOSE 7860
38
 
39
+ # --- 启动应用 ---
40
+ CMD ["python", "app.py"]