| <powershell> |
| $ErrorActionPreference = "Stop" |
| Set-StrictMode -Version Latest |
| function Check-Call { |
| param ( |
| [scriptblock]$ScriptBlock |
| ) |
| Write-Host "Executing $ScriptBlock" |
| & @ScriptBlock |
| if (($lastexitcode -ne 0)) { |
| Write-Error "Execution failed with $lastexitcode" |
| exit $lastexitcode |
| } |
| } |
| Set-ExecutionPolicy Bypass -Scope Process -Force |
| |
| # install ssh server and client, enable auto-startup, and start services |
| Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 |
| Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 |
| Set-Service -Name ssh-agent -StartupType ‘Automatic’ |
| Set-Service -Name sshd -StartupType ‘Automatic’ |
| Start-Service ssh-agent |
| Start-Service sshd |
| |
| # setup administrator ssh key |
| Invoke-WebRequest -Uri http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key -OutFile C:\ProgramData\ssh\administrators_authorized_keys |
| icacls C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r |
| icacls C:\ProgramData\ssh\administrators_authorized_keys /grant "Administrators:(F)" |
| Restart-Service -Name sshd, ssh-agent -Force |
| |
| # install chocolatey |
| Invoke-WebRequest -Uri https://chocolatey.org/install.ps1 -OutFile install.ps1 |
| ./install.ps1 |
| refreshenv |
| Remove-Item -path ./install.ps1 -force |
| |
| # install dependencies |
| Check-Call { C:\ProgramData\chocolatey\choco install python --version=3.7.0 --force -y --no-progress } |
| refreshenv |
| Check-Call { C:\Python37\python -m pip install --upgrade pip } |
| Invoke-WebRequest -Uri https://raw.githubusercontent.com/aiengines/ci/master/ami_generation/windows/requirements.txt -OutFile requirements.txt |
| Check-Call { C:\Python37\python -m pip install -r requirements.txt } |
| |
| Check-Call { C:\ProgramData\chocolatey\choco install git -y } |
| Check-Call { C:\ProgramData\chocolatey\choco install 7zip -y } |
| Check-Call { C:\ProgramData\chocolatey\choco install cmake -y } |
| Check-Call { C:\ProgramData\chocolatey\choco install ninja -y } |
| refreshenv |
| Check-Call { C:\ProgramData\chocolatey\choco install javaruntime -y } |
| refreshenv |
| |
| # get jenkins slave connect scripts |
| Invoke-WebRequest -Uri https://windows-post-install.s3-us-west-2.amazonaws.com/slave-autoconnect.py -OutFile C:\slave-autoconnect.py |
| Invoke-WebRequest -Uri https://windows-post-install.s3-us-west-2.amazonaws.com/run-auto-connect.bat -OutFile C:\run-auto-connect.bat |
| |
| # create required directories |
| New-Item -ItemType directory -Path C:\jenkins_slave |
| New-Item -ItemType directory -Path C:\jenkins_slave\workspace |
| |
| # setup jenkins slave autoconnect script at startup |
| $progressPreference = 'silentlyContinue' |
| $trigger = New-ScheduledTaskTrigger -AtStartup -RandomDelay 00:00:30 |
| $action = New-ScheduledTaskAction -Execute C:\run-auto-connect.bat |
| $principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest |
| Register-ScheduledTask -TaskName "JenkinsAutoConnect" -Description "Connect to Jenkins at startup" -Action $action -Trigger $trigger -Principal $principal |
| |
| # create second stage powershell script |
| Set-Content -Path C:\Users\Administrator\stage2.ps1 -Value @' |
| $ErrorActionPreference = "Stop" |
| Set-StrictMode -Version Latest |
| function Check-Call { |
| param ( |
| [scriptblock]$ScriptBlock |
| ) |
| Write-Host "Executing $ScriptBlock" |
| & @ScriptBlock |
| if (($lastexitcode -ne 0)) { |
| Write-Error "Execution failed with $lastexitcode" |
| exit $lastexitcode |
| } |
| } |
| Set-ExecutionPolicy Bypass -Scope Process -Force |
| cd C:\Users\Administrator |
| Invoke-WebRequest -Uri https://windows-post-install.s3-us-west-2.amazonaws.com/win2019_cuda11_installer.py -OutFile C:\Users\Administrator\windows_deps_headless_installer.py |
| Check-Call { C:\Python37\python windows_deps_headless_installer.py } |
| '@ |
| |
| $progressPreference = 'silentlyContinue' |
| $trigger = New-ScheduledTaskTrigger -AtStartup -RandomDelay 00:00:50 |
| $action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-executionpolicy bypass -noprofile -file C:\Users\Administrator\stage2.ps1" |
| $principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest |
| Register-ScheduledTask -TaskName "Stage2Install" -Action $action -Trigger $trigger -Principal $principal |
| |
| # install nvidia driver for g3 |
| # stage 2 installs will run after driver install reboot |
| Invoke-WebRequest -Uri https://windows-post-install.s3-us-west-2.amazonaws.com/nvidia_display_drivers_g3_452.39_win10_64.zip -OutFile drivers.zip |
| Expand-Archive -Path drivers.zip -DestinationPath c:\drivers |
| Remove-Item drivers.zip |
| Check-Call { C:\drivers\setup.exe -clean -forcereboot -noeula -nofinish -passive } |
| |
| </powershell> |