windows-provisioner.ps1 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. $ErrorActionPreference = "Continue"
  2. $VerbosePreference = "Continue"
  3. # Install Chocolatey
  4. [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
  5. $env:chocolateyUseWindowsCompression = 'true'
  6. Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
  7. # Add Chocolatey to powershell profile
  8. $ChocoProfileValue = @'
  9. $ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
  10. if (Test-Path($ChocolateyProfile)) {
  11. Import-Module "$ChocolateyProfile"
  12. }
  13. refreshenv
  14. '@
  15. # Write it to the $profile location
  16. Set-Content -Path "$PsHome\Microsoft.PowerShell_profile.ps1" -Value $ChocoProfileValue -Force
  17. # Source it
  18. . "$PsHome\Microsoft.PowerShell_profile.ps1"
  19. refreshenv
  20. Write-Host "Installing cloudwatch agent..."
  21. Invoke-WebRequest -Uri https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/amazon-cloudwatch-agent.msi -OutFile C:\amazon-cloudwatch-agent.msi
  22. $cloudwatchParams = '/i', 'C:\amazon-cloudwatch-agent.msi', '/qn', '/L*v', 'C:\CloudwatchInstall.log'
  23. Start-Process "msiexec.exe" $cloudwatchParams -Wait -NoNewWindow
  24. Remove-Item C:\amazon-cloudwatch-agent.msi
  25. # Install dependent tools
  26. Write-Host "Installing additional development tools"
  27. choco install git awscli -y
  28. refreshenv
  29. Write-Host "Creating actions-runner directory for the GH Action installtion"
  30. New-Item -ItemType Directory -Path C:\actions-runner ; Set-Location C:\actions-runner
  31. Write-Host "Downloading the GH Action runner from ${action_runner_url}"
  32. Invoke-WebRequest -Uri ${action_runner_url} -OutFile actions-runner.zip
  33. Write-Host "Un-zip action runner"
  34. Expand-Archive -Path actions-runner.zip -DestinationPath .
  35. Write-Host "Delete zip file"
  36. Remove-Item actions-runner.zip
  37. $action = New-ScheduledTaskAction -WorkingDirectory "C:\actions-runner" -Execute "PowerShell.exe" -Argument "-File C:\start-runner.ps1"
  38. $trigger = New-ScheduledTaskTrigger -AtStartup
  39. Register-ScheduledTask -TaskName "runnerinit" -Action $action -Trigger $trigger -User System -RunLevel Highest -Force
  40. C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 -Schedule