feat: Add embedded backend packaging for all-in-one deployment

- Add backend/run_server.py entry point for embedded deployment
- Add backend/build.py PyInstaller script for backend packaging
- Modify config.py to support frozen executable paths
- Extend client/config.json with backend configuration section
- Add backend sidecar management in Electron main process
- Add Whisper model download progress reporting
- Update build-client.bat with --embedded-backend flag
- Update DEPLOYMENT.md with all-in-one deployment documentation

This enables packaging frontend and backend into a single executable
for simplified enterprise deployment. Backward compatible with
existing separate deployment mode (backend.embedded: false).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
egg
2025-12-17 10:06:29 +08:00
parent b1633fdcff
commit 58f379bc0c
11 changed files with 1003 additions and 17 deletions

View File

@@ -224,6 +224,110 @@ npm start
4. 輸入 `api_url` 參數(例如 `http://192.168.1.100:8000/api`
5. 等待建置完成後下載 artifact
## All-in-One Deployment (全包部署模式)
此模式將前端、後端、Whisper 全部打包成單一執行檔,用戶雙擊即可使用,無需額外設置後端服務。
### 適用場景
- 企業內部部署,簡化用戶操作
- 無法獨立架設後端的環境
- 快速測試和演示
### 打包方式
```batch
# Windows 全包打包
.\scripts\build-client.bat build --embedded-backend --clean
```
### config.json 配置
全包模式需要在 `config.json` 中配置資料庫和 API 金鑰:
```json
{
"apiBaseUrl": "http://localhost:8000/api",
"uploadTimeout": 600000,
"appTitle": "Meeting Assistant",
"whisper": {
"model": "medium",
"device": "cpu",
"compute": "int8"
},
"backend": {
"embedded": true,
"host": "127.0.0.1",
"port": 8000,
"database": {
"host": "mysql.theaken.com",
"port": 33306,
"user": "your_username",
"password": "your_password",
"database": "your_database"
},
"externalApis": {
"authApiUrl": "https://pj-auth-api.vercel.app/api/auth/login",
"difyApiUrl": "https://dify.theaken.com/v1",
"difyApiKey": "app-xxxxxxxxxx",
"difySttApiKey": "app-xxxxxxxxxx"
},
"auth": {
"adminEmail": "admin@example.com",
"jwtSecret": "your_secure_jwt_secret",
"jwtExpireHours": 24
}
}
}
```
### 配置說明
| 區段 | 欄位 | 說明 |
|------|------|------|
| `backend.embedded` | `true`/`false` | 啟用/停用內嵌後端模式 |
| `backend.host` | IP | 後端監聽地址(通常為 127.0.0.1 |
| `backend.port` | 數字 | 後端監聽端口(預設 8000 |
| `backend.database.*` | 各欄位 | MySQL 資料庫連線資訊 |
| `backend.externalApis.*` | 各欄位 | 外部 API 設定認證、Dify |
| `backend.auth.*` | 各欄位 | 認證設定管理員信箱、JWT 金鑰) |
### 啟動流程
1. 用戶雙擊 exe
2. Electron 主程序啟動
3. 讀取 `config.json`
4. 啟動內嵌後端 (FastAPI)
5. 健康檢查等待後端就緒(最多 30 秒)
6. 後端就緒後,載入前端頁面
7. 啟動 Whisper Sidecar
8. 應用就緒
### 向後相容性
此功能完全向後相容,不影響既有部署方式:
| 部署方式 | config.json 設定 | 說明 |
|---------|------------------|------|
| 分離部署(預設) | `backend.embedded: false` | 前端連接遠端後端,使用 `apiBaseUrl` |
| 全包部署(新增) | `backend.embedded: true` | 前端內嵌後端,雙擊即可使用 |
### 安全注意事項
⚠️ **重要**:全包模式的 `config.json` 包含敏感資訊資料庫密碼、API 金鑰),請確保:
1. 不要將含有真實憑證的 config.json 提交到版本控制
2. 部署時由 IT 管理員配置敏感資訊
3. 考慮使用環境變數覆蓋敏感設定(環境變數優先級較高)
### Whisper 模型下載進度
首次運行時Whisper 模型(約 1.5GB)會自動下載。新版本會顯示下載進度:
- `⬇️ Downloading medium: 45% (675/1530 MB)` - 下載中
- `⏳ Loading medium...` - 載入模型中
- `✅ Ready` - 就緒
## Transcription Sidecar
### 1. Setup