quality-inspection-platform/start_project.command
qihongkun f5143aee09 feat: 添加 Docker 部署支持和 MCP 原生集成
- 添加 Dockerfile、docker-compose.yml 和 Jenkins 流水线配置
- 新增 MCP 原生集成模块 (mcp_native.py)
- 移除旧的 mcp_bridge.py,更新依赖和文档
- 添加部署文档 (Docker 和服务器部署指南)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-25 14:21:43 +08:00

142 lines
3.5 KiB
Bash
Executable File

#!/bin/zsh
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
BACKEND_PORT=8000
FRONTEND_PORT=5173
VENV_PYTHON="$ROOT_DIR/.venv/bin/python"
require_file() {
local path="$1"
local message="$2"
if [[ ! -e "$path" ]]; then
echo "$message"
read -r -k 1 "?按任意键关闭..."
exit 1
fi
}
require_command() {
local name="$1"
if ! command -v "$name" >/dev/null 2>&1; then
echo "缺少命令: $name"
read -r -k 1 "?按任意键关闭..."
exit 1
fi
}
ensure_venv() {
if [[ ! -x "$VENV_PYTHON" ]]; then
echo "创建 Python 虚拟环境 (.venv)..."
require_command python3
python3 -m venv "$ROOT_DIR/.venv"
fi
if ! "$VENV_PYTHON" -c "import fastapi, mcp, uvicorn" >/dev/null 2>&1; then
echo "安装/更新 Python 依赖 (requirements.txt)..."
"$VENV_PYTHON" -m pip install -r "$ROOT_DIR/requirements.txt"
fi
if ! "$VENV_PYTHON" -c "import fastapi, mcp, uvicorn" >/dev/null 2>&1; then
echo "Python 依赖安装失败,请检查网络或手动执行:"
echo " $VENV_PYTHON -m pip install -r requirements.txt"
read -r -k 1 "?按任意键关闭..."
exit 1
fi
}
is_port_listening() {
local port="$1"
lsof -iTCP:"$port" -sTCP:LISTEN -t >/dev/null 2>&1
}
wait_for_http() {
local url="$1"
local max_attempts="$2"
local attempt=1
while (( attempt <= max_attempts )); do
if curl -fsS "$url" >/dev/null 2>&1; then
return 0
fi
sleep 1
(( attempt++ ))
done
return 1
}
open_backend_terminal() {
osascript - "$ROOT_DIR" <<'APPLESCRIPT'
on run argv
set rootDir to item 1 of argv
tell application "Terminal"
activate
do script "cd " & quoted form of rootDir & " && exec ./.venv/bin/python -m uvicorn app.main:app --host 127.0.0.1 --port 8000"
end tell
end run
APPLESCRIPT
}
open_frontend_terminal() {
osascript - "$ROOT_DIR" <<'APPLESCRIPT'
on run argv
set rootDir to item 1 of argv
tell application "Terminal"
activate
do script "cd " & quoted form of (rootDir & "/frontend-admin") & " && exec npm run dev -- --host 0.0.0.0 --port 5173"
end tell
end run
APPLESCRIPT
}
require_file "$ROOT_DIR/frontend-admin/package.json" "未找到前端工程: frontend-admin/package.json"
require_file "$ROOT_DIR/requirements.txt" "未找到 requirements.txt"
require_command npm
require_command curl
require_command lsof
require_command osascript
ensure_venv
if ! is_port_listening "$BACKEND_PORT"; then
echo "启动后端..."
open_backend_terminal
else
echo "后端已在 $BACKEND_PORT 端口运行"
fi
if ! is_port_listening "$FRONTEND_PORT"; then
echo "启动前端..."
open_frontend_terminal
else
echo "前端已在 $FRONTEND_PORT 端口运行"
fi
echo "等待服务就绪..."
if ! wait_for_http "http://127.0.0.1:$BACKEND_PORT/health" 45; then
echo "后端启动失败,请检查新打开的 Terminal 窗口"
echo "常见原因: 依赖未装全 → 执行: .venv/bin/python -m pip install -r requirements.txt"
read -r -k 1 "?按任意键关闭..."
exit 1
fi
if ! wait_for_http "http://127.0.0.1:$FRONTEND_PORT/" 45; then
echo "前端启动失败,请检查新打开的 Terminal 窗口"
echo "常见原因: 未 npm install → 在 frontend-admin 目录执行 npm install"
read -r -k 1 "?按任意键关闭..."
exit 1
fi
open "http://127.0.0.1:$FRONTEND_PORT/"
echo
echo "启动成功"
echo "前端: http://127.0.0.1:$FRONTEND_PORT/"
echo "后端: http://127.0.0.1:$BACKEND_PORT/"
echo "MCP: http://127.0.0.1:$BACKEND_PORT/mcp"
echo
read -r -k 1 "?按任意键关闭..."