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 "========================================="
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# K8S 智能诊断平台 - 一键启动脚本
|
# K8S 智能诊断平台 - 一键启动脚本
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
PORT=${PORT:-8900}
|
PORT=${PORT:-8900}
|
||||||
@@ -24,13 +23,23 @@ if [ -f "$HOME/.kube/config" ]; then
|
|||||||
echo "✅ kubeconfig: ~/.kube/config"
|
echo "✅ kubeconfig: ~/.kube/config"
|
||||||
else
|
else
|
||||||
echo "⚠️ 未找到 ~/.kube/config,诊断将返回空结果"
|
echo "⚠️ 未找到 ~/.kube/config,诊断将返回空结果"
|
||||||
echo " 请将 kubeconfig 放到 ~/.kube/config"
|
fi
|
||||||
|
|
||||||
|
# 检查 Python 依赖
|
||||||
|
if ! python3 -c "import fastapi, uvicorn" 2>/dev/null; then
|
||||||
|
echo "❌ 缺少 Python 依赖,请先运行: ./setup.sh"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 检查前端构建
|
# 检查前端构建
|
||||||
if [ ! -d "frontend/dist" ]; then
|
if [ ! -f "frontend/dist/index.html" ]; then
|
||||||
|
if command -v npx &>/dev/null; then
|
||||||
echo "📦 构建前端..."
|
echo "📦 构建前端..."
|
||||||
cd frontend && npx vite build && cd ..
|
cd frontend && npx vite build && cd ..
|
||||||
|
else
|
||||||
|
echo "❌ 前端未构建且 npx 不可用,请先运行: ./setup.sh"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
Reference in New Issue
Block a user