@@ -14,14 +14,37 @@ $ErrorActionPreference = "Stop"
1414$root = Split-Path - Parent $PSScriptRoot
1515$tarball = Join-Path $env: TEMP " onevo-deploy.tar.gz"
1616
17- function Get-SshArgs {
18- if ($SshKeyPath -and (Test-Path $SshKeyPath )) {
19- return @ ( " -i " , $SshKeyPath , " -o " , " StrictHostKeyChecking=no " )
17+ function Prepare-SshKey ([ string ] $KeyPath ) {
18+ if (-not $KeyPath -or -not (Test-Path $KeyPath )) {
19+ throw " SSH key not found (pass -SshKeyPath or configure default ~/.ssh key). Got: ' $KeyPath ' "
2020 }
21- return @ ()
21+ $dest = Join-Path $env: TEMP (" onevo-deploy-key-{0}" -f [Guid ]::NewGuid().ToString(" N" ))
22+ $raw = [IO.File ]::ReadAllText($KeyPath ) -replace " `r`n " , " `n " -replace " `r " , " `n "
23+ if (-not $raw.EndsWith (" `n " )) { $raw += " `n " }
24+ [IO.File ]::WriteAllText($dest , $raw )
25+ $identity = [System.Security.Principal.WindowsIdentity ]::GetCurrent().Name
26+ & icacls $dest / inheritance:r / grant:r " ${identity} :(R)" | Out-Null
27+ return $dest
2228}
2329
24- $sshArgs = Get-SshArgs
30+ function Invoke-Checked {
31+ param ([string ]$Label , [scriptblock ]$Command )
32+ & $Command
33+ if ($LASTEXITCODE -ne 0 ) {
34+ throw " $Label failed (exit $LASTEXITCODE )"
35+ }
36+ }
37+
38+ function Get-SshArgs ([string ]$KeyPath ) {
39+ if ($KeyPath -and (Test-Path $KeyPath )) {
40+ return @ (" -i" , $KeyPath , " -o" , " StrictHostKeyChecking=no" , " -o" , " BatchMode=yes" )
41+ }
42+ return @ (" -o" , " StrictHostKeyChecking=no" , " -o" , " BatchMode=yes" )
43+ }
44+
45+ $preparedKey = $null
46+ if ($SshKeyPath ) { $preparedKey = Prepare- SshKey $SshKeyPath }
47+ $sshArgs = Get-SshArgs $preparedKey
2548$scpArgs = @ ($sshArgs ) + @ (" ${VmUser} @${VmHost} :" )
2649
2750Write-Host " ==> Packaging app (excluding large artifacts)..."
@@ -51,16 +74,18 @@ try {
5174}
5275
5376Write-Host " ==> Uploading to ${VmUser} @${VmHost} ..."
54- scp @sshArgs $tarball " ${VmUser} @${VmHost} :/tmp/onevo-deploy.tar.gz"
77+ Invoke-Checked " SCP tarball " { scp @sshArgs $tarball " ${VmUser} @${VmHost} :/tmp/onevo-deploy.tar.gz" }
5578
5679$installerExe = $null
5780if (-not $SkipInstaller ) {
81+ Write-Host " ==> Ensuring installer tools (ffmpeg, WinSW)..."
82+ & (Join-Path $root " scripts\ensure-installer-tools.ps1" )
5883 Write-Host " ==> Building Windows installer..."
5984 & (Join-Path $root " scripts\build-installer.ps1" ) - BackendUrl $BackendUrl - AllowHttp
6085 $installerExe = Get-ChildItem (Join-Path $root " connector\dist\ONEVO-Connector-Setup-*.exe" ) |
6186 Sort-Object LastWriteTime - Descending | Select-Object - First 1
6287 if (-not $installerExe ) { throw " Installer EXE not found after build" }
63- scp @sshArgs $installerExe.FullName " ${VmUser} @${VmHost} :/tmp/$ ( $installerExe.Name ) "
88+ Invoke-Checked " SCP installer " { scp @sshArgs $installerExe.FullName " ${VmUser} @${VmHost} :/tmp/$ ( $installerExe.Name ) " }
6489 $installerRemoteName = $installerExe.Name
6590} else {
6691 $installerRemoteName = " "
@@ -95,7 +120,11 @@ docker compose ps --format 'table {{.Name}}\t{{.Status}}'
95120"@ -replace " `r`n " , " `n "
96121
97122Write-Host " ==> Running remote deploy..."
98- ssh @sshArgs " ${VmUser} @${VmHost} " $remoteScript
123+ try {
124+ Invoke-Checked " SSH deploy" { ssh @sshArgs " ${VmUser} @${VmHost} " $remoteScript }
125+ } finally {
126+ if ($preparedKey -and (Test-Path $preparedKey )) { Remove-Item $preparedKey - Force - ErrorAction SilentlyContinue }
127+ }
99128
100129Write-Host " "
101130Write-Host " Deploy complete."
0 commit comments