94 lines
3.3 KiB
PowerShell
94 lines
3.3 KiB
PowerShell
# Fix Docker registry and deploy
|
|
param(
|
|
[string]$Server = "45.249.208.118",
|
|
[string]$User = "root",
|
|
[string]$Password = "lxvhNYFZ4160",
|
|
[string]$ProjectPath = "/root/youyidian-3d"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Fix Docker Registry and Deploy" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Check for plink
|
|
$plinkPath = "C:\Program Files\PuTTY\plink.exe"
|
|
$usePlink = (Test-Path $plinkPath)
|
|
|
|
if (-not $usePlink) {
|
|
Write-Host "Error: plink.exe not found. Please install PuTTY." -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# Step 1: Check current Docker daemon.json
|
|
Write-Host "[1/4] Checking Docker daemon configuration..." -ForegroundColor Yellow
|
|
|
|
$checkCmd = "cat /etc/docker/daemon.json 2>/dev/null || echo 'File not found'"
|
|
if ($usePlink) {
|
|
$plinkCmd = "`"$plinkPath`" -ssh -pw `"$Password`" -batch ${User}@${Server} `"$checkCmd`""
|
|
$result = cmd /c $plinkCmd 2>&1
|
|
Write-Host $result
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# Step 2: Update Docker daemon.json to remove problematic mirrors
|
|
Write-Host "[2/4] Updating Docker daemon configuration..." -ForegroundColor Yellow
|
|
|
|
# Create a new daemon.json without problematic mirrors
|
|
$newDaemonJson = @"
|
|
{
|
|
"registry-mirrors": []
|
|
}
|
|
"@
|
|
|
|
# Save to temp file
|
|
$tempDaemonJson = Join-Path $env:TEMP "daemon-$(Get-Date -Format 'yyyyMMdd-HHmmss').json"
|
|
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
|
|
$bytes = $utf8NoBom.GetBytes($newDaemonJson)
|
|
[System.IO.File]::WriteAllBytes($tempDaemonJson, $bytes)
|
|
|
|
# Upload and apply
|
|
Write-Host " Uploading new daemon.json..." -ForegroundColor Gray
|
|
$pscpPath = "C:\Program Files\PuTTY\pscp.exe"
|
|
$pscpCmd = "`"$pscpPath`" -pw `"$Password`" -batch `"$tempDaemonJson`" ${User}@${Server}:/tmp/daemon.json"
|
|
cmd /c $pscpCmd 2>&1 | Out-Null
|
|
|
|
Write-Host " Applying new configuration..." -ForegroundColor Gray
|
|
$applyCmd = "sudo cp /tmp/daemon.json /etc/docker/daemon.json && sudo systemctl restart docker && echo 'Docker restarted successfully'"
|
|
if ($usePlink) {
|
|
$plinkCmd = "`"$plinkPath`" -ssh -pw `"$Password`" -batch ${User}@${Server} `"$applyCmd`""
|
|
$result = cmd /c $plinkCmd 2>&1
|
|
Write-Host $result
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# Step 3: Wait for Docker to restart
|
|
Write-Host "[3/4] Waiting for Docker to restart..." -ForegroundColor Yellow
|
|
Start-Sleep -Seconds 5
|
|
|
|
# Step 4: Test Docker pull
|
|
Write-Host "[4/4] Testing Docker pull..." -ForegroundColor Yellow
|
|
$testCmd = "docker pull node:18-alpine 2>&1 | head -20"
|
|
if ($usePlink) {
|
|
$plinkCmd = "`"$plinkPath`" -ssh -pw `"$Password`" -batch ${User}@${Server} `"$testCmd`""
|
|
$result = cmd /c $plinkCmd 2>&1
|
|
Write-Host $result
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Docker configuration updated" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "If Docker pull still fails, you can:" -ForegroundColor Yellow
|
|
Write-Host " 1. Try deploying again: .\scripts\deploy\deploy-with-password.ps1" -ForegroundColor White
|
|
Write-Host " 2. Or configure a working mirror manually" -ForegroundColor White
|
|
Write-Host ""
|
|
|
|
# Cleanup
|
|
Remove-Item $tempDaemonJson -Force -ErrorAction SilentlyContinue
|