File size: 2,274 Bytes
bf9e111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20d5945
bf9e111
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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"]