| # Build stage | |
| FROM golang:1.23-alpine AS builder | |
| # Install build dependencies | |
| RUN apk add --no-cache git | |
| WORKDIR /app | |
| # Copy go.mod and go.sum and download dependencies | |
| COPY go.mod go.sum ./ | |
| RUN go mod download | |
| # Copy the entire source code | |
| COPY . . | |
| # Build the binary | |
| RUN go build -o main ./cmd/server | |
| # Final stage | |
| FROM debian:stable-slim | |
| # Install CA certificates for HTTPS requests | |
| RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* | |
| # Create a non-root user | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| WORKDIR /app | |
| # Copy the binary and necessary runtime files | |
| COPY --from=builder --chown=user /app/main /app/cli-proxy-api-plus | |
| COPY --chown=user config.yaml /app/config.yaml | |
| COPY --chown=user static /app/static | |
| COPY --chown=user auth /app/auth | |
| # Ensure the binary is executable | |
| RUN chmod +x /app/cli-proxy-api-plus | |
| # CLIProxyAPI runs on port 7860 for HF Spaces | |
| EXPOSE 7860 | |
| # Start the proxy server | |
| CMD ["./cli-proxy-api-plus", "-config", "config.yaml"] | |