# Dockerfile for Hugging Face Spaces # This Dockerfile is optimized for running CLIProxyAPI with Kiro integration on HF Spaces FROM golang:1.24-alpine AS builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . 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/ FROM python:3.11-slim # Install necessary packages RUN apt-get update && apt-get install -y --no-install-recommends \ tzdata \ ca-certificates \ curl \ && rm -rf /var/lib/apt/lists/* # Create app directory RUN mkdir -p /app # Copy the Go binary from builder COPY --from=builder /app/CLIProxyAPI /app/CLIProxyAPI # Copy config files COPY config.example.yaml /app/config.example.yaml # Copy kiro-gateway for Python-based Kiro authentication utilities (optional) COPY kiro-gateway/requirements.txt /app/kiro-requirements.txt RUN pip install --no-cache-dir -r /app/kiro-requirements.txt 2>/dev/null || true # Copy kiro-gateway source for reference utilities COPY kiro-gateway/kiro /app/kiro/ WORKDIR /app # HF Spaces requires port 7860 EXPOSE 7860 # Set environment variables for HF Spaces ENV TZ=UTC ENV PORT=7860 ENV HOST=0.0.0.0 # Create a startup script that handles HF Spaces configuration RUN echo '#!/bin/sh\n\ set -e\n\ \n\ # Create config from environment variables if provided\n\ # Only KIRO_REFRESH_TOKEN is required - profile-arn is auto-fetched from token refresh\n\ if [ -n "$KIRO_REFRESH_TOKEN" ]; then\n\ cat > /app/config.yaml << EOF\n\ host: "0.0.0.0"\n\ port: 7860\n\ auth-dir: "/app/auth"\n\ debug: ${DEBUG:-false}\n\ \n\ api-keys:\n\ - "${API_KEY:-default-key}"\n\ \n\ kiro-api-key:\n\ - refresh-token: "$KIRO_REFRESH_TOKEN"\n\ region: "${KIRO_REGION:-us-east-1}"\n\ EOF\n\ echo "Config created from environment variables"\n\ elif [ -f /app/config.yaml ]; then\n\ echo "Using existing config.yaml"\n\ else\n\ cp /app/config.example.yaml /app/config.yaml\n\ echo "Using example config"\n\ fi\n\ \n\ mkdir -p /app/auth\n\ \n\ exec ./CLIProxyAPI -config /app/config.yaml\n\ ' > /app/start.sh && chmod +x /app/start.sh CMD ["/app/start.sh"]