Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions images/linux-al2023/github_agent.linux.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
packer {
required_plugins {
amazon = {
version = ">= 0.0.2"
version = ">= 1.0.0"
source = "github.com/hashicorp/amazon"
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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
Expand All @@ -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"
}
Expand Down Expand Up @@ -166,20 +177,19 @@ build {
install_runner = templatefile("../../modules/runners/templates/install-runner.sh", {
ARM_PATCH = ""
S3_LOCATION_RUNNER_DISTRIBUTION = ""
RUNNER_ARCHITECTURE = "x64"
})
})
destination = "/tmp/install-runner.sh"
}

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"
]
}

Expand Down
1 change: 0 additions & 1 deletion modules/runners/templates/install-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## install the runner

s3_location=${S3_LOCATION_RUNNER_DISTRIBUTION}
architecture=${RUNNER_ARCHITECTURE}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason of removing this variable? Is it not used?


if [ -z "$RUNNER_TARBALL_URL" ] && [ -z "$s3_location" ]; then
echo "Neither RUNNER_TARBALL_URL or s3_location are set"
Expand Down