File size: 2,355 Bytes
5678c30
 
 
 
 
 
 
 
f70be6f
 
5678c30
 
 
 
 
 
 
 
 
 
8320443
 
5678c30
 
 
 
 
cc50d8e
 
 
 
 
 
5678c30
 
 
 
 
e9c4828
 
96928b2
622794b
 
72c31e0
e9c4828
67b2006
 
 
df40561
622794b
 
 
 
5678c30
 
 
 
cc50d8e
5678c30
 
 
 
 
 
622794b
 
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
# 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"]