Files
wecom-ai-assistant/scripts/test-registry-connection.ps1
2026-02-05 20:09:07 +08:00

79 lines
2.8 KiB
PowerShell

# 测试私有 Registry 连接
# 用途:验证 Docker Registry 连接和认证
Write-Host "=== 测试私有 Registry 连接 ===" -ForegroundColor Cyan
Write-Host ""
# 读取 Registry 配置
$configFile = ".registry-config"
if (-not (Test-Path $configFile)) {
Write-Host "错误: 配置文件 $configFile 不存在" -ForegroundColor Red
exit 1
}
$config = @{}
Get-Content $configFile | ForEach-Object {
if ($_ -match '^\s*([^#=]+?)\s*=\s*(.+?)\s*$') {
$key = $matches[1].Trim()
$value = $matches[2].Trim()
$config[$key] = $value
}
}
$registryUrl = $config['REGISTRY_URL']
$registryUsername = $config['REGISTRY_USERNAME']
$registryPassword = $config['REGISTRY_PASSWORD']
if (-not $registryUrl -or -not $registryUsername -or -not $registryPassword) {
Write-Host "错误: Registry 配置不完整" -ForegroundColor Red
exit 1
}
Write-Host "配置信息:" -ForegroundColor Cyan
Write-Host " Registry URL: $registryUrl" -ForegroundColor Gray
Write-Host " 用户名: $registryUsername" -ForegroundColor Gray
Write-Host " 密码: ****" -ForegroundColor Gray
Write-Host ""
# 测试网络连接
Write-Host "1. 测试网络连接..." -ForegroundColor Yellow
$testResult = Test-NetConnection -ComputerName $registryUrl -Port 443 -InformationLevel Quiet -WarningAction SilentlyContinue 2>$null
if ($testResult) {
Write-Host "✓ 网络连接正常" -ForegroundColor Green
} else {
Write-Host "⚠ 网络连接可能有问题" -ForegroundColor Yellow
}
Write-Host ""
# 测试 Docker 登录
Write-Host "2. 测试 Docker 登录..." -ForegroundColor Yellow
$loginResult = echo $registryPassword | docker login $registryUrl -u $registryUsername --password-stdin 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host "✓ Docker 登录成功" -ForegroundColor Green
} else {
Write-Host "✗ Docker 登录失败" -ForegroundColor Red
Write-Host " 请检查:" -ForegroundColor Yellow
Write-Host " - Registry URL 是否正确" -ForegroundColor Gray
Write-Host " - 用户名和密码是否正确" -ForegroundColor Gray
Write-Host " - Registry 服务是否正常运行" -ForegroundColor Gray
exit 1
}
Write-Host ""
# 测试 Registry 访问
Write-Host "3. 测试 Registry 访问..." -ForegroundColor Yellow
$images = docker images 2>&1
if ($images -match $registryUrl) {
Write-Host "✓ Registry 访问正常" -ForegroundColor Green
} else {
Write-Host "⚠ 无法验证 Registry 访问(可能需要先推送镜像)" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "=== 测试完成 ===" -ForegroundColor Green
Write-Host ""
Write-Host "Registry 连接正常,可以使用以下命令推送镜像:" -ForegroundColor Cyan
$pushScript = ".\scripts\push-images-to-private-registry.ps1"
Write-Host " $pushScript" -ForegroundColor Gray
Write-Host ""