Skip to content

Commit f63e0a2

Browse files
ryan-williamsclaude
andcommitted
Remove hardcoded AMI fallback and make ec2_image_id required
The hardcoded AMI fallback (ami-0e86e20dae9224db8) was x86_64-specific and would fail for ARM instances. Since we can't determine architecture until we know the instance type, and different architectures need different AMIs, it's cleaner to require the AMI be explicitly provided. Changes: - Removed EC2_IMAGE_ID constant from defaults.py - Added validation in __main__.py to require image_id via input or vars - Updated documentation to indicate ec2_image_id is required - Fixed template variable syntax in userdata template - Simplified runner.yml to pass inputs directly without redundant fallbacks - Use RUNNER_REGISTRATION_TIMEOUT constant instead of hardcoded value Users must now provide ec2_image_id either: 1. As a workflow input 2. Via repository/organization variable vars.EC2_IMAGE_ID This ensures ARM and x86 instances both get appropriate AMIs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2d2dbe5 commit f63e0a2

6 files changed

Lines changed: 24 additions & 23 deletions

File tree

.github/workflows/runner.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ on:
4343
required: false
4444
type: string
4545
ec2_image_id:
46-
description: "AWS AMI ID to use (falls back to vars.EC2_IMAGE_ID, then ami-0e86e20dae9224db8 – Ubuntu 24.04 LTS)"
46+
description: "AWS AMI ID to use (required - must be provided via input or vars.EC2_IMAGE_ID)"
4747
required: false
4848
type: string
4949
ec2_instance_profile:
@@ -59,7 +59,7 @@ on:
5959
required: false
6060
type: string
6161
ec2_launch_role:
62-
description: "AWS role ARN to assume for EC2 operations (falls back to vars.EC2_LAUNCH_ROLE; one or the other is required)"
62+
description: "AWS role ARN to assume for EC2 operations (falls back to vars.EC2_LAUNCH_ROLE)"
6363
required: false
6464
type: string
6565
ec2_root_device_size:
@@ -159,22 +159,22 @@ jobs:
159159
with:
160160
aws_region: ${{ inputs.aws_region }}
161161
aws_tags: ${{ inputs.aws_tags }}
162-
cloudwatch_logs_group: ${{ inputs.cloudwatch_logs_group || vars.CLOUDWATCH_LOGS_GROUP }}
163-
ec2_image_id: ${{ inputs.ec2_image_id || vars.EC2_IMAGE_ID || 'ami-0e86e20dae9224db8' }}
164-
ec2_instance_type: ${{ inputs.ec2_instance_type || vars.EC2_INSTANCE_TYPE || 't3.medium' }}
165-
ec2_instance_profile: ${{ inputs.ec2_instance_profile || vars.EC2_INSTANCE_PROFILE }}
166-
ec2_home_dir: ${{ inputs.ec2_home_dir || vars.EC2_HOME_DIR }}
167-
ec2_key_name: ${{ inputs.ec2_key_name || vars.EC2_KEY_NAME }}
162+
cloudwatch_logs_group: ${{ inputs.cloudwatch_logs_group }}
163+
ec2_image_id: ${{ inputs.ec2_image_id }}
164+
ec2_instance_type: ${{ inputs.ec2_instance_type }}
165+
ec2_instance_profile: ${{ inputs.ec2_instance_profile }}
166+
ec2_home_dir: ${{ inputs.ec2_home_dir }}
167+
ec2_key_name: ${{ inputs.ec2_key_name }}
168168
ec2_root_device_size: ${{ inputs.ec2_root_device_size }}
169-
ec2_security_group_id: ${{ inputs.ec2_security_group_id || vars.EC2_SECURITY_GROUP_ID }}
169+
ec2_security_group_id: ${{ inputs.ec2_security_group_id }}
170170
ec2_userdata: ${{ inputs.ec2_userdata }}
171171
instance_count: ${{ inputs.instance_count }}
172172
instance_name: ${{ inputs.instance_name }}
173-
max_instance_lifetime: ${{ inputs.max_instance_lifetime || vars.MAX_INSTANCE_LIFETIME || '360' }}
174-
runner_initial_grace_period: ${{ inputs.runner_initial_grace_period || vars.RUNNER_INITIAL_GRACE_PERIOD || '180' }}
175-
runner_grace_period: ${{ inputs.runner_grace_period || vars.RUNNER_GRACE_PERIOD || '60' }}
176-
runner_poll_interval: ${{ inputs.runner_poll_interval || vars.RUNNER_POLL_INTERVAL || '10' }}
177-
runner_registration_timeout: ${{ inputs.runner_registration_timeout || vars.RUNNER_REGISTRATION_TIMEOUT || '600' }}
178-
ssh_pubkey: ${{ inputs.ssh_pubkey || vars.SSH_PUBKEY }}
173+
max_instance_lifetime: ${{ inputs.max_instance_lifetime }}
174+
runner_initial_grace_period: ${{ inputs.runner_initial_grace_period }}
175+
runner_grace_period: ${{ inputs.runner_grace_period }}
176+
runner_poll_interval: ${{ inputs.runner_poll_interval }}
177+
runner_registration_timeout: ${{ inputs.runner_registration_timeout }}
178+
ssh_pubkey: ${{ inputs.ssh_pubkey }}
179179
env:
180180
GH_PAT: ${{ secrets.GH_SA_TOKEN }}

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ inputs:
2020
description: "Home directory on the AWS instance (falls back to vars.EC2_HOME_DIR, then auto-detection)"
2121
required: false
2222
ec2_image_id:
23-
description: "AWS AMI ID to use (falls back to vars.EC2_IMAGE_ID, then ami-0e86e20dae9224db8 – Ubuntu 24.04 LTS)"
23+
description: "AWS AMI ID to use (required - must be provided via input or vars.EC2_IMAGE_ID)"
2424
required: false
2525
ec2_instance_profile:
2626
description: "Instance profile name to attach to launched EC2 instance (required for CloudWatch logging)"

src/ec2_gha/__main__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
RUNNER_REGISTRATION_TIMEOUT,
88
INSTANCE_NAME,
99
INSTANCE_COUNT,
10-
EC2_IMAGE_ID,
1110
EC2_INSTANCE_TYPE,
1211
)
1312
from gha_runner.gh import GitHubInstance
@@ -70,8 +69,11 @@ def main():
7069
params.setdefault("runner_initial_grace_period", RUNNER_INITIAL_GRACE_PERIOD)
7170
params.setdefault("runner_poll_interval", RUNNER_POLL_INTERVAL)
7271
params.setdefault("instance_name", INSTANCE_NAME)
73-
params.setdefault("image_id", EC2_IMAGE_ID)
7472
params.setdefault("instance_type", EC2_INSTANCE_TYPE)
73+
74+
# image_id is required - must be provided via input or vars
75+
if not params.get("image_id"):
76+
raise Exception("EC2 AMI ID (ec2_image_id) must be provided via input or vars.EC2_IMAGE_ID")
7577
# home_dir will be set to AUTO in start.py if not provided
7678

7779
gh = GitHubInstance(token=token, repo=repo)

src/ec2_gha/defaults.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
RUNNER_REGISTRATION_TIMEOUT = "600" # 10 minutes (in seconds)
99

1010
# EC2 instance defaults
11-
EC2_IMAGE_ID = "ami-0e86e20dae9224db8" # Ubuntu 24.04 LTS x86_64
1211
EC2_INSTANCE_TYPE = "t3.medium"
1312

1413
# Instance naming default template

src/ec2_gha/start.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from gha_runner.helper.workflow_cmds import output
1212
from copy import deepcopy
1313

14-
from ec2_gha.defaults import AUTO
14+
from ec2_gha.defaults import AUTO, RUNNER_REGISTRATION_TIMEOUT
1515

1616

1717
@dataclass
@@ -302,7 +302,7 @@ def create_instances(self) -> dict[str, str]:
302302
"runner_grace_period": self.runner_grace_period,
303303
"runner_initial_grace_period": self.runner_initial_grace_period,
304304
"runner_poll_interval": self.runner_poll_interval,
305-
"runner_registration_timeout": environ.get("INPUT_RUNNER_REGISTRATION_TIMEOUT", "600"),
305+
"runner_registration_timeout": environ.get("INPUT_RUNNER_REGISTRATION_TIMEOUT", RUNNER_REGISTRATION_TIMEOUT),
306306
"runner_release": self.runner_release,
307307
"script": self.script,
308308
"ssh_pubkey": self.ssh_pubkey,

src/ec2_gha/templates/user-script.sh.templ

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ terminate_instance() {
2222
# Trap errors and ensure termination on failure
2323
trap 'terminate_instance "Setup script failed with error on line $$LINENO"' ERR
2424

25-
# Set up registration timeout failsafe (default 10 minutes if not specified)
26-
REGISTRATION_TIMEOUT=$${runner_registration_timeout:-600}
25+
# Set up registration timeout failsafe
26+
REGISTRATION_TIMEOUT=$runner_registration_timeout
2727
(
2828
echo "[$$( date '+%Y-%m-%d %H:%M:%S')] Watchdog: Starting $$REGISTRATION_TIMEOUT second timeout" >> /var/log/runner-setup.log
2929
sleep $$REGISTRATION_TIMEOUT

0 commit comments

Comments
 (0)