Files
OCR/DEPLOY.md
egg f46402f6c9 refactor: simplify deployment - unified env and startup script
- Remove Docker deployment files (1panel doesn't use Docker)
- Unify .env files: .env.example -> .env (single config file)
- Merge start.sh and start-prod.sh into unified start.sh with --prod flag
- Update setup_dev_env.sh to use .env instead of .env.local
- Add DEPLOY.md with 1panel deployment guide

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 15:16:26 +08:00

2.9 KiB
Raw Permalink Blame History

Tool_OCR 佈署指南

本指南說明如何在 1panel 或其他 Linux 環境中佈署 Tool_OCR。

快速佈署

# 1. 複製並配置環境變數
cp .env.example .env
# 編輯 .env 填入實際的資料庫、API 金鑰等配置

# 2. 安裝依賴並初始化
./setup_dev_env.sh

# 3. 啟動服務
./start.sh --prod

詳細步驟

1. 系統需求

  • Ubuntu 20.04+ 或相容的 Linux 發行版
  • Python 3.10+
  • Node.js 18+ (透過 nvm 自動安裝)
  • 至少 4GB RAM
  • 至少 10GB 磁碟空間

2. 環境配置

複製範例配置檔:

cp .env.example .env

編輯 .env 填入實際值:

# 資料庫 (必填)
MYSQL_HOST=your-mysql-host
MYSQL_PORT=3306
MYSQL_USER=your-username
MYSQL_PASSWORD=your-password
MYSQL_DATABASE=your-database

# 服務端口 (由 IT 指派)
BACKEND_PORT=8000
FRONTEND_PORT=5173

# 安全性 (必填,請使用隨機字串)
SECRET_KEY=your-random-secret-key

# 外部認證 (必填)
EXTERNAL_AUTH_API_URL=https://your-auth-api.example.com

# 翻譯 API (選填)
ENABLE_TRANSLATION=true
DIFY_BASE_URL=https://your-dify-instance.example.com/v1
DIFY_API_KEY=your-dify-api-key

# CORS (根據前端 URL 設定)
CORS_ORIGINS=http://localhost:5173

3. 安裝依賴

執行設置腳本:

./setup_dev_env.sh

此腳本會:

  • 安裝系統依賴 (pandoc, fonts, opencv 等)
  • 安裝 Node.js (透過 nvm)
  • 建立 Python 虛擬環境
  • 自動偵測 GPU 並安裝對應的 PaddlePaddle 版本
  • 安裝前端依賴
  • 初始化資料庫

4. 啟動服務

開發模式 (hot-reload):

./start.sh

正式模式 (無 hot-reload多 worker):

./start.sh --prod

自訂端口:

BACKEND_PORT=8088 FRONTEND_PORT=3000 ./start.sh --prod

5. 服務管理

# 查看狀態
./start.sh --status

# 停止服務
./start.sh --stop

# 僅啟動後端
./start.sh backend

# 僅啟動前端
./start.sh frontend

6. 日誌

# 後端日誌
tail -f .pid/backend.log

# 前端日誌
tail -f .pid/frontend.log

1panel 設定

在 1panel 中設定為「應用」或「腳本任務」:

  1. 工作目錄設為專案根目錄
  2. 啟動指令:./start.sh --prod
  3. 停止指令:./start.sh --stop
  4. 環境變數:可在 .env 中配置,或透過 1panel 的環境變數功能設定端口

常見問題

GPU 支援

如果有 NVIDIA GPUsetup_dev_env.sh 會自動偵測並安裝 GPU 版本的 PaddlePaddle。

強制使用 CPU 版本:

./setup_dev_env.sh --cpu-only

資料庫連線失敗

  1. 確認 .env 中的資料庫配置正確
  2. 手動執行資料庫遷移:
    source venv/bin/activate
    cd backend
    alembic upgrade head
    

端口被佔用

檢查並終止佔用端口的程序:

lsof -i :8000  # 檢查後端端口
lsof -i :5173  # 檢查前端端口

或使用不同端口:

BACKEND_PORT=8088 FRONTEND_PORT=3000 ./start.sh --prod