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

Upload 11 files

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -14
  2. entrypoint.sh +32 -17
  3. supervisord.conf +11 -8
Dockerfile CHANGED
@@ -2,10 +2,12 @@
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
 
@@ -16,13 +18,11 @@ LABEL description="CLI Proxy API with Streamlit UI for Hugging Face Spaces"
16
 
17
  # 安裝系統依賴
18
  RUN apt-get update && apt-get install -y --no-install-recommends \
19
- supervisor \
20
  curl \
21
  wget \
22
  tzdata \
23
  ca-certificates \
24
- && rm -rf /var/lib/apt/lists/* \
25
- && mkdir -p /var/log/supervisor
26
 
27
  # 創建目錄結構
28
  RUN mkdir -p /app/go-server \
@@ -32,20 +32,13 @@ RUN mkdir -p /app/go-server \
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
 
2
  # CLIProxyAPI Plus - Hugging Face Spaces Dockerfile
3
  # ============================================
4
  # 此 Dockerfile 專為 HF Spaces 設計
 
5
  #
6
+ # 運行模式
7
+ # 1. 完整模式Go + Streamlit):需要預先構建 CLIProxyAPIPlus 二進制
8
+ # 2. 僅 Streamlit 模式:不需要 Go 二進制,僅運行前端 UI
9
+ #
10
+ # 構建 Go 二進制(在專案根目錄執行):
11
  # GOOS=linux GOARCH=amd64 go build -o hf-spaces/CLIProxyAPIPlus ./cmd/server/
12
  # ============================================
13
 
 
18
 
19
  # 安裝系統依賴
20
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
21
  curl \
22
  wget \
23
  tzdata \
24
  ca-certificates \
25
+ && rm -rf /var/lib/apt/lists/*
 
26
 
27
  # 創建目錄結構
28
  RUN mkdir -p /app/go-server \
 
32
  && mkdir -p /root/.cli-proxy-api \
33
  && mkdir -p /app/logs
34
 
35
+ # 複製 Streamlit 應用必須存在
 
 
 
 
36
  COPY streamlit_app/ /app/streamlit/
37
  COPY requirements.txt /app/streamlit/
38
 
39
  # 安裝 Python 依賴
40
  RUN pip install --no-cache-dir -r /app/streamlit/requirements.txt
41
 
 
 
 
42
  # 複製啟動腳本
43
  COPY entrypoint.sh /app/entrypoint.sh
44
  RUN chmod +x /app/entrypoint.sh
entrypoint.sh CHANGED
@@ -3,21 +3,24 @@
3
  # Entrypoint Script for Hugging Face Spaces
4
  # ============================================
5
 
6
- set -e
7
-
8
  echo "============================================"
9
  echo "CLIProxyAPI Plus - Hugging Face Spaces"
10
  echo "============================================"
11
 
12
- # 生成配置文件(從環境變數)
13
- if [ ! -f /app/config/config.yaml ] || [ "$GENERATE_CONFIG" = "true" ]; then
14
- echo "Generating configuration from environment..."
15
- cp /app/config/config.yaml /app/config/config.yaml.bak 2>/dev/null || true
16
-
17
- # 如果有環境變數,生成配置
18
- if [ -n "$API_KEYS" ]; then
19
- echo "API Keys configured from environment"
20
- fi
 
 
 
 
 
21
  fi
22
 
23
  # 創建必要的目錄
@@ -31,11 +34,23 @@ chmod -R 755 /app
31
  # 顯示環境資訊
32
  echo ""
33
  echo "Environment Information:"
34
- echo " - API Server Port: 8317 (internal)"
35
- echo " - Streamlit Port: 7860 (public)"
36
- echo " - Timezone: $TZ"
 
 
 
 
 
 
 
37
  echo ""
38
 
39
- # 啟動 Supervisor
40
- echo "Starting services via supervisord..."
41
- exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
 
 
 
 
 
 
3
  # Entrypoint Script for Hugging Face Spaces
4
  # ============================================
5
 
 
 
6
  echo "============================================"
7
  echo "CLIProxyAPI Plus - Hugging Face Spaces"
8
  echo "============================================"
9
 
10
+ # 檢查 Go 二進制是否存在
11
+ GO_BINARY="/app/go-server/CLIProxyAPIPlus"
12
+ if [ -f "$GO_BINARY" ]; then
13
+ echo "✓ Go API Server found: $GO_BINARY"
14
+ chmod +x "$GO_BINARY"
15
+ # 啟動 Go 服務器
16
+ echo "Starting Go API Server..."
17
+ /app/go-server/CLIProxyAPIPlus &
18
+ export GO_SERVER_PID=$!
19
+ export HAS_GO_SERVER=true
20
+ else
21
+ echo "⚠ Go API Server not found - Running in Streamlit-only mode"
22
+ echo " To enable full mode, build and include CLIProxyAPIPlus binary"
23
+ export HAS_GO_SERVER=false
24
  fi
25
 
26
  # 創建必要的目錄
 
34
  # 顯示環境資訊
35
  echo ""
36
  echo "Environment Information:"
37
+ if [ "$HAS_GO_SERVER" = "true" ]; then
38
+ echo " - Mode: Full (Go API + Streamlit)"
39
+ echo " - API Server Port: 8317 (internal)"
40
+ echo " - Go Server PID: $GO_SERVER_PID"
41
+ else
42
+ echo " - Mode: Streamlit-only (no Go backend)"
43
+ echo " - API Server: Not available"
44
+ fi
45
+ echo " - Streamlit Port: 7860 (public)"
46
+ echo " - Timezone: $TZ"
47
  echo ""
48
 
49
+ # 啟動 Streamlit
50
+ echo "Starting Streamlit..."
51
+ exec streamlit run /app/streamlit/app.py \
52
+ --server.port=7860 \
53
+ --server.address=0.0.0.0 \
54
+ --server.headless=true \
55
+ --server.enableCORS=false \
56
+ --server.enableXsrfProtection=false
supervisord.conf CHANGED
@@ -13,12 +13,13 @@ logfile_maxbytes=10MB
13
  logfile_backups=3
14
 
15
  ; ============================================
16
- ; Go API Server - CLIProxyAPI Plus
 
17
  ; ============================================
18
  [program:go-server]
19
  command=/app/go-server/CLIProxyAPIPlus
20
  directory=/app/go-server
21
- autostart=true
22
  autorestart=true
23
  startsecs=10
24
  stopwaitsecs=30
@@ -34,7 +35,7 @@ stderr_logfile_backups=3
34
  environment=HOME="/root",DEPLOY="true"
35
 
36
  ; ============================================
37
- ; Streamlit Frontend
38
  ; ============================================
39
  [program:streamlit]
40
  command=streamlit run /app/streamlit/app.py --server.port=7860 --server.address=0.0.0.0
@@ -52,12 +53,14 @@ stdout_logfile_backups=3
52
  stderr_logfile=/var/log/supervisor/streamlit-error.log
53
  stderr_logfile_maxbytes=10MB
54
  stderr_logfile_backups=3
55
- environment=HOME="/root",STREAMLIT_SERVER_PORT="7860",STREAMLIT_SERVER_ADDRESS="0.0.0.0",STREAMLIT_SERVER_HEADLESS="true"
56
 
57
  ; ============================================
58
- ; Event Listeners
59
  ; ============================================
60
- [eventlistener:process_exit]
61
- command=bash -c "echo 'Process exited'"
62
- events=PROCESS_STATE_EXITED
63
  buffer_size=100
 
 
 
13
  logfile_backups=3
14
 
15
  ; ============================================
16
+ ; Go API Server - CLIProxyAPI Plus (Optional)
17
+ ; Only starts if CLIProxyAPIPlus binary exists
18
  ; ============================================
19
  [program:go-server]
20
  command=/app/go-server/CLIProxyAPIPlus
21
  directory=/app/go-server
22
+ autostart=false
23
  autorestart=true
24
  startsecs=10
25
  stopwaitsecs=30
 
35
  environment=HOME="/root",DEPLOY="true"
36
 
37
  ; ============================================
38
+ ; Streamlit Frontend (Always runs)
39
  ; ============================================
40
  [program:streamlit]
41
  command=streamlit run /app/streamlit/app.py --server.port=7860 --server.address=0.0.0.0
 
53
  stderr_logfile=/var/log/supervisor/streamlit-error.log
54
  stderr_logfile_maxbytes=10MB
55
  stderr_logfile_backups=3
56
+ environment=HOME="/root",STREAMLIT_SERVER_HEADLESS="true"
57
 
58
  ; ============================================
59
+ ; Event Listener for Go Server Auto-Start
60
  ; ============================================
61
+ [eventlistener:go_server_checker]
62
+ command=bash -c "if [ -f /app/go-server/CLIProxyAPIPlus ]; then supervisorctl start go-server; fi"
63
+ events=PROCESS_STATE_RUNNING
64
  buffer_size=100
65
+ stdout_logfile=/var/log/supervisor/go-server-checker.log
66
+ stderr_logfile=/var/log/supervisor/go-server-checker-error.log