kines9661 commited on
Commit
6cace42
·
verified ·
1 Parent(s): f74ea9e

Upload 11 files

Browse files
Files changed (3) hide show
  1. DEPLOYMENT.md +42 -5
  2. Dockerfile +12 -38
  3. README.md +31 -7
DEPLOYMENT.md CHANGED
@@ -5,10 +5,11 @@
5
  ## 📋 目錄
6
 
7
  1. [前置需求](#前置需求)
8
- 2. [快速部署](#快速部署)
9
- 3. [配置 Secrets](#配置-secrets)
10
- 4. [使用說明](#使用說明)
11
- 5. [常見問題](#常見問題)
 
12
 
13
  ---
14
 
@@ -20,7 +21,11 @@
20
  - 註冊地址: https://huggingface.co/join
21
  - 建議啟用兩步驗證以保護帳號安全
22
 
23
- 2. **AI 服務提供商帳號**(至少需要一個
 
 
 
 
24
  - [Anthropic Claude](https://console.anthropic.com/)
25
  - [Google AI Studio](https://aistudio.google.com/)
26
  - [GitHub Copilot](https://github.com/features/copilot)
@@ -32,6 +37,38 @@
32
 
33
  ---
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  ## 快速部署
36
 
37
  ### 方法一:從模板創建(推薦)
 
5
  ## 📋 目錄
6
 
7
  1. [前置需求](#前置需求)
8
+ 2. [構建 Go 二進制](#構建-go-二進制)
9
+ 3. [快速部署](#快速部署)
10
+ 4. [配置 Secrets](#配置-secrets)
11
+ 5. [使用說明](#使用說明)
12
+ 6. [常見問題](#常見問題)
13
 
14
  ---
15
 
 
21
  - 註冊地址: https://huggingface.co/join
22
  - 建議啟用兩步驗證以保護帳號安全
23
 
24
+ 2. **Go 編譯環境**(用於構建二進制
25
+ - Go 1.26 或更高版本
26
+ - 下載地址: https://go.dev/dl/
27
+
28
+ 3. **AI 服務提供商帳號**(至少需要一個)
29
  - [Anthropic Claude](https://console.anthropic.com/)
30
  - [Google AI Studio](https://aistudio.google.com/)
31
  - [GitHub Copilot](https://github.com/features/copilot)
 
37
 
38
  ---
39
 
40
+ ## 構建 Go 二進制
41
+
42
+ **重要**:HF Spaces Dockerfile 需要預先構建的 Go 二進制文件。
43
+
44
+ ### 步驟 1:克隆專案
45
+
46
+ ```bash
47
+ git clone https://github.com/router-for-me/CLIProxyAPI.git
48
+ cd CLIProxyAPI
49
+ ```
50
+
51
+ ### 步驟 2:構建 Linux 二進制
52
+
53
+ **Linux/macOS:**
54
+ ```bash
55
+ GOOS=linux GOARCH=amd64 go build -o hf-spaces/CLIProxyAPIPlus ./cmd/server/
56
+ ```
57
+
58
+ **Windows (PowerShell):**
59
+ ```powershell
60
+ $env:GOOS="linux"; $env:GOARCH="amd64"; go build -o hf-spaces/CLIProxyAPIPlus ./cmd/server/
61
+ ```
62
+
63
+ ### 步驟 3:驗證構建
64
+
65
+ ```bash
66
+ ls -la hf-spaces/CLIProxyAPIPlus
67
+ # 應該顯示一個約 20-30MB 的可執行文件
68
+ ```
69
+
70
+ ---
71
+
72
  ## 快速部署
73
 
74
  ### 方法一:從模板創建(推薦)
Dockerfile CHANGED
@@ -1,41 +1,14 @@
1
  # ============================================
2
  # CLIProxyAPI Plus - Hugging Face Spaces Dockerfile
3
  # ============================================
4
- # 此 Dockerfile 所有文件都在構建上下文根目錄
5
- # 適合直接上傳 hf-spaces/ 內容到 HF Space
 
 
 
 
6
  # ============================================
7
 
8
- # ============================================
9
- # Stage 1: 構建 Go 應用
10
- # ============================================
11
- FROM golang:1.26-alpine AS go-builder
12
-
13
- WORKDIR /build
14
-
15
- # 安裝構建依賴
16
- RUN apk add --no-cache git ca-certificates tzdata
17
-
18
- # 複製 Go 模組文件
19
- COPY go.mod go.sum ./
20
- RUN go mod download
21
-
22
- # 複製源碼並構建
23
- COPY . .
24
-
25
- ARG VERSION=hf-spaces
26
- ARG COMMIT=none
27
- ARG BUILD_DATE=unknown
28
-
29
- RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
30
- go build -ldflags="-s -w \
31
- -X 'main.Version=${VERSION}-plus' \
32
- -X 'main.Commit=${COMMIT}' \
33
- -X 'main.BuildDate=${BUILD_DATE}'" \
34
- -o ./CLIProxyAPIPlus ./cmd/server/
35
-
36
- # ============================================
37
- # Stage 2: 最終運行環境
38
- # ============================================
39
  FROM python:3.11-slim-bookworm
40
 
41
  LABEL maintainer="CLIProxyAPI Plus"
@@ -59,20 +32,21 @@ RUN mkdir -p /app/go-server \
59
  && mkdir -p /root/.cli-proxy-api \
60
  && mkdir -p /app/logs
61
 
62
- # 複製 Go 二進制文件(構建階段
63
- COPY --from=go-builder /build/CLIProxyAPIPlus /app/go-server/CLIProxyAPIPlus
 
64
 
65
- # 複製 Streamlit 應用(文件在根目錄)
66
  COPY streamlit_app/ /app/streamlit/
67
  COPY requirements.txt /app/streamlit/
68
 
69
  # 安裝 Python 依賴
70
  RUN pip install --no-cache-dir -r /app/streamlit/requirements.txt
71
 
72
- # 複製 Supervisor 配置(文件在根目錄)
73
  COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
74
 
75
- # 複製啟動腳本(文件在根目錄)
76
  COPY entrypoint.sh /app/entrypoint.sh
77
  RUN chmod +x /app/entrypoint.sh
78
 
 
1
  # ============================================
2
  # CLIProxyAPI Plus - Hugging Face Spaces Dockerfile
3
  # ============================================
4
+ # 此 Dockerfile 專為 HF Spaces
5
+ # 假設用戶上傳 hf-spaces/ 目錄內容到 Space 根目錄
6
+ #
7
+ # 重要:Go 二進制文件需要預先構建並放入此目錄
8
+ # 構建命令(在專案根目錄執行):
9
+ # GOOS=linux GOARCH=amd64 go build -o hf-spaces/CLIProxyAPIPlus ./cmd/server/
10
  # ============================================
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  FROM python:3.11-slim-bookworm
13
 
14
  LABEL maintainer="CLIProxyAPI Plus"
 
32
  && mkdir -p /root/.cli-proxy-api \
33
  && mkdir -p /app/logs
34
 
35
+ # 複製 Go 二進制文件(需要預先構建)
36
+ COPY CLIProxyAPIPlus /app/go-server/CLIProxyAPIPlus
37
+ RUN chmod +x /app/go-server/CLIProxyAPIPlus
38
 
39
+ # 複製 Streamlit 應用
40
  COPY streamlit_app/ /app/streamlit/
41
  COPY requirements.txt /app/streamlit/
42
 
43
  # 安裝 Python 依賴
44
  RUN pip install --no-cache-dir -r /app/streamlit/requirements.txt
45
 
46
+ # 複製 Supervisor 配置
47
  COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
48
 
49
+ # 複製啟動腳本
50
  COPY entrypoint.sh /app/entrypoint.sh
51
  RUN chmod +x /app/entrypoint.sh
52
 
README.md CHANGED
@@ -81,13 +81,15 @@ curl https://{your-space}.hf.space/v1/models
81
 
82
  ```
83
  hf-spaces/
84
- ├── Dockerfile # Docker 構建文件
85
- ├── supervisord.conf # 進程管理配置
86
- ├── entrypoint.sh # 容器入口腳本
87
- ├── requirements.txt # Python 依賴
88
- ├── README.md # 本文件
89
- ── streamlit_app/ # Streamlit 應用
90
- ├── app.py # 主程序
 
 
91
  └── pages/
92
  ├── 1_💬_Chat.py # API 測試頁面
93
  ├── 2_🔑_Auth.py # 認證管理頁面
@@ -95,6 +97,28 @@ hf-spaces/
95
  └── 4_⚙️_Settings.py # 系統設定頁面
96
  ```
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  ## 🏗️ 架構
99
 
100
  ```
 
81
 
82
  ```
83
  hf-spaces/
84
+ ├── Dockerfile # Docker 構建文件
85
+ ├── supervisord.conf # 進程管理配置
86
+ ├── entrypoint.sh # 容器入口腳本
87
+ ├── requirements.txt # Python 依賴
88
+ ├── README.md # 本文件
89
+ ── DEPLOYMENT.md # 詳細部署指南
90
+ ├── CLIProxyAPIPlus # Go 二進制(需預先構建)
91
+ └── streamlit_app/ # Streamlit 應用
92
+ ├── app.py # 主程序
93
  └── pages/
94
  ├── 1_💬_Chat.py # API 測試頁面
95
  ├── 2_🔑_Auth.py # 認證管理頁面
 
97
  └── 4_⚙️_Settings.py # 系統設定頁面
98
  ```
99
 
100
+ ## 🔧 構建 Go 二進制
101
+
102
+ **重要**:部署前需要先構建 Go 二進制文件。
103
+
104
+ ### Linux/macOS
105
+ ```bash
106
+ cd /path/to/CLIProxyAPIPlus
107
+ GOOS=linux GOARCH=amd64 go build -o hf-spaces/CLIProxyAPIPlus ./cmd/server/
108
+ ```
109
+
110
+ ### Windows (PowerShell)
111
+ ```powershell
112
+ cd C:\path\to\CLIProxyAPIPlus
113
+ $env:GOOS="linux"; $env:GOARCH="amd64"; go build -o hf-spaces/CLIProxyAPIPlus ./cmd/server/
114
+ ```
115
+
116
+ ### 驗證構建
117
+ ```bash
118
+ ls -la hf-spaces/CLIProxyAPIPlus
119
+ # 應該顯示一個約 20-30MB 的可執行文件
120
+ ```
121
+
122
  ## 🏗️ 架構
123
 
124
  ```