flnxi-Wu/scripts/deploy/check-and-fix-deploy.ps1
WuYongJie f646b71813
Some checks failed
CI Check / check (push) Has been cancelled
chore: 初始化本地仓库并同步最近改动
2025-11-18 17:50:16 +08:00

59 lines
2.3 KiB
PowerShell

# 检查并修复部署
param(
[string]$Server = "45.249.208.118",
[string]$Username = "root",
[string]$Password = "lxvhNYFZ4160",
[string]$RemotePath = "/root/deploy"
)
$plinkPath = "C:\Program Files\PuTTY\plink.exe"
$hostKey = "SHA256:WZOtvC/+IWw29P8vyovSabmIRFkQ/Bnmhj+qhTshA4Q"
function Invoke-SSHCommand {
param([string]$Command)
Write-Host "执行: $Command" -ForegroundColor Gray
$result = & $plinkPath -batch -ssh -hostkey $hostKey -pw $Password "${Username}@${Server}" $Command 2>&1
Write-Host $result
return $LASTEXITCODE
}
Write-Host "=== 检查并修复部署 ===" -ForegroundColor Cyan
# 1. 检查 Docker 镜像源配置
Write-Host "`n检查 Docker 镜像源配置..." -ForegroundColor Yellow
Invoke-SSHCommand "cat /etc/docker/daemon.json 2>/dev/null || echo '未找到 daemon.json'"
# 2. 检查现有镜像
Write-Host "`n检查现有镜像..." -ForegroundColor Yellow
Invoke-SSHCommand "docker images | grep -E 'minio|youyidian'"
# 3. 尝试使用国内镜像源拉取
Write-Host "`n尝试配置临时镜像源并拉取..." -ForegroundColor Yellow
$pullCmd = @"
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/minio:RELEASE.2025-04-22T22-12-26Z 2>/dev/null || \
docker pull minio/mc:RELEASE.2025-04-22T22-12-26Z
"@
Invoke-SSHCommand $pullCmd
# 4. 如果拉取失败,尝试使用已有的 minio 镜像
Write-Host "`n检查是否有可用的 minio 镜像..." -ForegroundColor Yellow
$minioCheck = Invoke-SSHCommand "docker images minio/mc --format '{{.Tag}}' | head -1"
if ($minioCheck -eq 0) {
Write-Host "找到 minio 镜像,修改 docker-compose.yml..." -ForegroundColor Green
Invoke-SSHCommand "cd ${RemotePath} && sed -i 's|minio/mc:RELEASE.2025-04-22T22-12-26Z|minio/mc:latest|g' docker-compose.yml"
}
# 5. 重试部署
Write-Host "`n重试部署..." -ForegroundColor Yellow
$deployResult = Invoke-SSHCommand "cd ${RemotePath} && docker compose up -d 2>&1"
if ($deployResult -eq 0) {
Write-Host "`n✓ 部署成功!" -ForegroundColor Green
Write-Host "`n容器状态:" -ForegroundColor Cyan
Invoke-SSHCommand "cd ${RemotePath} && docker compose ps"
} else {
Write-Host "`n✗ 部署失败" -ForegroundColor Red
Write-Host "`n查看详细错误:" -ForegroundColor Yellow
Invoke-SSHCommand "cd ${RemotePath} && docker compose logs --tail=50"
}