FROM golang:1.26-alpine AS builder ARG CLIPROXY_REPO=https://github.com/xiubia/CLIProxyAPI.git ARG CLIPROXY_REF=main RUN apk add --no-cache bash ca-certificates git WORKDIR /src RUN git clone --depth 1 --branch "${CLIPROXY_REF}" "${CLIPROXY_REPO}" CLIProxyAPI WORKDIR /src/CLIProxyAPI RUN go build -o /out/cli-proxy-api ./cmd/server FROM alpine:3.22 USER root # Install runtime dependencies required by the Space container. RUN apk add --no-cache bash ca-certificates libc6-compat gcompat WORKDIR /app # Copy the compiled binary into the Hugging Face runtime path. COPY --from=builder /out/cli-proxy-api ./cli-proxy-api RUN chmod +x ./cli-proxy-api # Create writable runtime directories for auth, logs, and pg cache. RUN mkdir -p /tmp/.cli-proxy-api /tmp/logs /tmp/pg_cache/pgstore \ && chmod -R 777 /tmp # Copy the runtime configuration into the container. COPY config.yaml /app/config.yaml # Keep config.example.yaml available because the binary expects it at startup. RUN cp /app/config.yaml /app/config.example.yaml ENV TZ=Asia/Shanghai EXPOSE 7860 # Run the proxy directly without an additional web server. CMD ["./cli-proxy-api", "--config", "/app/config.yaml"]