# ============================================ # 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"]