File size: 2,234 Bytes
5241269
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<#
Run the browser runner on this Windows PC (fast, real-time live view) and connect it to the runner VM's HTTPS address
through an SSH tunnel. While it runs, the VM's front door (Caddy) sends Astra's browser work here; when it stops, the VM's
own runner takes over again. Nothing is opened on this PC's network: the tunnel goes out to the VM.

Usage (PowerShell):
  .\deploy\pc-runner\start-pc-runner.ps1 -VmHost 129.225.117.95 -KeyFile $HOME\.ssh\oci_patchwise -TokenFile $HOME\.oci\runner_token.txt

Needs: Python 3, Node 22+, `npm ci` and `npx playwright install chromium` in automation\, OpenSSH (built into Windows).
Stop it with Ctrl+C or by closing the window. See docs/REMOTE_RUNNER.md "A PC as the runner".
#>
param(
  [Parameter(Mandatory = $true)][string]$VmHost,
  [Parameter(Mandatory = $true)][string]$KeyFile,
  [Parameter(Mandatory = $true)][string]$TokenFile,
  [int]$Port = 8898,
  [string]$DataDir = (Join-Path $env:LOCALAPPDATA 'astra-runner')
)
$ErrorActionPreference = 'Stop'
$repo = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
$env:RUNNER_TOKEN = (Get-Content -Raw $TokenFile).Trim()
$env:RUNNER_PORT = "$Port"
$env:RUNNER_HOME = $DataDir
$env:AUTOMATION_DIR = Join-Path $repo 'automation'
New-Item -ItemType Directory -Force $DataDir | Out-Null

$server = Join-Path $repo 'automation\remote_runner\server.py'
$runner = Start-Process python -ArgumentList '-I', "`"$server`"" -NoNewWindow -PassThru `
  -RedirectStandardOutput (Join-Path $DataDir 'runner.log') -RedirectStandardError (Join-Path $DataDir 'runner.err')
Write-Host "Runner started on 127.0.0.1:$Port (logs in $DataDir). Connecting the tunnel to $VmHost ..."
try {
  while (-not $runner.HasExited) {
    # the VM's port $Port leads to this PC's runner while the tunnel is up; reconnect after any drop
    & ssh -N -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=accept-new `
      -i $KeyFile -R "${Port}:127.0.0.1:${Port}" "ubuntu@$VmHost"
    Write-Host "Tunnel closed; reconnecting in 5 s (Ctrl+C to stop)."
    Start-Sleep -Seconds 5
  }
} finally {
  if (-not $runner.HasExited) { Stop-Process -Id $runner.Id -Force }
  Write-Host 'Runner stopped; the VM runner takes over.'
}