109 lines
4.1 KiB
PowerShell
109 lines
4.1 KiB
PowerShell
# Test new Docker mirror sources
|
|
param(
|
|
[string]$Server = "45.249.208.118",
|
|
[string]$User = "root",
|
|
[string]$Password = "lxvhNYFZ4160"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Test New Docker Mirror Sources" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
$plinkPath = "C:\Program Files\PuTTY\plink.exe"
|
|
$pscpPath = "C:\Program Files\PuTTY\pscp.exe"
|
|
|
|
if (-not (Test-Path $plinkPath) -or -not (Test-Path $pscpPath)) {
|
|
Write-Host "Error: plink.exe or pscp.exe not found" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# New mirrors to test
|
|
$mirrors = @(
|
|
"https://docker.m.daocloud.io",
|
|
"https://mirror.ccs.tencentyun.com",
|
|
"https://registry.docker-cn.com"
|
|
)
|
|
|
|
$workingMirror = $null
|
|
|
|
foreach ($mirror in $mirrors) {
|
|
Write-Host "Testing: $mirror" -ForegroundColor Yellow
|
|
Write-Host " Configuring Docker daemon..." -ForegroundColor Gray
|
|
|
|
# Create daemon.json with this mirror
|
|
$daemonJson = @"
|
|
{
|
|
"registry-mirrors": ["$mirror"]
|
|
}
|
|
"@
|
|
|
|
$tempDaemonJson = Join-Path $env:TEMP "daemon-$(Get-Random).json"
|
|
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
|
|
$bytes = $utf8NoBom.GetBytes($daemonJson)
|
|
[System.IO.File]::WriteAllBytes($tempDaemonJson, $bytes)
|
|
|
|
# Upload daemon.json
|
|
$pscpCmd = "`"$pscpPath`" -pw `"$Password`" -batch `"$tempDaemonJson`" ${User}@${Server}:/tmp/daemon.json"
|
|
$uploadResult = cmd /c $pscpCmd 2>&1
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host " ✗ Failed to upload daemon.json" -ForegroundColor Red
|
|
Remove-Item $tempDaemonJson -Force -ErrorAction SilentlyContinue
|
|
continue
|
|
}
|
|
|
|
# Apply configuration and restart Docker
|
|
Write-Host " Restarting Docker..." -ForegroundColor Gray
|
|
$applyCmd = "sudo cp /tmp/daemon.json /etc/docker/daemon.json && sudo systemctl restart docker && sleep 5 && echo 'Docker restarted'"
|
|
$plinkCmd = "`"$plinkPath`" -ssh -pw `"$Password`" -batch ${User}@${Server} `"$applyCmd`""
|
|
$applyResult = cmd /c $plinkCmd 2>&1
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host " ✗ Failed to restart Docker" -ForegroundColor Red
|
|
Write-Host $applyResult -ForegroundColor Red
|
|
Remove-Item $tempDaemonJson -Force -ErrorAction SilentlyContinue
|
|
continue
|
|
}
|
|
|
|
# Test pulling the image
|
|
Write-Host " Testing image pull..." -ForegroundColor Gray
|
|
$testCmd = "timeout 30 docker pull node:18-alpine 2>&1"
|
|
$plinkCmd = "`"$plinkPath`" -ssh -pw `"$Password`" -batch ${User}@${Server} `"$testCmd`""
|
|
$pullResult = cmd /c $plinkCmd 2>&1
|
|
|
|
# Check if pull was successful
|
|
if ($pullResult -match "Downloaded|Pulled|Image is up to date|already exists" -or $pullResult -match "18-alpine: Pulling from library/node") {
|
|
Write-Host " ✓ SUCCESS! Image pull working with $mirror" -ForegroundColor Green
|
|
Write-Host " Pull output:" -ForegroundColor Gray
|
|
Write-Host $pullResult -ForegroundColor Gray
|
|
$workingMirror = $mirror
|
|
Remove-Item $tempDaemonJson -Force -ErrorAction SilentlyContinue
|
|
break
|
|
} else {
|
|
Write-Host " ✗ Failed to pull image" -ForegroundColor Red
|
|
Write-Host " Error output:" -ForegroundColor Gray
|
|
Write-Host $pullResult -ForegroundColor Red
|
|
}
|
|
|
|
Remove-Item $tempDaemonJson -Force -ErrorAction SilentlyContinue
|
|
Write-Host ""
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
if ($workingMirror) {
|
|
Write-Host "Found working mirror: $workingMirror" -ForegroundColor Green
|
|
Write-Host "Docker daemon.json has been updated with this mirror" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "You can now deploy using:" -ForegroundColor Yellow
|
|
Write-Host " .\scripts\deploy\deploy-with-password.ps1" -ForegroundColor White
|
|
} else {
|
|
Write-Host "No working mirror found" -ForegroundColor Red
|
|
Write-Host "All tested mirrors failed" -ForegroundColor Red
|
|
}
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|