4
4
Write-Host " Retrieving TOKEN from AWS API"
5
5
$token = Invoke-RestMethod - Method PUT - Uri " http://169.254.169.254/latest/api/token" - Headers @ {" X-aws-ec2-metadata-token-ttl-seconds" = " 180" }
6
6
7
+ $ami_id = Invoke-RestMethod - Uri " http://169.254.169.254/latest/meta-data/ami-id" - Headers @ {" X-aws-ec2-metadata-token" = $token }
8
+
7
9
$metadata = Invoke-RestMethod - Uri " http://169.254.169.254/latest/dynamic/instance-identity/document" - Headers @ {" X-aws-ec2-metadata-token" = $token }
8
10
9
11
$Region = $metadata.region
@@ -32,7 +34,7 @@ Write-Host "Retrieved /$environment/runner/agent-mode parameter - ($agent_mode)
32
34
33
35
if ($enable_cloudwatch_agent -eq " true" )
34
36
{
35
- Write-Host " Enabling CloudWatch Agent"
37
+ Write-Host " Enabling CloudWatch Agent"
36
38
& ' C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1' - a fetch- config - m ec2 - s - c " ssm:$environment -cloudwatch_agent_config_runner"
37
39
}
38
40
@@ -42,7 +44,7 @@ Write-Host "Get GH Runner config from AWS SSM"
42
44
$config = $null
43
45
$i = 0
44
46
do {
45
- $config = (aws ssm get-parameters -- names " $environment -$InstanceId " -- with- decryption -- region $Region -- query " Parameters[*].{Name:Name,Value:Value}" | ConvertFrom-Json )[0 ].value
47
+ $config = (aws ssm get-parameters -- names " $environment -$InstanceId " -- with- decryption -- region $Region -- query " Parameters[*].{Name:Name,Value:Value}" | ConvertFrom-Json )[0 ].value
46
48
Write-Host " Waiting for GH Runner config to become available in AWS SSM ($i /30)"
47
49
Start-Sleep 1
48
50
$i ++
@@ -88,10 +90,18 @@ Invoke-Expression $configCmd
88
90
89
91
Write-Host " Starting the runner as user $run_as "
90
92
93
+ $jsonBody = @ (
94
+ @ {
95
+ group = ' Runner Image'
96
+ details = " AMI id: $ami_id "
97
+ }
98
+ )
99
+ ConvertTo-Json - InputObject $jsonBody | Set-Content - Path " $pwd \.setup_info"
100
+
91
101
Write-Host " Installing the runner as a service"
92
102
93
103
$action = New-ScheduledTaskAction - WorkingDirectory " $pwd " - Execute " run.cmd"
94
104
$trigger = Get-CimClass " MSFT_TaskRegistrationTrigger" - Namespace " Root/Microsoft/Windows/TaskScheduler"
95
105
Register-ScheduledTask - TaskName " runnertask" - Action $action - Trigger $trigger - User $username - Password $password - RunLevel Highest - Force
96
106
Write-Host " Starting the runner in persistent mode"
97
- Write-Host " Starting runner after $ ( ((get-date ) - (gcim Win32_OperatingSystem).LastBootUpTime).tostring(" hh':'mm':'ss''" )) "
107
+ Write-Host " Starting runner after $ ( ((get-date ) - (gcim Win32_OperatingSystem).LastBootUpTime).tostring(" hh':'mm':'ss''" )) "
0 commit comments