From a6b8f381f04b54ecda35aff116a3b7852096f5a5 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Fri, 22 Mar 2024 15:48:51 +0100 Subject: [PATCH] feat: support windows containers in bootstrap script (#12662) Fixes #7462. --- provisionersdk/scripts/bootstrap_windows.ps1 | 22 +++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/provisionersdk/scripts/bootstrap_windows.ps1 b/provisionersdk/scripts/bootstrap_windows.ps1 index 469ace15fb..aa3089f90d 100644 --- a/provisionersdk/scripts/bootstrap_windows.ps1 +++ b/provisionersdk/scripts/bootstrap_windows.ps1 @@ -25,8 +25,24 @@ while ($true) { } } -# If the below fails, retrying probably will not help. -Set-MpPreference -DisableRealtimeMonitoring $true -ExclusionPath $env:TEMP\sshd.exe +# Check if running in a Windows container +if (-not (Get-Command 'Set-MpPreference' -ErrorAction SilentlyContinue)) { + Write-Output "Set-MpPreference not available, skipping..." +} else { + Set-MpPreference -DisableRealtimeMonitoring $true -ExclusionPath $env:TEMP\sshd.exe +} + $env:CODER_AGENT_AUTH = "${AUTH_TYPE}" $env:CODER_AGENT_URL = "${ACCESS_URL}" -Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru + +# Check if we're running inside a Windows container! +$inContainer = $false +if ((Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control' -Name 'ContainerType' -ErrorAction SilentlyContinue) -ne $null) { + $inContainer = $true +} +if ($inContainer) { + # If we're in a container, run in a the foreground! + Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -Wait -NoNewWindow +} else { + Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru +}