fix: 添加setup.sh环境安装脚本, 修复start.sh依赖检查
- 新增 setup.sh: 一键安装 Node.js/Python依赖/构建前端/创建.env - start.sh: 增加 Python 依赖检查, npx 不可用时给出明确提示 - 解决新机器上 npx not found 和 backend.main import 失败问题
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
# K8S 智能诊断平台 - 环境安装脚本
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
echo "========================================="
|
||||
echo " K8S 智能诊断平台 - 环境安装"
|
||||
echo "========================================="
|
||||
|
||||
# 1. 检查 Node.js
|
||||
if ! command -v node &>/dev/null; then
|
||||
echo "📦 安装 Node.js 20.x ..."
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
||||
apt-get install -y nodejs
|
||||
fi
|
||||
echo "✅ Node.js: $(node -v)"
|
||||
echo "✅ npm: $(npm -v)"
|
||||
|
||||
# 2. 安装前端依赖
|
||||
echo "📦 安装前端依赖..."
|
||||
cd frontend
|
||||
npm install --include=dev
|
||||
cd ..
|
||||
|
||||
# 3. 安装 Python 依赖
|
||||
echo "📦 安装 Python 依赖..."
|
||||
if command -v pip3 &>/dev/null; then
|
||||
pip3 install fastapi uvicorn kubernetes httpx python-dotenv
|
||||
elif command -v pip &>/dev/null; then
|
||||
pip install fastapi uvicorn kubernetes httpx python-dotenv
|
||||
else
|
||||
apt-get install -y python3-pip
|
||||
pip3 install fastapi uvicorn kubernetes httpx python-dotenv
|
||||
fi
|
||||
echo "✅ Python 依赖安装完成"
|
||||
|
||||
# 4. 构建前端
|
||||
echo "📦 构建前端..."
|
||||
cd frontend && npx vite build && cd ..
|
||||
echo "✅ 前端构建完成"
|
||||
|
||||
# 5. 创建 .env (如果不存在)
|
||||
if [ ! -f .env ]; then
|
||||
cat > .env << 'EOF'
|
||||
AI_API_BASE=http://localhost:8648/v1
|
||||
AI_API_KEY=hermes
|
||||
AI_MODEL=qwen3.8-max-preview
|
||||
PORT=8900
|
||||
KUBECONFIG_PATH=
|
||||
EOF
|
||||
echo "✅ 已创建 .env 配置文件 (请按需修改 AI 接口配置)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "========================================="
|
||||
echo " 安装完成!运行 ./start.sh 启动服务"
|
||||
echo "========================================="
|
||||
Reference in New Issue
Block a user