Skip to content

Commit dac5853

Browse files
committed
Parameterize architecture
1 parent aeaca0c commit dac5853

File tree

2 files changed

+18
-212
lines changed

2 files changed

+18
-212
lines changed

images/linux-al2023-arm/github_agent.linux.pkr.hcl

Lines changed: 0 additions & 204 deletions
This file was deleted.

images/linux-al2023/github_agent.linux.pkr.hcl

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
packer {
22
required_plugins {
33
amazon = {
4-
version = ">= 0.0.2"
4+
version = ">= 1.0.0"
55
source = "github.com/hashicorp/amazon"
66
}
77
}
@@ -12,6 +12,16 @@ variable "runner_version" {
1212
default = null
1313
}
1414

15+
variable "architecture" {
16+
description = "The architecture of the runner. Supported values are 'x86-64' and 'arm64'"
17+
type = string
18+
default = "x86_64"
19+
validation {
20+
condition = contains(["arm64", "x86_64"], var.architecture)
21+
error_message = "`lambda_architecture` value is not valid, valid values are: `arm64` and `x86_64`."
22+
}
23+
}
24+
1525
variable "region" {
1626
description = "The region to build the image in"
1727
type = string
@@ -39,7 +49,7 @@ variable "associate_public_ip_address" {
3949
variable "instance_type" {
4050
description = "The instance type Packer will use for the builder"
4151
type = string
42-
default = "m3.medium"
52+
default = "t4g.small"
4353
}
4454

4555
variable "iam_instance_profile" {
@@ -99,12 +109,13 @@ data "http" github_runner_release_json {
99109

100110
locals {
101111
runner_version = coalesce(var.runner_version, trimprefix(jsondecode(data.http.github_runner_release_json.body).tag_name, "v"))
112+
instance_type = coalesce(var.instance_type, var.architecture == "arm64" ? "t4g.small" : "m3.medium")
102113
}
103114

104115
source "amazon-ebs" "githubrunner" {
105-
ami_name = "github-runner-al2023-x86_64-${formatdate("YYYYMMDDhhmm", timestamp())}"
116+
ami_name = "github-runner-al2023-${var.architecture}-${formatdate("YYYYMMDDhhmm", timestamp())}"
106117
instance_type = var.instance_type
107-
iam_instance_profile = var.iam_instance_profile
118+
iam_instance_profile = var.iam_instance_profile
108119
region = var.region
109120
security_group_id = var.security_group_id
110121
subnet_id = var.subnet_id
@@ -113,7 +124,7 @@ source "amazon-ebs" "githubrunner" {
113124

114125
source_ami_filter {
115126
filters = {
116-
name = "al2023-ami-2023.*-kernel-6.*-x86_64"
127+
name = "al2023-ami-2023.*-kernel-6.*-${var.architecture}"
117128
root-device-type = "ebs"
118129
virtualization-type = "hvm"
119130
}
@@ -166,20 +177,19 @@ build {
166177
install_runner = templatefile("../../modules/runners/templates/install-runner.sh", {
167178
ARM_PATCH = ""
168179
S3_LOCATION_RUNNER_DISTRIBUTION = ""
169-
RUNNER_ARCHITECTURE = "x64"
170180
})
171181
})
172182
destination = "/tmp/install-runner.sh"
173183
}
174184

175185
provisioner "shell" {
176186
environment_vars = [
177-
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${local.runner_version}/actions-runner-linux-x64-${local.runner_version}.tar.gz"
187+
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${local.runner_version}/actions-runner-linux-${var.architecture}-${local.runner_version}.tar.gz"
178188
]
179189
inline = [
180190
"sudo chmod +x /tmp/install-runner.sh",
181191
"echo ec2-user > /tmp/install-user.txt",
182-
"sudo RUNNER_ARCHITECTURE=x64 RUNNER_TARBALL_URL=$RUNNER_TARBALL_URL /tmp/install-runner.sh"
192+
"sudo RUNNER_TARBALL_URL=$RUNNER_TARBALL_URL /tmp/install-runner.sh"
183193
]
184194
}
185195

0 commit comments

Comments
 (0)