diff --git a/images/linux-amzn2/github_agent.linux.pkr.hcl b/images/linux-amzn2/github_agent.linux.pkr.hcl index 566423d03f..a930814fa3 100644 --- a/images/linux-amzn2/github_agent.linux.pkr.hcl +++ b/images/linux-amzn2/github_agent.linux.pkr.hcl @@ -7,10 +7,10 @@ packer { } } -variable "action_runner_url" { - description = "The URL to the tarball of the action runner" +variable "runner_version" { + description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases" type = string - default = "https://github.com/actions/runner/releases/download/v2.284.0/actions-runner-linux-x64-2.284.0.tar.gz" + default = "2.286.0" } variable "region" { @@ -19,10 +19,41 @@ variable "region" { default = "eu-west-1" } +variable "security_group_id" { + description = "The ID of the security group Packer will associate with the builder to enable access" + type = string + default = null +} + +variable "subnet_id" { + description = "If using VPC, the ID of the subnet, such as subnet-12345def, where Packer will launch the EC2 instance. This field is required if you are using an non-default VPC" + type = string + default = null +} + +variable "instance_type" { + description = "The instance type Packer will use for the builder" + type = string + default = "m3.medium" +} + +variable "root_volume_size_gb" { + type = number + default = 8 +} + +variable "tags" { + description = "Additional tags to add globally" + type = map(string) + default = {} +} + source "amazon-ebs" "githubrunner" { - ami_name = "github-runner-amzn2-x86_64-${formatdate("YYYYMMDDhhmm", timestamp())}" - instance_type = "m3.medium" - region = var.region + ami_name = "github-runner-amzn2-x86_64-${formatdate("YYYYMMDDhhmm", timestamp())}" + instance_type = var.instance_type + region = var.region + security_group_id = var.security_group_id + subnet_id = var.subnet_id source_ami_filter { filters = { name = "amzn2-ami-hvm-2.*-x86_64-ebs" @@ -33,10 +64,18 @@ source "amazon-ebs" "githubrunner" { owners = ["137112412989"] } ssh_username = "ec2-user" - tags = { - OS_Version = "amzn2" - Release = "Latest" - Base_AMI_Name = "{{ .SourceAMIName }}" + tags = merge( + var.tags, + { + OS_Version = "amzn2" + Release = "Latest" + Base_AMI_Name = "{{ .SourceAMIName }}" + }) + + launch_block_device_mappings { + device_name = "/dev/xvda" + volume_size = "${var.root_volume_size_gb}" + volume_type = "gp3" } } @@ -58,16 +97,24 @@ build { ] } - provisioner "shell" { - environment_vars = [ - "RUNNER_TARBALL_URL=${var.action_runner_url}" - ] - inline = [templatefile("../install-runner.sh", { + provisioner "file" { + content = templatefile("../install-runner.sh", { install_runner = templatefile("../../modules/runners/templates/install-runner.sh", { ARM_PATCH = "" S3_LOCATION_RUNNER_DISTRIBUTION = "" }) - })] + }) + destination = "/tmp/install-runner.sh" + } + + provisioner "shell" { + environment_vars = [ + "RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${var.runner_version}/actions-runner-linux-x64-${var.runner_version}.tar.gz" + ] + inline = [ + "sudo chmod +x /tmp/install-runner.sh", + "sudo RUNNER_TARBALL_URL=$RUNNER_TARBALL_URL /tmp/install-runner.sh" + ] } provisioner "file" { diff --git a/modules/runners/templates/install-runner.sh b/modules/runners/templates/install-runner.sh index 9ca7d4913e..3739973c74 100644 --- a/modules/runners/templates/install-runner.sh +++ b/modules/runners/templates/install-runner.sh @@ -13,7 +13,7 @@ file_name="actions-runner.tar.gz" echo "Creating actions-runner directory for the GH Action installtion" cd /opt/ -mkdir actions-runner && cd actions-runner +mkdir -p actions-runner && cd actions-runner if [[ -n "$RUNNER_TARBALL_URL" ]]; then echo "Downloading the GH Action runner from $RUNNER_TARBALL_URL to $file_name"