diff --git a/examples/default/main.tf b/examples/default/main.tf index de89b063d0..faef591d4a 100644 --- a/examples/default/main.tf +++ b/examples/default/main.tf @@ -87,4 +87,7 @@ module "runners" { # enable_workflow_job_events_queue = true enable_user_data_debug_logging_runner = true + + # prefix GitHub runners with the environment name + runner_name_prefix = local.environment } diff --git a/modules/runners/lambdas/runners/src/aws/runners.test.ts b/modules/runners/lambdas/runners/src/aws/runners.test.ts index 895ac24bff..fd234789e6 100644 --- a/modules/runners/lambdas/runners/src/aws/runners.test.ts +++ b/modules/runners/lambdas/runners/src/aws/runners.test.ts @@ -477,7 +477,6 @@ function createRunnerConfig(runnerConfig: RunnerConfig): RunnerInputParameters { }, subnets: ['subnet-123', 'subnet-456'], amiIdSsmParameterName: runnerConfig.amiIdSsmParameterName, - runnerNamePrefix: RUNNER_NAME_PREFIX, }; } diff --git a/modules/runners/lambdas/runners/src/aws/runners.ts b/modules/runners/lambdas/runners/src/aws/runners.ts index bb6240aa6b..32902ff978 100644 --- a/modules/runners/lambdas/runners/src/aws/runners.ts +++ b/modules/runners/lambdas/runners/src/aws/runners.ts @@ -44,7 +44,6 @@ export interface RunnerInputParameters { instanceAllocationStrategy: EC2.SpotAllocationStrategy; }; numberOfRunners?: number; - runnerNamePrefix: string; amiIdSsmParameterName?: string; } diff --git a/modules/runners/lambdas/runners/src/pool/pool.ts b/modules/runners/lambdas/runners/src/pool/pool.ts index c362924c88..0d07b6001b 100644 --- a/modules/runners/lambdas/runners/src/pool/pool.ts +++ b/modules/runners/lambdas/runners/src/pool/pool.ts @@ -33,7 +33,6 @@ export async function adjust(event: PoolEvent): Promise { const instanceAllocationStrategy = process.env.INSTANCE_ALLOCATION_STRATEGY || 'lowest-price'; // same as AWS default const runnerOwner = process.env.RUNNER_OWNER; const amiIdSsmParameterName = process.env.AMI_ID_SSM_PARAMETER_NAME; - const runnerNamePrefix = process.env.RUNNER_NAME_PREFIX || ''; let ghesApiUrl = ''; if (ghesBaseUrl) { @@ -112,7 +111,6 @@ export async function adjust(event: PoolEvent): Promise { subnets, numberOfRunners: topUp, amiIdSsmParameterName, - runnerNamePrefix, }, githubInstallationClient, ); diff --git a/modules/runners/lambdas/runners/src/scale-runners/scale-up.test.ts b/modules/runners/lambdas/runners/src/scale-runners/scale-up.test.ts index e5a8d9d2ac..73c3eed508 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/scale-up.test.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/scale-up.test.ts @@ -64,7 +64,6 @@ const EXPECTED_RUNNER_PARAMS: RunnerInputParameters = { }, ssmTokenPath: '/github-action-runners/default/runners/config', subnets: ['subnet-123'], - runnerNamePrefix: 'unit-test', }; let expectedRunnerParams: RunnerInputParameters; diff --git a/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts b/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts index 1f10bf742f..9dc7809f6a 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts @@ -34,7 +34,6 @@ interface CreateEC2RunnerConfig { ec2instanceCriteria: RunnerInputParameters['ec2instanceCriteria']; numberOfRunners?: number; amiIdSsmParameterName?: string; - runnerNamePrefix: string; } function generateRunnerServiceConfig(githubRunnerConfig: CreateGitHubRunnerConfig, token: string) { @@ -157,7 +156,6 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage const instanceAllocationStrategy = process.env.INSTANCE_ALLOCATION_STRATEGY || 'lowest-price'; // same as AWS default const enableJobQueuedCheck = yn(process.env.ENABLE_JOB_QUEUED_CHECK, { default: true }); const amiIdSsmParameterName = process.env.AMI_ID_SSM_PARAMETER_NAME; - const runnerNamePrefix = process.env.RUNNER_NAME_PREFIX || ''; if (ephemeralEnabled && payload.eventType !== 'workflow_job') { logger.warn( @@ -223,7 +221,6 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage ssmTokenPath, subnets, amiIdSsmParameterName, - runnerNamePrefix, }, githubInstallationClient, ); diff --git a/modules/runners/templates/start-runner.sh b/modules/runners/templates/start-runner.sh index 2e35a3c5c5..9d1cae27f9 100644 --- a/modules/runners/templates/start-runner.sh +++ b/modules/runners/templates/start-runner.sh @@ -16,6 +16,7 @@ echo "Retrieved INSTANCE_ID from AWS API ($instance_id)" %{ if metadata_tags == "enabled" } environment=$(curl -f -H "X-aws-ec2-metadata-token: $token" -v http://169.254.169.254/latest/meta-data/tags/instance/ghr:environment) ssm_config_path=$(curl -f -H "X-aws-ec2-metadata-token: $token" -v http://169.254.169.254/latest/meta-data/tags/instance/ghr:ssm_config_path) +runner_name_prefix=$(curl -f -H "X-aws-ec2-metadata-token: $token" -v http://169.254.169.254/latest/meta-data/tags/instance/ghr:runner_name_prefix) || true %{ else } tags=$(aws ec2 describe-tags --region "$region" --filters "Name=resource-id,Values=$instance_id") @@ -23,11 +24,12 @@ echo "Retrieved tags from AWS API ($tags)" environment=$(echo "$tags" | jq -r '.Tags[] | select(.Key == "ghr:environment") | .Value') ssm_config_path=$(echo "$tags" | jq -r '.Tags[] | select(.Key == "ghr:ssm_config_path") | .Value') +runner_name_prefix=$(echo "$tags" | jq -r '.Tags[] | select(.Key == "ghr:runner_name_prefix") | .Value') + %{ endif } echo "Retrieved ghr:environment tag - ($environment)" echo "Retrieved ghr:ssm_config_path tag - ($ssm_config_path)" -runner_name_prefix=$(curl -f -H "X-aws-ec2-metadata-token: $token" -v http://169.254.169.254/latest/meta-data/tags/instance/ghr:runner_name_prefix) || true echo "Retrieved ghr:runner_name_prefix tag - ($runner_name_prefix)" parameters=$(aws ssm get-parameters-by-path --path "$ssm_config_path" --region "$region" --query "Parameters[*].{Name:Name,Value:Value}")