FROM python:3.11-slim WORKDIR /app # 安装必要工具 RUN apt-get update && \ apt-get install -y --no-install-recommends git && \ rm -rf /var/lib/apt/lists/* # 添加一个 ADD 指令获取时间戳文件,强制后续指令不使用缓存 ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" checkout # 先清理工作目录,然后克隆仓库 RUN rm -rf * && git clone https://github.com/iidamie/deepseek2api.git . \ && rm -rf .git # 创建生成配置的Python脚本 RUN echo '#!/usr/bin/env python3\n\ import os\n\ import json\n\ \n\ def load_existing_config():\n\ try:\n\ with open("config.json", "r") as f:\n\ return json.load(f)\n\ except FileNotFoundError:\n\ return {"keys": [], "accounts": []}\n\ \n\ # 读取原有配置\n\ config = load_existing_config()\n\ \n\ # 读取环境变量\n\ keys = os.environ.get("KEYS", "")\n\ tokens = os.environ.get("TOKENS", "")\n\ \n\ # 只在环境变量存在时更新配置\n\ if keys.strip():\n\ config["keys"] = [k.strip() for k in keys.split(",") if k.strip()]\n\ \n\ if tokens.strip():\n\ config["accounts"] = [\n\ {\n\ "email": t.strip(),\n\ "password": "",\n\ "token": t.strip()\n\ } for t in tokens.split(",") if t.strip()\n\ ]\n\ \n\ # 写入新配置\n\ with open("config.json", "w") as f:\n\ json.dump(config, f, indent=2)\n\ ' > generate_config.py && chmod +x generate_config.py # 安装依赖 RUN pip install --no-cache-dir -r requirements.txt # 替换路由路径 RUN sed -i 's|@app.post("/v1/|@app.post("/deep/v1/|g' app.py && \ sed -i 's|@app.get("/v1/|@app.get("/deep/v1/|g' app.py # 确保文件权限正确 RUN chmod 777 /app && \ chmod 666 config.json # 创建启动脚本 RUN echo '#!/bin/sh\n\ python generate_config.py\n\ echo "==========================================="\n\ echo "Current config.json content:"\n\ echo "==========================================="\n\ cat config.json\n\ echo "==========================================="\n\ exec python app.py\n\ ' > entrypoint.sh && chmod +x entrypoint.sh EXPOSE 5001 ENTRYPOINT ["./entrypoint.sh"]