Files
inquiry_robot/deploy/_local_deploy_quote_template.ps1
T

99 lines
5.0 KiB
PowerShell

# 本机:打包 agent/admin,上传 jar,远端重启主账与智能体,并 seed 模板
$ErrorActionPreference = 'Stop'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
if (-not $here) { $here = (Get-Location).Path }
$Repo = (Resolve-Path (Join-Path $here '..')).Path
$key = Join-Path $env:USERPROFILE '.ssh\id_ed25519_ytd'
$remote = 'ytd_extdev_0903@129.211.181.80'
$incoming = "${remote}:C:/Users/ytd_extdev_0903/incoming"
Write-Host ("here=" + $here)
Write-Host ("Repo=" + $Repo)
if (-not (Test-Path (Join-Path $Repo 'inquiry-agent'))) { throw "bad repo path: $Repo" }
Write-Host '=== package agent ==='
$stage = Join-Path $env:TEMP 'ytd-agent-release-stage'
$zipAgent = Join-Path $Repo 'agent-release.zip'
if (Test-Path $stage) { Remove-Item $stage -Recurse -Force }
New-Item -ItemType Directory -Force -Path (Join-Path $stage 'agent') | Out-Null
robocopy (Join-Path $Repo 'inquiry-agent') (Join-Path $stage 'agent') /E /XD .venv __pycache__ .git /XF *.pyc /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null
if (Test-Path $zipAgent) { Remove-Item $zipAgent -Force }
Compress-Archive -Path (Join-Path $stage 'agent') -DestinationPath $zipAgent -Force
Write-Host ("agent_zip=" + (Get-Item $zipAgent).Length)
$jar = Join-Path $Repo 'inquiry-api\jeecg-module-system\jeecg-system-start\target\jeecg-system-start-3.5.3.jar'
if (-not (Test-Path $jar)) { throw 'jar missing' }
Write-Host ("jar_bytes=" + (Get-Item $jar).Length)
Write-Host '=== build admin ==='
$Src = Join-Path $Repo 'inquiry-backend'
$Build = 'C:\ytd\inquiry-backend'
robocopy $Src $Build /MIR /XD node_modules dist .git .vite .husky /XF *.log /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null
if (Test-Path (Join-Path $Src '.env.production')) {
Copy-Item (Join-Path $Src '.env.production') (Join-Path $Build '.env.production') -Force
}
Copy-Item (Join-Path $Src 'vite.config.ts') (Join-Path $Build 'vite.config.ts') -Force
Push-Location $Build
if (Test-Path dist) { Remove-Item dist -Recurse -Force }
pnpm run build
$code = $LASTEXITCODE
Pop-Location
if ($code -ne 0) { throw "admin build failed $code" }
$zipAdmin = Join-Path $env:TEMP 'admin-dist.zip'
if (Test-Path $zipAdmin) { Remove-Item $zipAdmin -Force }
Compress-Archive -Path "$Build\dist\*" -DestinationPath $zipAdmin -Force
Write-Host ("admin_zip=" + (Get-Item $zipAdmin).Length)
$cfgZip = Join-Path $env:TEMP 'ledger-config.zip'
if (Test-Path $cfgZip) { Remove-Item $cfgZip -Force }
$cfgStage = Join-Path $env:TEMP 'ledger-cfg-stage-qt'
if (Test-Path $cfgStage) { Remove-Item $cfgStage -Recurse -Force }
New-Item -ItemType Directory $cfgStage | Out-Null
Copy-Item (Join-Path $Repo 'deploy\config\application-inquiry.yml') (Join-Path $cfgStage 'application-inquiry.yml') -Force
Compress-Archive -Path "$cfgStage\*" -DestinationPath $cfgZip -Force
# templates zip for seed
$tplZip = Join-Path $env:TEMP 'quote-templates-seed.zip'
if (Test-Path $tplZip) { Remove-Item $tplZip -Force }
$tplStage = Join-Path $env:TEMP 'quote-templates-seed-stage'
if (Test-Path $tplStage) { Remove-Item $tplStage -Recurse -Force }
New-Item -ItemType Directory $tplStage | Out-Null
$tplDir = Get-ChildItem -Path $Repo -Directory | Where-Object { $_.Name -like '*报价*' -and $_.Name -like '*模板*' } | Select-Object -First 1
if (-not $tplDir) { throw 'template folder not found under repo' }
robocopy $tplDir.FullName (Join-Path $tplStage 'templates') /E /XF ~$* /NFL /NDL /NJH /NJS /nc /ns /np | Out-Null
Write-Host ("templates_from=" + $tplDir.FullName)
Copy-Item (Join-Path $Repo 'deploy\seed\quote_templates_seed_manifest_v1.json') (Join-Path $tplStage 'manifest.json') -Force
Compress-Archive -Path "$tplStage\*" -DestinationPath $tplZip -Force
Write-Host '=== upload ==='
scp -o BatchMode=yes -i $key `
$zipAgent `
$zipAdmin `
$jar `
$cfgZip `
$tplZip `
(Join-Path $Repo 'deploy\_remote_wmi_start_ledger.ps1') `
(Join-Path $Repo 'deploy\_remote_safe_deploy_agent.ps1') `
(Join-Path $Repo 'deploy\_remote_cutover_admin_8180.ps1') `
(Join-Path $Repo 'deploy\_remote_seed_quote_templates.ps1') `
$incoming
if ($LASTEXITCODE -ne 0) { throw 'scp failed' }
Write-Host 'UPLOAD_OK'
Write-Host '=== deploy ledger ==='
ssh -o BatchMode=yes -i $key $remote "powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\ytd_extdev_0903\incoming\_remote_wmi_start_ledger.ps1"
if ($LASTEXITCODE -ne 0) { throw 'ledger deploy failed' }
Write-Host '=== deploy agent ==='
ssh -o BatchMode=yes -i $key $remote "powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\ytd_extdev_0903\incoming\_remote_safe_deploy_agent.ps1"
if ($LASTEXITCODE -ne 0) { throw 'agent deploy failed' }
Write-Host '=== deploy admin ==='
ssh -o BatchMode=yes -i $key $remote "powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\ytd_extdev_0903\incoming\_remote_cutover_admin_8180.ps1"
if ($LASTEXITCODE -ne 0) { throw 'admin deploy failed' }
Write-Host '=== wait ledger ==='
Start-Sleep -Seconds 25
ssh -o BatchMode=yes -i $key $remote "powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\ytd_extdev_0903\incoming\_remote_seed_quote_templates.ps1"
if ($LASTEXITCODE -ne 0) { throw 'seed failed' }
Write-Host 'QUOTE_TEMPLATE_DEPLOY_DONE'