lengfengy commited on
Commit
91a07e8
·
verified ·
1 Parent(s): d25a7b6

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +14 -14
Dockerfile CHANGED
@@ -1,33 +1,33 @@
1
  FROM ghcr.io/su-kaka/gcli2api:latest
2
 
3
  USER root
4
- # 1. 创建精确的子目录层级
5
- RUN mkdir -p /app/creds/credentials /app/creds/antigravity && \
6
- chmod -R 777 /app/creds
7
 
8
- # 2. 修改 Python 脚本,根据 Secret 存入对应的子文件夹
9
  RUN echo 'import os\n\
10
- def restore(env_name, sub_folder):\n\
11
  data = os.environ.get(env_name, "").strip()\n\
12
  if not data: return\n\
13
- target_path = f"/app/creds/{sub_folder}"\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_path, filename)\n\
21
- with open(file_path, "w") as f:\n\
22
- f.write(content)\n\
23
- print(f"✅ 已恢复到 {sub_folder}: {filename}")\n\
 
 
24
  \n\
25
- # 凭证归位\n\
26
  restore("CREDENTIALS", "credentials")\n\
27
  restore("ANTIGRAVITY", "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
 
1
  FROM ghcr.io/su-kaka/gcli2api:latest
2
 
3
  USER root
4
+ # 创建目录,注意这次我们直接在根目录下尝试
5
+ RUN mkdir -p /app/credentials /app/antigravity /app/creds && \
6
+ chmod -R 777 /app
7
 
8
+ # 修改 Python 脚本,同时往两个可能的地方写文件
9
  RUN echo 'import os\n\
10
+ def restore(env_name, folder_name):\n\
11
  data = os.environ.get(env_name, "").strip()\n\
12
  if not data: return\n\
 
13
  blocks = data.split("---END---")\n\
14
  for block in blocks:\n\
15
  lines = block.strip().split("\\n")\n\
16
  if len(lines) < 2: continue\n\
17
+ fname = lines[0].strip()\n\
18
+ content = "\\n".join(lines[1:])\n\
19
+ # 方案:同时写入程序可能读取的两个位置\n\
20
+ paths = [f"/app/{folder_name}/{fname}", f"/app/creds/{folder_name}/{fname}"]\n\
21
+ for p in paths:\n\
22
+ os.makedirs(os.path.dirname(p), exist_ok=True)\n\
23
+ with open(p, "w") as f: f.write(content)\n\
24
+ print(f"✅ 已恢复到: {p}")\n\
25
  \n\
 
26
  restore("CREDENTIALS", "credentials")\n\
27
  restore("ANTIGRAVITY", "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