diff --git a/images/linux-al2023/github_agent.linux.pkr.hcl b/images/linux-al2023/github_agent.linux.pkr.hcl index de72a9466f..929042f06a 100644 --- a/images/linux-al2023/github_agent.linux.pkr.hcl +++ b/images/linux-al2023/github_agent.linux.pkr.hcl @@ -1,7 +1,7 @@ packer { required_plugins { amazon = { - version = ">= 0.0.2" + version = ">= 1.0.0" source = "github.com/hashicorp/amazon" } } @@ -12,6 +12,16 @@ variable "runner_version" { default = null } +variable "architecture" { + description = "The architecture of the runner. Supported values are 'x64' and 'arm64'" + type = string + default = "x64" + validation { + condition = contains(["arm64", "x64"], var.architecture) + error_message = "`architecture` value is not valid, valid values are: `arm64` and `x64`." + } +} + variable "region" { description = "The region to build the image in" type = string @@ -39,7 +49,7 @@ variable "associate_public_ip_address" { variable "instance_type" { description = "The instance type Packer will use for the builder" type = string - default = "m3.medium" + default = null } variable "iam_instance_profile" { @@ -99,12 +109,13 @@ data "http" github_runner_release_json { locals { runner_version = coalesce(var.runner_version, trimprefix(jsondecode(data.http.github_runner_release_json.body).tag_name, "v")) + instance_type = coalesce(var.instance_type, var.architecture == "arm64" ? "t4g.medium" : "m3.medium") } source "amazon-ebs" "githubrunner" { - ami_name = "github-runner-al2023-x86_64-${formatdate("YYYYMMDDhhmm", timestamp())}" - instance_type = var.instance_type - iam_instance_profile = var.iam_instance_profile + ami_name = "github-runner-al2023-${var.architecture}-${formatdate("YYYYMMDDhhmm", timestamp())}" + instance_type = local.instance_type + iam_instance_profile = var.iam_instance_profile region = var.region security_group_id = var.security_group_id subnet_id = var.subnet_id @@ -113,7 +124,7 @@ source "amazon-ebs" "githubrunner" { source_ami_filter { filters = { - name = "al2023-ami-2023.*-kernel-6.*-x86_64" + name = "al2023-ami-2023.*-kernel-6.*-${var.architecture == "x64" ? "x86_64" : var.architecture}" root-device-type = "ebs" virtualization-type = "hvm" } @@ -166,7 +177,6 @@ build { install_runner = templatefile("../../modules/runners/templates/install-runner.sh", { ARM_PATCH = "" S3_LOCATION_RUNNER_DISTRIBUTION = "" - RUNNER_ARCHITECTURE = "x64" }) }) destination = "/tmp/install-runner.sh" @@ -174,12 +184,12 @@ build { provisioner "shell" { environment_vars = [ - "RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${local.runner_version}/actions-runner-linux-x64-${local.runner_version}.tar.gz" + "RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${local.runner_version}/actions-runner-linux-${var.architecture}-${local.runner_version}.tar.gz" ] inline = [ "sudo chmod +x /tmp/install-runner.sh", "echo ec2-user > /tmp/install-user.txt", - "sudo RUNNER_ARCHITECTURE=x64 RUNNER_TARBALL_URL=$RUNNER_TARBALL_URL /tmp/install-runner.sh" + "sudo RUNNER_TARBALL_URL=$RUNNER_TARBALL_URL /tmp/install-runner.sh" ] } diff --git a/modules/runners/templates/install-runner.sh b/modules/runners/templates/install-runner.sh index 05445eb98b..23fef8ac95 100644 --- a/modules/runners/templates/install-runner.sh +++ b/modules/runners/templates/install-runner.sh @@ -3,7 +3,6 @@ ## install the runner s3_location=${S3_LOCATION_RUNNER_DISTRIBUTION} -architecture=${RUNNER_ARCHITECTURE} if [ -z "$RUNNER_TARBALL_URL" ] && [ -z "$s3_location" ]; then echo "Neither RUNNER_TARBALL_URL or s3_location are set"