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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +26 -69
Dockerfile CHANGED
@@ -1,85 +1,42 @@
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"]
 
1
  # 使用官方Python 3.10 slim镜像
2
  FROM python:3.10-slim
3
 
4
+ # --- 1. 设置环境变量 ---
5
+ ENV PYTHONUNBUFFERED=1 \
6
+ PIP_NO_CACHE_DIR=off \
7
+ PIP_DISABLE_PIP_VERSION_CHECK=on \
8
+ POETRY_VIRTUALENVS_CREATE=false \
9
+ NLTK_DATA=/usr/local/share/nltk_data \
10
+ ANONYMIZED_TELEMETRY=false
11
+
12
+ # --- 2. 安装最基本的系统依赖 ---
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
 
 
 
14
  curl \
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
+ # --- 3. 创建应用用户和工作目录 ---
18
+ RUN useradd --create-home --shell /bin/bash appuser
19
+ WORKDIR /app
20
 
21
+ # --- 4. 复制依赖文件并安装 ---
22
+ COPY requirements.txt .
23
+ # 核心修改:在安装时使用 --extra-index-url
24
+ RUN pip install -r requirements.txt
25
 
26
+ # --- 5. 复制整个项目代码 ---
27
+ COPY . .
 
 
 
 
 
 
 
 
28
 
29
+ # --- 6. 下载NLTK数据 ---
30
+ RUN python -m nltk.downloader -d $NLTK_DATA punkt
31
 
32
+ # --- 7. 设置权限 ---
33
+ RUN chown -R appuser:appuser /app
 
 
 
34
 
35
+ # --- 8. 切换到非root用户 ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  USER appuser
37
 
38
+ # --- 9. 暴露端口 ---
 
 
 
39
  EXPOSE 7860
40
 
41
+ # --- 10. 启动应用 ---
42
+ CMD ["gunicorn", "--workers", "1", "--bind", "0.0.0.0:7860", "--timeout", "120", "app:app"]