exable324 commited on
Commit
ec1432d
·
verified ·
1 Parent(s): 0a72e55

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -21
Dockerfile CHANGED
@@ -1,12 +1,17 @@
1
- # Stage 1: 构建前端
2
  FROM node:20-slim AS builder
3
- RUN apt-get update && apt-get install -y git
 
 
 
4
  WORKDIR /build
5
  RUN git clone https://github.com/Dreamy-rain/gemini-business2api.git .
 
 
6
  WORKDIR /build/frontend
7
- RUN npm install && npm run build
8
 
9
- # Stage 2: 最终运行环境
10
  FROM python:3.11-slim
11
 
12
  # 设置环境变量
@@ -17,13 +22,15 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
17
  PATH=/home/user/.local/bin:$PATH \
18
  CHROME_PATH=/usr/bin/chromium
19
 
20
- # 创建 HF 强制要求的非 root 用户
21
  RUN useradd -m -u 1000 user
 
22
  WORKDIR $HOME/app
23
 
24
- # 安装 Chromium 及其所有依赖环境
25
- USER root
26
 
 
27
  RUN apt-get update && \
28
  apt-get install -y --no-install-recommends \
29
  gcc \
@@ -42,26 +49,22 @@ RUN apt-get update && \
42
  apt-get autoremove -y && \
43
  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
44
 
 
 
 
 
 
 
45
 
46
- # 复制项目文件
47
- COPY --from=builder --chown=user /build $HOME/app
48
-
49
- # 切换到非 root 用户
50
- #USER user
51
-
52
- # 安装 Python 依赖
53
- #RUN pip install --no-cache-dir -r requirements.txt
54
-
55
- # 确保目录权限和端口暴露
56
- RUN mkdir -p $HOME/app/data && chmod 777 $HOME/app/data
57
  EXPOSE 7860
58
 
59
- # 赋予启动脚本权限
60
- RUN chmod +x entrypoint.sh
61
 
62
  # 健康检查
63
  HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
64
  CMD curl -f http://localhost:7860/admin/health || exit 1
65
 
66
- # 启动命令
67
  CMD ["./entrypoint.sh"]
 
1
+ # Stage 1: 克隆代码并构建前端
2
  FROM node:20-slim AS builder
3
+
4
+ RUN apt-get update && apt-get install -y --no-install-recommends git && \
5
+ rm -rf /var/lib/apt/lists/*
6
+
7
  WORKDIR /build
8
  RUN git clone https://github.com/Dreamy-rain/gemini-business2api.git .
9
+
10
+ # 构建前端
11
  WORKDIR /build/frontend
12
+ RUN npm install --silent && npm run build
13
 
14
+ # Stage 2: 最终运行时镜像
15
  FROM python:3.11-slim
16
 
17
  # 设置环境变量
 
22
  PATH=/home/user/.local/bin:$PATH \
23
  CHROME_PATH=/usr/bin/chromium
24
 
25
+ # 创建 HF 强制要求的非 root 用户(uid=1000)
26
  RUN useradd -m -u 1000 user
27
+
28
  WORKDIR $HOME/app
29
 
30
+ # builder 阶段复制整个项目(包含构建好的 static)
31
+ COPY --from=builder /build $HOME/app
32
 
33
+ # 安装系统依赖和 Python 依赖
34
  RUN apt-get update && \
35
  apt-get install -y --no-install-recommends \
36
  gcc \
 
49
  apt-get autoremove -y && \
50
  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
51
 
52
+ # 创建数据目录并设置权限
53
+ RUN mkdir -p ./data && \
54
+ chown -R user:user $HOME/app && \
55
+ chmod -R 755 $HOME/app && \
56
+ chmod 777 ./data && \
57
+ chmod +x entrypoint.sh
58
 
59
+ # 声明端口
 
 
 
 
 
 
 
 
 
 
60
  EXPOSE 7860
61
 
62
+ # 切换到非 root 用户(HF Space 强制要求)
63
+ USER user
64
 
65
  # 健康检查
66
  HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
67
  CMD curl -f http://localhost:7860/admin/health || exit 1
68
 
69
+ # 启动服务
70
  CMD ["./entrypoint.sh"]