diff --git a/modules/runners/templates/start-runner.ps1 b/modules/runners/templates/start-runner.ps1 index bdb9f0c851..3271652a0c 100644 --- a/modules/runners/templates/start-runner.ps1 +++ b/modules/runners/templates/start-runner.ps1 @@ -4,6 +4,8 @@ Write-Host "Retrieving TOKEN from AWS API" $token=Invoke-RestMethod -Method PUT -Uri "http://169.254.169.254/latest/api/token" -Headers @{"X-aws-ec2-metadata-token-ttl-seconds" = "180"} +$ami_id=Invoke-RestMethod -Uri "http://169.254.169.254/latest/meta-data/ami-id" -Headers @{"X-aws-ec2-metadata-token" = $token} + $metadata=Invoke-RestMethod -Uri "http://169.254.169.254/latest/dynamic/instance-identity/document" -Headers @{"X-aws-ec2-metadata-token" = $token} $Region = $metadata.region @@ -32,7 +34,7 @@ Write-Host "Retrieved /$environment/runner/agent-mode parameter - ($agent_mode) if ($enable_cloudwatch_agent -eq "true") { - Write-Host "Enabling CloudWatch Agent" + Write-Host "Enabling CloudWatch Agent" & 'C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1' -a fetch-config -m ec2 -s -c "ssm:$environment-cloudwatch_agent_config_runner" } @@ -42,7 +44,7 @@ Write-Host "Get GH Runner config from AWS SSM" $config = $null $i = 0 do { - $config = (aws ssm get-parameters --names "$environment-$InstanceId" --with-decryption --region $Region --query "Parameters[*].{Name:Name,Value:Value}" | ConvertFrom-Json)[0].value + $config = (aws ssm get-parameters --names "$environment-$InstanceId" --with-decryption --region $Region --query "Parameters[*].{Name:Name,Value:Value}" | ConvertFrom-Json)[0].value Write-Host "Waiting for GH Runner config to become available in AWS SSM ($i/30)" Start-Sleep 1 $i++ @@ -88,10 +90,18 @@ Invoke-Expression $configCmd Write-Host "Starting the runner as user $run_as" +$jsonBody = @( + @{ + group='Runner Image' + details="AMI id: $ami_id" + } +) +ConvertTo-Json -InputObject $jsonBody | Set-Content -Path "$pwd\.setup_info" + Write-Host "Installing the runner as a service" $action = New-ScheduledTaskAction -WorkingDirectory "$pwd" -Execute "run.cmd" $trigger = Get-CimClass "MSFT_TaskRegistrationTrigger" -Namespace "Root/Microsoft/Windows/TaskScheduler" Register-ScheduledTask -TaskName "runnertask" -Action $action -Trigger $trigger -User $username -Password $password -RunLevel Highest -Force Write-Host "Starting the runner in persistent mode" -Write-Host "Starting runner after $(((get-date) - (gcim Win32_OperatingSystem).LastBootUpTime).tostring("hh':'mm':'ss''"))" \ No newline at end of file +Write-Host "Starting runner after $(((get-date) - (gcim Win32_OperatingSystem).LastBootUpTime).tostring("hh':'mm':'ss''"))" diff --git a/modules/runners/templates/start-runner.sh b/modules/runners/templates/start-runner.sh index 9dedb6a813..80cf886db8 100644 --- a/modules/runners/templates/start-runner.sh +++ b/modules/runners/templates/start-runner.sh @@ -5,6 +5,8 @@ echo "Retrieving TOKEN from AWS API" token=$(curl -f -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 180") +ami_id=$(curl -f -H "X-aws-ec2-metadata-token: $token" -v http://169.254.169.254/latest/meta-data/ami-id) + region=$(curl -f -H "X-aws-ec2-metadata-token: $token" -v http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region) echo "Retrieved REGION from AWS API ($region)" @@ -60,6 +62,23 @@ chown -R $run_as . echo "Configure GH Runner as user $run_as" sudo --preserve-env=RUNNER_ALLOW_RUNASROOT -u "$run_as" -- ./config.sh --unattended --name "$instance_id" --work "_work" $${config} +info_arch=$(uname -p) +info_os=$(( lsb_release -ds || cat /etc/*release || uname -om ) 2>/dev/null | head -n1 | cut -d "=" -f2- | tr -d '"') + +tee /opt/actions-runner/.setup_info <