FROM debian:bookworm-slim # 安装基础工具 RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ bash \ && rm -rf /var/lib/apt/lists/* ENV TZ=Asia/Shanghai WORKDIR /app # ---- 下载并稳健解压 CLIProxyAPI ---- RUN set -eux; \ ARCH=$(dpkg --print-architecture); \ case "$ARCH" in \ amd64) CLI_ARCH=amd64 ;; \ arm64) CLI_ARCH=arm64 ;; \ *) echo "Unsupported architecture: $ARCH" >&2; exit 1 ;; \ esac; \ DOWNLOAD_URL=$(curl -fsSL https://api.github.com/repos/router-for-me/CLIProxyAPI/releases/latest \ | grep "browser_download_url.*CLIProxyAPI_.*_linux_${CLI_ARCH}\.tar\.gz" \ | head -n 1 | cut -d '"' -f 4); \ echo "Downloading: $DOWNLOAD_URL"; \ curl -fsSL "$DOWNLOAD_URL" -o /tmp/cli-proxy-api.tar.gz; \ mkdir -p /tmp/cpa-extract; \ tar -xzf /tmp/cli-proxy-api.tar.gz -C /tmp/cpa-extract; \ # 同时匹配 CLIProxyAPI 和 cli-proxy-api 两种大小写形式 BIN_PATH=$(find /tmp/cpa-extract -type f \( -name "CLIProxyAPI" -o -name "cli-proxy-api" \) | head -n 1); \ if [ -z "$BIN_PATH" ]; then \ echo "ERROR: Binary not found in archive. Extracted files:"; \ find /tmp/cpa-extract -type f; \ exit 1; \ fi; \ cp "$BIN_PATH" /app/cli-proxy-api; \ chmod +x /app/cli-proxy-api; \ rm -rf /tmp/cpa-extract /tmp/cli-proxy-api.tar.gz # ---- 配置文件(你必须提供 config.yaml) ---- COPY config.yaml /app/config.yaml RUN cp /app/config.yaml /app/config.example.yaml # ---- 创建必要目录(沿用你原来的结构) ---- RUN mkdir -p /tmp/.cli-proxy-api /tmp/logs /tmp/pg_cache/pgstore \ && chmod -R 777 /tmp # ---- Hugging Face Spaces 要求:UID 1000 非 root 用户 ---- RUN useradd -m -u 1000 user \ && chown -R user:user /app USER user EXPOSE 7860 # ---- 启动命令:强制监听 7860 ---- CMD ["/app/cli-proxy-api", "--config", "/app/config.yaml", "0.0.0.0:7860"]