param( [string]$Environment = "dev" ) $ErrorActionPreference = "Stop" $successCount = 0 $failCount = 0 $warningCount = 0 function Write-Status { param( [string]$Status, [string]$Message ) switch ($Status) { "OK" { Write-Host "✅ $Message" -ForegroundColor Green } "FAIL" { Write-Host "❌ $Message" -ForegroundColor Red } "WARN" { Write-Host "⚠️ $Message" -ForegroundColor Yellow } "INFO" { Write-Host "📋 $Message" -ForegroundColor Cyan } default { Write-Host "$Message" } } } function Test-Path-WithStatus { param( [string]$Path, [string]$Description ) if (Test-Path $Path) { Write-Status "OK" "$Description" $script:successCount++ } else { Write-Status "FAIL" "$Description - 缺失" $script:failCount++ } } Write-Host "`n============================================" -ForegroundColor Cyan Write-Host " 部署前检查脚本 v1.0" -ForegroundColor Cyan Write-Host " 环境: $Environment" -ForegroundColor Cyan Write-Host "============================================`n" -ForegroundColor Cyan Write-Status "INFO" "检查核心脚本..." Test-Path-WithStatus -Path "start.ps1" -Description "快速启动脚本" Test-Path-WithStatus -Path "scripts/deploy.ps1" -Description "统一部署脚本" Test-Path-WithStatus -Path "scripts/utils.ps1" -Description "工具函数库" Test-Path-WithStatus -Path "scripts/build-all.ps1" -Description "本地构建脚本" Test-Path-WithStatus -Path "scripts/pre-deploy-check.ps1" -Description "部署前检查脚本" Write-Status "INFO" "`n检查Jenkins配置..." Test-Path-WithStatus -Path "infrastructure/jenkins/Jenkinsfile" -Description "Jenkins Pipeline配置" Write-Status "INFO" "`n检查环境配置..." Test-Path-WithStatus -Path "infrastructure/compose/.env.aliyun" -Description "阿里云环境变量配置" Test-Path-WithStatus -Path "infrastructure/compose/podman-compose.dev.yml" -Description "开发环境Compose配置" Test-Path-WithStatus -Path "infrastructure/compose/podman-compose.test.yml" -Description "测试环境Compose配置" Test-Path-WithStatus -Path "infrastructure/compose/podman-compose.prod.yml" -Description "生产环境Compose配置" Write-Status "INFO" "`n检查服务目录..." $services = @( 'api-gateway', 'auth-service', 'common-service', 'user-service', 'order-service', 'merchant-service', 'platform-service', 'product-service', 'rider-service', 'upload-service', 'marketing-service', 'map-service' ) foreach ($service in $services) { Test-Path-WithStatus -Path "services/$service" -Description "服务: $service" } Write-Status "INFO" "`n检查前端项目..." Test-Path-WithStatus -Path "frontend/platform_web" -Description "平台端Web" Test-Path-WithStatus -Path "frontend/merchant_web" -Description "商家端Web" Test-Path-WithStatus -Path "frontend/official_website" -Description "官方网站" Test-Path-WithStatus -Path "frontend/user_app" -Description "用户端APP(Flutter)" Test-Path-WithStatus -Path "frontend/rider_app" -Description "骑手端APP(Flutter)" Write-Status "INFO" "`n检查配置文件..." Test-Path-WithStatus -Path "VERSION" -Description "版本号文件" Test-Path-WithStatus -Path "README.md" -Description "项目说明文档" Write-Status "INFO" "`n检查监控配置..." Test-Path-WithStatus -Path "infrastructure/grafana/dashboard-fzx-platform.json" -Description "Grafana监控大盘" Write-Status "INFO" "`n检查镜像仓库配置..." $envFile = "infrastructure/compose/.env.aliyun" if (Test-Path $envFile) { $content = Get-Content $envFile -Raw if ($content -match "IMAGE_REGISTRY=registry\.fengzhongxing\.com") { Write-Status "OK" "镜像仓库已配置为域名: registry.fengzhongxing.com" $successCount++ } else { Write-Status "WARN" "镜像仓库配置可能需要更新" $warningCount++ } if ($content -match "IMAGE_TAG=v1\.15") { Write-Status "OK" "镜像版本标签正确: v1.15.x" $successCount++ } else { Write-Status "WARN" "镜像版本标签可能需要更新" $warningCount++ } } else { Write-Status "FAIL" "环境配置文件缺失" $failCount++ } Write-Host "`n============================================" -ForegroundColor Cyan Write-Host " 检查结果汇总" -ForegroundColor Cyan Write-Host "============================================`n" -ForegroundColor Cyan Write-Status "INFO" "成功: $successCount" Write-Status "INFO" "失败: $failCount" Write-Status "INFO" "警告: $warningCount" if ($failCount -eq 0) { Write-Host "`n🎉 所有检查通过!可以进行部署。" -ForegroundColor Green exit 0 } else { Write-Host "`n❌ 存在 $failCount 项检查失败,请修复后再进行部署。" -ForegroundColor Red exit 1 }