forked from wangbo/easyai
fix(deploy): 修复组件版本解析和安装升级验收流程
This commit is contained in:
+17
-51
@@ -205,7 +205,15 @@ if (-not (Test-Path ".env")) { Write-Err "未找到 .env,请先执行 start.ps
|
||||
. (Join-Path $scriptDir "scripts\Initialize-SecurityEnv.ps1")
|
||||
$environmentPath = Join-Path $scriptDir ".env"
|
||||
. (Join-Path $scriptDir "scripts/Initialize-ApplicationVersions.ps1")
|
||||
if (-not (Get-EnvValue (Get-Content $environmentPath -Raw -Encoding UTF8) 'SYSTEM_UPDATE_MODE')) {
|
||||
& docker inspect easyai-server *> $null
|
||||
$existingServer = $LASTEXITCODE -eq 0
|
||||
& docker inspect easyai-updater *> $null
|
||||
if ($existingServer -and $LASTEXITCODE -ne 0) { $env:EASYAI_UPDATE_MODE_HINT = 'legacy_watchtower' }
|
||||
}
|
||||
try { $applicationVersionPlan = @(Get-ApplicationVersionPlan -Path $environmentPath) } catch { Write-Err $_.Exception.Message }
|
||||
. (Join-Path $scriptDir 'scripts/DeploymentRuntime.ps1')
|
||||
Backup-DeploymentConfig -ProjectRoot $scriptDir
|
||||
$environmentContent = Get-Content $environmentPath -Raw -Encoding UTF8
|
||||
if (-not (Get-EnvValue $environmentContent "SYSTEM_UPDATE_MODE")) {
|
||||
& docker inspect easyai-server *> $null
|
||||
@@ -228,6 +236,7 @@ Initialize-ServerHttpBindIp -Path (Join-Path $scriptDir ".env")
|
||||
. (Join-Path $scriptDir "scripts\Initialize-SecurityEnv.ps1")
|
||||
Initialize-SecurityEnv -Path (Join-Path $scriptDir ".env") -Mode "upgrade"
|
||||
Set-ApplicationVersions -Path $environmentPath -Plan $applicationVersionPlan
|
||||
Set-DeploymentReleaseSource -Path $environmentPath
|
||||
|
||||
# 在更新镜像和重建服务前迁移并校验后端公开 API 地址。
|
||||
. (Join-Path $scriptDir "scripts\Initialize-PublicApiBaseUrl.ps1")
|
||||
@@ -303,57 +312,8 @@ function Invoke-Compose {
|
||||
}
|
||||
|
||||
function Wait-CoreServices {
|
||||
$timeoutSeconds = 300
|
||||
if (-not [string]::IsNullOrWhiteSpace($env:UPDATE_HEALTH_TIMEOUT_SECONDS)) {
|
||||
if (-not [int]::TryParse($env:UPDATE_HEALTH_TIMEOUT_SECONDS, [ref]$timeoutSeconds) -or $timeoutSeconds -le 0) {
|
||||
Write-Err "UPDATE_HEALTH_TIMEOUT_SECONDS 必须是正整数,当前为: $($env:UPDATE_HEALTH_TIMEOUT_SECONDS)"
|
||||
}
|
||||
}
|
||||
|
||||
$services = if ($updateServices.Count -gt 0) {
|
||||
$updateServices
|
||||
} elseif ($availableServices -contains "model-conversion-worker") {
|
||||
@("easyai-server", "ws-gateway", "easyai-web", "model-conversion-worker")
|
||||
} else {
|
||||
@("easyai-server", "ws-gateway", "easyai-web")
|
||||
}
|
||||
$deadline = (Get-Date).AddSeconds($timeoutSeconds)
|
||||
Write-Step "⏳ 正在等待核心服务恢复可用(最长 $timeoutSeconds 秒)..."
|
||||
|
||||
while ((Get-Date) -lt $deadline) {
|
||||
$allReady = $true
|
||||
foreach ($service in $services) {
|
||||
if ($hasComposeV2) {
|
||||
$containerId = (& docker compose ps -q $service 2>$null | Select-Object -First 1)
|
||||
} else {
|
||||
$containerId = (& docker-compose ps -q $service 2>$null | Select-Object -First 1)
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($containerId)) {
|
||||
$allReady = $false
|
||||
continue
|
||||
}
|
||||
|
||||
$state = (& docker inspect --format '{{.State.Running}}|{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' $containerId 2>$null)
|
||||
$parts = "$state".Trim().Split('|')
|
||||
if ($parts.Count -lt 2 -or $parts[0] -ne "true" -or ($parts[1] -ne "none" -and $parts[1] -ne "healthy")) {
|
||||
$allReady = $false
|
||||
}
|
||||
}
|
||||
|
||||
if ($allReady) {
|
||||
Write-Ok "核心服务已恢复可用"
|
||||
return
|
||||
}
|
||||
Start-Sleep -Seconds 5
|
||||
}
|
||||
|
||||
Write-Host "❌ 更新后核心服务未在 $timeoutSeconds 秒内恢复可用" -ForegroundColor Red
|
||||
if ($hasComposeV2) {
|
||||
docker compose ps @services
|
||||
} else {
|
||||
docker-compose ps @services
|
||||
}
|
||||
Write-Err "请检查核心服务日志,确认失败原因后重试"
|
||||
$timeout = if ($env:UPDATE_HEALTH_TIMEOUT_SECONDS) { [int]$env:UPDATE_HEALTH_TIMEOUT_SECONDS } else { 600 }
|
||||
Wait-DeploymentServices -ComposeCommand $composeCommand -Services $updateServices -TimeoutSeconds $timeout
|
||||
}
|
||||
|
||||
# ==================== 更新并启动 ====================
|
||||
@@ -371,6 +331,10 @@ if (-not [string]::IsNullOrWhiteSpace($env:UPDATE_SERVICES)) {
|
||||
}
|
||||
}
|
||||
$composeCommand = if ($hasComposeV2) { @("docker","compose") } else { @("docker-compose") }
|
||||
. (Join-Path $scriptDir 'scripts/DeploymentRuntime.ps1')
|
||||
Initialize-DeploymentDockerConfig -ProjectRoot $scriptDir
|
||||
Test-DeploymentStorage -ComposeCommand $composeCommand -Services $updateServices
|
||||
Test-DeploymentImages -ComposeCommand $composeCommand -Services $updateServices
|
||||
try { Test-ApplicationVersionImages -Plan $applicationVersionPlan -ComposeCommand $composeCommand } catch { Write-Err $_.Exception.Message }
|
||||
$upArguments = @("up", "-d")
|
||||
if ($updateServices.Count -gt 0) { $upArguments += @("--no-deps") + $updateServices }
|
||||
@@ -380,11 +344,13 @@ if ($updateServices.Count -eq 0 -or $updateServices -contains "redis") {
|
||||
if ($hasComposeV2) {
|
||||
docker compose pull @updateServices
|
||||
if ($LASTEXITCODE -ne 0) { Write-Err "镜像拉取失败,请检查网络、镜像仓库权限和服务器磁盘空间后重试" }
|
||||
Test-PulledReleaseImages -ComposeCommand $composeCommand -Services $updateServices
|
||||
docker compose @upArguments
|
||||
if ($LASTEXITCODE -ne 0) { Write-Err "容器启动失败,EasyAI 未被标记为更新成功" }
|
||||
} else {
|
||||
docker-compose pull @updateServices
|
||||
if ($LASTEXITCODE -ne 0) { Write-Err "镜像拉取失败,请检查网络、镜像仓库权限和服务器磁盘空间后重试" }
|
||||
Test-PulledReleaseImages -ComposeCommand $composeCommand -Services $updateServices
|
||||
docker-compose @upArguments
|
||||
if ($LASTEXITCODE -ne 0) { Write-Err "容器启动失败,EasyAI 未被标记为更新成功" }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user