# 验证构建和推送是否成功 # 用途:检查镜像是否已构建并推送到 Registry param( [string]$Tag = "latest", [string]$Registry = "registry.667788.cool" ) Write-Host "=== 验证构建和推送结果 ===" -ForegroundColor Cyan Write-Host "" Write-Host "Registry: $Registry" -ForegroundColor Gray Write-Host "Tag: $Tag" -ForegroundColor Gray Write-Host "" $images = @( "$Registry/wecom-backend:$Tag", "$Registry/wecom-admin:$Tag", "$Registry/wecom-nginx:$Tag" ) $allSuccess = $true # 1. 检查本地镜像 Write-Host "1. 检查本地镜像..." -ForegroundColor Yellow foreach ($image in $images) { $result = docker images $image --format "{{.Repository}}:{{.Tag}}" 2>$null if ($result -and $result -eq $image) { $size = docker images $image --format "{{.Size}}" 2>$null Write-Host " ✓ $image ($size)" -ForegroundColor Green } else { Write-Host " ✗ $image (未找到)" -ForegroundColor Red $allSuccess = $false } } Write-Host "" # 2. 测试 Registry 连接 Write-Host "2. 测试 Registry 连接..." -ForegroundColor Yellow try { $testResult = Test-NetConnection -ComputerName $Registry -Port 443 -InformationLevel Quiet -WarningAction SilentlyContinue 2>$null if ($testResult) { Write-Host " ✓ Registry 网络连接正常" -ForegroundColor Green } else { Write-Host " ⚠ Registry 网络连接可能有问题" -ForegroundColor Yellow } } catch { Write-Host " ⚠ 无法测试网络连接" -ForegroundColor Yellow } Write-Host "" # 3. 测试拉取镜像(验证推送是否成功) Write-Host "3. 测试拉取镜像(验证推送是否成功)..." -ForegroundColor Yellow Write-Host " 提示: 如果镜像已推送,可以尝试拉取验证" -ForegroundColor Gray Write-Host "" foreach ($image in $images) { Write-Host " 测试: $image" -ForegroundColor Gray $pullResult = docker pull $image 2>&1 if ($LASTEXITCODE -eq 0) { Write-Host " ✓ 拉取成功(镜像已推送到 Registry)" -ForegroundColor Green } else { $errorMsg = $pullResult | Select-String -Pattern "error|not found|unauthorized" -CaseSensitive:$false if ($errorMsg) { Write-Host " ✗ 拉取失败: $errorMsg" -ForegroundColor Red Write-Host " 可能原因:" -ForegroundColor Yellow Write-Host " - 镜像尚未推送" -ForegroundColor Gray Write-Host " - Registry 需要认证" -ForegroundColor Gray Write-Host " - 网络连接问题" -ForegroundColor Gray } else { Write-Host " ⚠ 无法验证(可能需要先登录 Registry)" -ForegroundColor Yellow } } Write-Host "" } Write-Host "" # 4. 检查镜像详细信息 Write-Host "4. 镜像详细信息..." -ForegroundColor Yellow foreach ($image in $images) { $localImage = docker images $image --format "{{.Repository}}:{{.Tag}} {{.Size}} {{.CreatedAt}}" 2>$null if ($localImage) { Write-Host " $image" -ForegroundColor Cyan Write-Host " $localImage" -ForegroundColor Gray } } Write-Host "" # 5. 验证镜像内容(可选) Write-Host "5. 验证镜像内容(可选)..." -ForegroundColor Yellow Write-Host " 可以运行以下命令测试镜像:" -ForegroundColor Gray Write-Host "" Write-Host " # 测试 Backend 镜像" -ForegroundColor Gray Write-Host " docker run --rm $Registry/wecom-backend:$Tag python --version" -ForegroundColor Gray Write-Host "" Write-Host " # 测试 Admin 镜像" -ForegroundColor Gray Write-Host " docker run --rm $Registry/wecom-admin:$Tag node --version" -ForegroundColor Gray Write-Host "" Write-Host " # 测试 Nginx 镜像" -ForegroundColor Gray Write-Host " docker run --rm $Registry/wecom-nginx:$Tag nginx -v" -ForegroundColor Gray Write-Host "" # 总结 Write-Host "=== 验证完成 ===" -ForegroundColor Cyan Write-Host "" if ($allSuccess) { Write-Host "✓ 所有镜像已成功构建" -ForegroundColor Green Write-Host "" Write-Host "下一步:" -ForegroundColor Yellow Write-Host " 1. 如果尚未推送,运行: .\scripts\build_and_push.ps1 -Tag $Tag" -ForegroundColor Gray Write-Host " 2. 在服务器上拉取镜像并部署" -ForegroundColor Gray Write-Host " 3. 参考 README_DEPLOY.md 进行部署" -ForegroundColor Gray } else { Write-Host "⚠ 部分镜像未找到,请检查构建日志" -ForegroundColor Yellow Write-Host "" Write-Host "重新构建:" -ForegroundColor Yellow Write-Host " .\scripts\build_and_push.ps1 -Tag $Tag" -ForegroundColor Gray } Write-Host ""