Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 8f9c342

Browse files
authored
feat: Add variable to specify custom commands while building the AMI (#1838)
Add ability to specify custom commands while building the AMI This can be used to install additional software or to customize anything else for the final AMI
1 parent 3f1a67f commit 8f9c342

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

Diff for: images/linux-amzn2/github_agent.linux.pkr.hcl

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ variable "snapshot_tags" {
7272
default = {}
7373
}
7474

75+
variable "custom_shell_commands" {
76+
description = "Additional commands to run on the EC2 instance, to customize the instance, like installing packages"
77+
type = list(string)
78+
default = []
79+
}
80+
7581
source "amazon-ebs" "githubrunner" {
7682
ami_name = "github-runner-amzn2-x86_64-${formatdate("YYYYMMDDhhmm", timestamp())}"
7783
instance_type = var.instance_type
@@ -118,15 +124,15 @@ build {
118124
]
119125
provisioner "shell" {
120126
environment_vars = []
121-
inline = [
127+
inline = concat([
122128
"sudo yum update -y",
123129
"sudo yum install -y amazon-cloudwatch-agent curl jq git",
124130
"sudo amazon-linux-extras install docker",
125131
"sudo systemctl enable docker.service",
126132
"sudo systemctl enable containerd.service",
127133
"sudo service docker start",
128134
"sudo usermod -a -G docker ec2-user",
129-
]
135+
], var.custom_shell_commands)
130136
}
131137

132138
provisioner "file" {

Diff for: images/ubuntu-focal/github_agent.ubuntu.pkr.hcl

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ variable "snapshot_tags" {
7272
default = {}
7373
}
7474

75+
variable "custom_shell_commands" {
76+
description = "Additional commands to run on the EC2 instance, to customize the instance, like installing packages"
77+
type = list(string)
78+
default = []
79+
}
80+
7581
source "amazon-ebs" "githubrunner" {
7682
ami_name = "github-runner-ubuntu-focal-amd64-${formatdate("YYYYMMDDhhmm", timestamp())}"
7783
instance_type = var.instance_type
@@ -120,7 +126,7 @@ build {
120126
environment_vars = [
121127
"DEBIAN_FRONTEND=noninteractive"
122128
]
123-
inline = [
129+
inline = concat([
124130
"sudo apt-get -y update",
125131
"sudo apt-get -y install ca-certificates curl gnupg lsb-release",
126132
"sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg",
@@ -136,7 +142,7 @@ build {
136142
"sudo curl -f https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip",
137143
"unzip awscliv2.zip",
138144
"sudo ./aws/install",
139-
]
145+
], var.custom_shell_commands)
140146
}
141147

142148
provisioner "file" {

Diff for: images/windows-core-2019/github_agent.windows.pkr.hcl

+11-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ variable "associate_public_ip_address" {
3131
default = null
3232
}
3333

34+
variable "custom_shell_commands" {
35+
description = "Additional commands to run on the EC2 instance, to customize the instance, like installing packages"
36+
type = list(string)
37+
default = []
38+
}
39+
3440
source "amazon-ebs" "githubrunner" {
3541
ami_name = "github-runner-windows-core-2019-${formatdate("YYYYMMDDhhmm", timestamp())}"
3642
communicator = "winrm"
@@ -78,8 +84,10 @@ build {
7884
}
7985

8086
provisioner "powershell" {
81-
inline = [templatefile("./windows-provisioner.ps1", {
82-
action_runner_url = var.action_runner_url
83-
})]
87+
inline = concat([
88+
templatefile("./windows-provisioner.ps1", {
89+
action_runner_url = var.action_runner_url
90+
})
91+
], var.custom_shell_commands)
8492
}
8593
}

0 commit comments

Comments
 (0)