diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..b5a6ba9 --- /dev/null +++ b/setup.sh @@ -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 "=========================================" diff --git a/start.sh b/start.sh index 5cde9c6..b047933 100755 --- a/start.sh +++ b/start.sh @@ -1,7 +1,6 @@ #!/bin/bash # K8S 智能诊断平台 - 一键启动脚本 set -e - cd "$(dirname "$0")" PORT=${PORT:-8900} @@ -24,13 +23,23 @@ if [ -f "$HOME/.kube/config" ]; then echo "✅ kubeconfig: ~/.kube/config" else 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 # 检查前端构建 -if [ ! -d "frontend/dist" ]; then - echo "📦 构建前端..." - cd frontend && npx vite build && cd .. +if [ ! -f "frontend/dist/index.html" ]; then + if command -v npx &>/dev/null; then + echo "📦 构建前端..." + cd frontend && npx vite build && cd .. + else + echo "❌ 前端未构建且 npx 不可用,请先运行: ./setup.sh" + exit 1 + fi fi echo ""