lengfengy commited on
Commit
56905fc
·
verified ·
1 Parent(s): 2276523

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -23
Dockerfile CHANGED
@@ -1,29 +1,33 @@
1
- # 1. 使用原作者镜像
2
  FROM ghcr.io/su-kaka/gcli2api:latest
3
 
4
- # 2. 切换到 root 权限进行配置
5
  USER root
 
 
 
6
 
7
- # 3. 设置环境变量
8
- # 核心:HF 必须监听 7860,否则外部无法访问
9
- ENV PORT=7860
10
-
11
- # 4. 处理持久化目录权限
12
- # HF 容器内部默认使用 user id 1000
13
- RUN mkdir -p /app/creds && chmod -R 777 /app/creds
14
-
15
- # 5. 暴露端口
16
- EXPOSE 7860
 
 
 
 
 
 
 
 
 
 
17
 
18
- # 6. 核心:Entrypoint 逻辑转换
19
- # 将你的 shell 逻辑写成一个启动脚本
20
- RUN echo '#!/bin/sh\n\
21
- echo "✅正在启动服务..."\n\
22
- # 如果原镜像需要特定域名替换逻辑,可以在此处添加\n\
23
- exec python web.py' > /app/start.sh && chmod +x /app/start.sh
24
-
25
- # 7. 切换回非 root 用户(HF 安全要求)
26
- USER 1000
27
 
28
- # 8. 启动命令
29
- ENTRYPOINT ["/app/start.sh"]
 
 
1
  FROM ghcr.io/su-kaka/gcli2api:latest
2
 
 
3
  USER root
4
+ # 创建必要的目录
5
+ RUN mkdir -p /app/creds/credentials /app/creds/antigravity && \
6
+ chmod -R 777 /app/creds
7
 
8
+ # 编写还原逻辑的 Python 脚本
9
+ RUN echo 'import os\n\
10
+ def restore(env_name, target_dir):\n\
11
+ data = os.environ.get(env_name, "").strip()\n\
12
+ if not data: return\n\
13
+ # 按照 ---END--- 分隔每个文件块\n\
14
+ blocks = data.split("---END---")\n\
15
+ for block in blocks:\n\
16
+ lines = block.strip().split("\\n")\n\
17
+ if len(lines) < 2: continue\n\
18
+ filename = lines[0].strip()\n\
19
+ content = "\\n".join(lines[1:]).strip()\n\
20
+ file_path = os.path.join(target_dir, filename)\n\
21
+ with open(file_path, "w") as f:\n\
22
+ f.write(content)\n\
23
+ print(f"✅ 已恢复文件: {file_path}")\n\
24
+ \n\
25
+ # 执行还原\n\
26
+ restore("CREDENTIALS", "/app/creds/credentials")\n\
27
+ restore("ANTIGRAVITY", "/app/creds/antigravity")' > /app/init_creds.py
28
 
29
+ ENV PORT=7860
30
+ # 启动顺序:先运行还原脚本,再执行主程序
31
+ ENTRYPOINT ["/bin/sh", "-c", "python3 /app/init_creds.py && exec python web.py"]
 
 
 
 
 
 
32
 
33
+ USER 1000