leonsimon23 commited on
Commit
30cf0d1
·
verified ·
1 Parent(s): dac8a26

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +69 -22
Dockerfile CHANGED
@@ -1,38 +1,85 @@
1
  # 使用官方Python 3.10 slim镜像
2
  FROM python:3.10-slim
3
 
4
- # --- 1. 安装最基本的系统依赖 ---
5
- # 我们只需要curl(一个通用的网络工具)和libgomp1(torch可能需要)
6
  RUN apt-get update && apt-get install -y --no-install-recommends \
7
- curl \
 
 
8
  libgomp1 \
 
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
- # --- 2. 创建应用用户和工作目录 ---
12
- RUN useradd --create-home --shell /bin/bash appuser
13
- WORKDIR /app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- # --- 3. 复制依赖文件并安装 (利用Docker缓存) ---
16
- COPY requirements.txt .
17
- RUN pip install --no-cache-dir -r requirements.txt
 
 
18
 
19
- # --- 4. 复制整个项目代码和数据 ---
20
- # 所有.py, templates/, static/, data/等文件都会被复制
21
- COPY . .
 
 
22
 
23
- # --- 5. 配置NLTK和ChromaDB环境 ---
24
- ENV NLTK_DATA=/app/nltk_data
25
  ENV ANONYMIZED_TELEMETRY=false
26
- # 在复制完代码后,以appuser身份下载,确保权限正确
27
- RUN mkdir -p $NLTK_DATA && \
28
- chown -R appuser:appuser /app && \
29
- su appuser -c "python -m nltk.downloader -d $NLTK_DATA punkt"
30
 
31
- # --- 6. 切换到非root用户 ---
 
 
 
 
 
 
 
 
 
 
32
  USER appuser
33
 
34
- # --- 7. 暴露端口 ---
 
 
 
35
  EXPOSE 7860
36
 
37
- # --- 8. 启动应用 ---
38
- CMD ["gunicorn", "--workers", "1", "--bind", "0.0.0.0:7860", "--timeout", "120", "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
+ git-lfs \
8
+ build-essential \
9
  libgomp1 \
10
+ curl \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
+ # --- 设置工作目录 ---
14
+ WORKDIR /src
15
+
16
+ # --- Git LFS初始化 ---
17
+ RUN git lfs install
18
+
19
+ # --- 克隆私有仓库 ---
20
+ RUN --mount=type=secret,id=GH_USER \
21
+ --mount=type=secret,id=GH_TOKEN \
22
+ echo "Starting repository clone..." && \
23
+ GH_USER=$(cat /run/secrets/GH_USER) && \
24
+ GH_TOKEN=$(cat /run/secrets/GH_TOKEN) && \
25
+ echo "Cloning for user: $GH_USER" && \
26
+ git clone https://$GH_USER:$GH_TOKEN@github.com/leoncool23/tcm_expert_builder.git && \
27
+ echo "Clone completed successfully" && \
28
+ ls -la tcm_expert_builder/
29
+
30
+ # --- 切换到项目目录 ---
31
+ WORKDIR /src/tcm_expert_builder
32
 
33
+ # --- 验证关键文件 ---
34
+ RUN echo "Verifying project structure..." && \
35
+ ls -la && \
36
+ test -f requirements.txt && echo "requirements.txt found" || echo "requirements.txt missing" && \
37
+ test -f app.py && echo "app.py found" || echo "app.py missing"
38
 
39
+ # --- 安装Python依赖 ---
40
+ RUN echo "Installing Python dependencies..." && \
41
+ pip install --no-cache-dir --upgrade pip && \
42
+ pip install --no-cache-dir -r requirements.txt && \
43
+ echo "Dependencies installed successfully"
44
 
45
+ # --- 配置环境变量 ---
46
+ ENV NLTK_DATA=/usr/local/share/nltk_data
47
  ENV ANONYMIZED_TELEMETRY=false
48
+ ENV PYTHONUNBUFFERED=1
 
 
 
49
 
50
+ # --- 下载NLTK数据 ---
51
+ RUN echo "Downloading NLTK data..." && \
52
+ python -c "import nltk; nltk.download('punkt', quiet=True); nltk.download('stopwords', quiet=True)" 2>/dev/null || \
53
+ python -m nltk.downloader -d $NLTK_DATA punkt stopwords || \
54
+ echo "NLTK download completed with warnings"
55
+
56
+ # --- 创建用户和设置权限 ---
57
+ RUN useradd --create-home --shell /bin/bash appuser && \
58
+ chown -R appuser:appuser /src
59
+
60
+ # --- 切换到非root用户 ---
61
  USER appuser
62
 
63
+ # --- 创建必要目录 ---
64
+ RUN mkdir -p ./uploads ./data/vector_db ./data ./templates ./static
65
+
66
+ # --- 暴露端口 ---
67
  EXPOSE 7860
68
 
69
+ # --- 健康检查 ---
70
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \
71
+ CMD curl -f http://localhost:7860/health || exit 1
72
+
73
+ # --- 启动应用 ---
74
+ # 使用更保守的配置,增加启动时间容限
75
+ CMD ["gunicorn", \
76
+ "--workers", "1", \
77
+ "--bind", "0.0.0.0:7860", \
78
+ "--timeout", "300", \
79
+ "--graceful-timeout", "60", \
80
+ "--keep-alive", "5", \
81
+ "--log-level", "info", \
82
+ "--access-logfile", "-", \
83
+ "--error-logfile", "-", \
84
+ "--capture-output", \
85
+ "app:app"]