habppyar commited on
Commit
cfdcdcf
·
verified ·
1 Parent(s): 19437e0

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -35
Dockerfile CHANGED
@@ -1,54 +1,39 @@
1
  # 基础镜像选择(Node 20官方精简版)
2
- FROM node:20-slim@sha256:1e85773c98c31d4fe5b545e4cb17379e617b348832fb3738b22a08f68dec30f3
3
 
4
- # 设置非交互式环境,避免安装过程中的交互提示
5
  ENV DEBIAN_FRONTEND=noninteractive \
6
- # 配置Python虚拟环境路径(避免系统路径冲突)
7
  VIRTUAL_ENV=/app/.venv \
8
- # 设置Hugging Face缓存目录(避免权限问题)
9
  HF_HOME=/app/.cache/huggingface \
10
- # 配置pip镜像源(解决网络问题)
11
- PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \
12
- # 确保使用正确的Python版本
13
- PYTHON_VERSION=3.11
14
 
15
- # 一次性安装所有基础依赖(合并为单个RUN层减少镜像层数
16
  RUN apt-get update && apt-get install -y --no-install-recommends \
17
- # 必要的系统工具
18
- ca-certificates curl bash git tini \
19
- # Python核心环境(指定版本避免兼容性问题)
20
- python3=${PYTHON_VERSION}* python3-pip python3-venv \
21
- # 清理缓存减少镜像大小
22
  && rm -rf /var/lib/apt/lists/*
23
 
24
- # 创建应用目录结构(避免权限问题)
25
- RUN mkdir -p /app /app/.cache/huggingface /app/.local/bin
26
 
27
- # 设置工作目录
28
  WORKDIR /app
29
 
30
- # 配置Python虚拟环境(最佳实践避免污染系统环境)
 
31
  RUN python3 -m venv $VIRTUAL_ENV \
32
- && . $VIRTUAL_ENV/bin/activate \
33
- # 升级pip确保兼容性(关键步骤)
34
  && pip install --upgrade pip setuptools wheel \
35
- # 安装Hugging Face核心库(使用正确包名)
36
  && pip install huggingface_hub \
37
- # 安装OpenCode工具
38
- && npm install -g opencode-ai
 
 
 
39
 
40
- # 配置环境变量(确保所有工具能找到正确路径)
41
- ENV PATH="$VIRTUAL_ENV/bin:$PATH" \
42
- HOME=/app \
43
- APP_ENV=production
44
 
45
- # 复制应用代码(使用chown确保权限正确)
46
- COPY --chown=root:root . /app
47
-
48
- # 验证安装(提前发现问题)
49
- RUN opencode-ai --version && \
50
- python3 -c "import huggingface_hub; print('Hugging Face Hub installed successfully')"
51
-
52
- # 设置入口点(确保tini正确工作)
53
  ENTRYPOINT ["/usr/bin/tini", "--"]
54
  CMD ["/app/entrypoint.sh"]
 
1
  # 基础镜像选择(Node 20官方精简版)
2
+ FROM node:20-slim
3
 
4
+ # 设置非交互式环境
5
  ENV DEBIAN_FRONTEND=noninteractive \
6
+ # 核心修复:将虚拟环境路径和 npm 全局路径合并到 PATH
7
  VIRTUAL_ENV=/app/.venv \
8
+ PATH="/app/.venv/bin:/usr/local/bin:${PATH}" \
9
  HF_HOME=/app/.cache/huggingface \
10
+ PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
 
 
 
11
 
12
+ # 安装系统依赖(包含 python3-venv
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
14
+ ca-certificates curl bash git tini python3 python3-pip python3-venv \
 
 
 
 
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
+ # 创建目录
18
+ RUN mkdir -p /app /app/.cache/huggingface
19
 
 
20
  WORKDIR /app
21
 
22
+ # --- 关键整合步骤安装与验证合二为一 ---
23
+ # 利用 && 连接命令,确保在同一 Shell 层级下执行,环境变量有效
24
  RUN python3 -m venv $VIRTUAL_ENV \
25
+ # 1. 升级 pip 并安装 Python 依赖
 
26
  && pip install --upgrade pip setuptools wheel \
 
27
  && pip install huggingface_hub \
28
+ # 2. 安装 Node.js 全局工具
29
+ && npm install -g opencode-ai \
30
+ # 3. 立即在同一层级进行验证(此时 PATH 依然生效)
31
+ && opencode-ai --version \
32
+ && python3 -c "import huggingface_hub; print('Hugging Face Hub installed successfully')"
33
 
34
+ # 复制代码
35
+ COPY . /app
 
 
36
 
37
+ # 启动命令
 
 
 
 
 
 
 
38
  ENTRYPOINT ["/usr/bin/tini", "--"]
39
  CMD ["/app/entrypoint.sh"]