CLIProxyAPI / Dockerfile
asemxin
Use HF persistent storage for auth data
e9c4828
# Build stage
FROM golang:1.24-alpine AS builder
WORKDIR /app
# Install git for go mod download
RUN apk add --no-cache git
# Clone the repository at v6.7.7
RUN git clone --branch v6.7.7 --depth 1 https://github.com/router-for-me/CLIProxyAPI.git .
ARG VERSION=dev
ARG COMMIT=none
ARG BUILD_DATE=unknown
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X 'main.Version=${VERSION}' -X 'main.Commit=${COMMIT}' -X 'main.BuildDate=${BUILD_DATE}'" -o ./CLIProxyAPI ./cmd/server/
# Runtime stage
FROM alpine:3.22.0
RUN apk add --no-cache tzdata curl
# Create non-root user for HF Spaces
RUN adduser -D -u 1000 user
RUN mkdir -p /CLIProxyAPI && chown -R user:user /CLIProxyAPI
# Download management panel to static directory
RUN mkdir -p /CLIProxyAPI/static && \
curl -L -o /CLIProxyAPI/static/management.html \
"https://github.com/router-for-me/Cli-Proxy-API-Management-Center/releases/download/v1.2.6/management.html" && \
chown -R user:user /CLIProxyAPI/static
COPY --from=builder /app/CLIProxyAPI /CLIProxyAPI/CLIProxyAPI
COPY --from=builder /app/config.example.yaml /CLIProxyAPI/config.example.yaml
WORKDIR /CLIProxyAPI
# Create auth directory in persistent storage
RUN mkdir -p /data/.cli-proxy-api && chown -R user:user /data/.cli-proxy-api
RUN echo 'host: "0.0.0.0"' > /CLIProxyAPI/config.yaml && \
echo 'port: 7860' >> /CLIProxyAPI/config.yaml && \
echo 'debug: false' >> /CLIProxyAPI/config.yaml && \
echo 'auth-dir: "/data/.cli-proxy-api"' >> /CLIProxyAPI/config.yaml && \
echo 'remote-management:' >> /CLIProxyAPI/config.yaml && \
echo ' allow-remote: true' >> /CLIProxyAPI/config.yaml && \
echo ' disable-control-panel: false' >> /CLIProxyAPI/config.yaml && \
echo ' panel-github-repository: "https://github.com/router-for-me/Cli-Proxy-API-Management-Center"' >> /CLIProxyAPI/config.yaml && \
echo 'api-keys:' >> /CLIProxyAPI/config.yaml && \
echo ' - "default-key"' >> /CLIProxyAPI/config.yaml && \
chown user:user /CLIProxyAPI/config.yaml
# HF Spaces requires port 7860
EXPOSE 7860
ENV TZ=Asia/Shanghai
ENV MANAGEMENT_STATIC_PATH=/CLIProxyAPI/static/management.html
RUN cp /usr/share/zoneinfo/${TZ} /etc/localtime && echo "${TZ}" > /etc/timezone
# Switch to non-root user
USER user
# Start with config file
CMD ["./CLIProxyAPI", "-config", "/CLIProxyAPI/config.yaml"]