File size: 2,069 Bytes
c1a43bf
 
 
6cace42
 
96e1383
 
 
 
 
6cace42
c1a43bf
 
 
 
 
 
 
 
 
 
 
 
 
96e1383
c1a43bf
 
 
 
 
 
 
 
 
96e1383
f74ea9e
 
c1a43bf
 
 
 
6cace42
f74ea9e
c1a43bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f74ea9e
c1a43bf
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
# ============================================
# CLIProxyAPI Plus - Hugging Face Spaces Dockerfile
# ============================================
# 此 Dockerfile 專為 HF Spaces 設計
# 
# 運行模式:
# 1. 完整模式(Go + Streamlit):需要預先構建 CLIProxyAPIPlus 二進制
# 2. 僅 Streamlit 模式:不需要 Go 二進制,僅運行前端 UI
#
# 構建 Go 二進制(在專案根目錄執行):
#   GOOS=linux GOARCH=amd64 go build -o hf-spaces/CLIProxyAPIPlus ./cmd/server/
# ============================================

FROM python:3.11-slim-bookworm

LABEL maintainer="CLIProxyAPI Plus"
LABEL description="CLI Proxy API with Streamlit UI for Hugging Face Spaces"

# 安裝系統依賴
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    wget \
    tzdata \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# 創建目錄結構
RUN mkdir -p /app/go-server \
    && mkdir -p /app/streamlit \
    && mkdir -p /app/config \
    && mkdir -p /app/auths \
    && mkdir -p /root/.cli-proxy-api \
    && mkdir -p /app/logs

# 複製 Streamlit 應用(必須存在)
COPY streamlit_app/ /app/streamlit/
COPY requirements.txt /app/streamlit/

# 安裝 Python 依賴
RUN pip install --no-cache-dir -r /app/streamlit/requirements.txt

# 複製啟動腳本
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

# 設置環境變數
ENV TZ=Asia/Shanghai \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    STREAMLIT_SERVER_PORT=7860 \
    STREAMLIT_SERVER_ADDRESS=0.0.0.0 \
    STREAMLIT_SERVER_HEADLESS=true \
    STREAMLIT_SERVER_ENABLE_CORS=false \
    STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION=false \
    STREAMLIT_BROWSER_GATHER_USAGE_STATS=false \
    API_BASE_URL=http://localhost:8317 \
    HOME=/root

# HF Spaces 暴露端口 (7860 是 HF Spaces 默認端口)
EXPOSE 7860

# 健康檢查
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:7860/_stcore/health || exit 1

# 啟動容器
ENTRYPOINT ["/app/entrypoint.sh"]