habppyar commited on
Commit
f818f8e
·
verified ·
1 Parent(s): bfcb6ed

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -39
Dockerfile CHANGED
@@ -1,50 +1,26 @@
1
- # 基础镜像
2
  FROM node:20-slim
3
 
4
- # 1. 强制设置 npm 全局路径并验证
5
- RUN npm config set prefix '/usr/local' && \
6
- echo "npm prefix set to $(npm config get prefix)"
7
-
8
- # 2. 切换为 root 用户
9
- USER root
10
-
11
- # 3. 安装系统依赖
12
  RUN apt-get update && apt-get install -y --no-install-recommends \
13
- python3 python3-venv git \
14
  && rm -rf /var/lib/apt/lists/*
15
 
16
- # 4. 创建 Python 虚拟环境
17
- RUN python3 -m venv /app/venv && \
18
- chown -R node:node /app/venv
19
 
20
- # 5. 安装 npm 全局包
21
  RUN npm install -g opencode-ai
22
 
23
- # 6. 关键步骤:查找 opencode-ai 的实际安装位置
24
- RUN echo "Finding opencode-ai location..." && \
25
- which opencode-ai || find / -name opencode-ai 2>/dev/null
26
-
27
- # 7. 创建符号链接确保在 PATH 中
28
- RUN ln -sf $(find / -name opencode-ai 2>/dev/null) /usr/local/bin/opencode-ai
29
-
30
- # 8. 验证安装位置
31
- RUN ls -la /usr/local/bin/opencode-ai
32
-
33
- # 9. 切换回 node 用户
34
- USER node
35
-
36
- # 10. 设置工作目录
37
- WORKDIR /home/node/app
38
-
39
- # 11. 复制代码
40
- COPY --chown=node . .
41
 
42
- # 12. 安装 Python 依赖
43
- RUN /app/venv/bin/pip install --upgrade pip huggingface_hub
 
44
 
45
- # 13. 验证安装(使用符号链接路径)
46
- RUN /app/venv/bin/python -c "import huggingface_hub; print('Success')" && \
47
- /usr/local/bin/opencode-ai --version
48
 
49
- EXPOSE 7860
50
- CMD ["sh", "-c", "node server.js"]
 
 
1
  FROM node:20-slim
2
 
3
+ # basic tools + tini for clean signal handling
 
 
 
 
 
 
 
4
  RUN apt-get update && apt-get install -y --no-install-recommends \
5
+ ca-certificates curl bash git tini \
6
  && rm -rf /var/lib/apt/lists/*
7
 
8
+ # Create non-root user (recommended in Spaces)
9
+ RUN useradd -m -u 1000 user
 
10
 
11
+ # Install OpenCode (Node method is officially supported)
12
  RUN npm install -g opencode-ai
13
 
14
+ # Install HF CLI (standalone installer)
15
+ # Official CLI docs: curl -LsSf https://hf.co/cli/install.sh | bash
16
+ RUN curl -LsSf https://hf.co/cli/install.sh | bash
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ USER user
19
+ ENV HOME=/home/user
20
+ ENV PATH="/home/user/.local/bin:/usr/local/bin:${PATH}"
21
 
22
+ WORKDIR /app
23
+ COPY --chown=user:user . /app
 
24
 
25
+ ENTRYPOINT ["/usr/bin/tini","--"]
26
+ CMD ["/app/entrypoint.sh"]