Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(packer): add vars and minor clean up #1611

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
79 changes: 63 additions & 16 deletions images/linux-amzn2/github_agent.linux.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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"
Expand All @@ -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"
}
}

Expand All @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion modules/runners/templates/install-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down