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

Commit da49078

Browse files
gautamg795npalm
andauthored
feat(images): automatically find latest GitHub Runner version when building images (#3129)
* feat: Automatically find latest GitHub Runner version when building images * update the rest of the packer configs * Update .github/workflows/packer-build.yml Co-authored-by: Niek Palm <[email protected]> --------- Co-authored-by: Niek Palm <[email protected]>
1 parent 569cff8 commit da49078

File tree

7 files changed

+93
-27
lines changed

7 files changed

+93
-27
lines changed

Diff for: .github/workflows/packer-build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
name: Verify packer
1616
runs-on: ubuntu-latest
1717
container:
18-
image: index.docker.io/hashicorp/packer@sha256:f795aace438ef92e738228c21d5ceb7d5dd73ceb7e0b1efab5b0e90cbc4d4dcd # ratchet:hashicorp/packer:1.7.8
18+
image: index.docker.io/hashicorp/packer@sha256:297bbbbbbf3ce9e0431ac1e8f02934b20e1197613f877b55dfdb1ebfd94eb748 # ratchet:index.docker.io/hashicorp/packer:1.8.6
1919
strategy:
2020
matrix:
2121
image: ["linux-amzn2", "windows-core-2019", "windows-core-2022", "ubuntu-focal", "ubuntu-jammy", "ubuntu-jammy-arm64"]
@@ -30,4 +30,4 @@ jobs:
3030
- name: check packer formatting
3131
run: packer fmt -recursive -check=true .
3232
- name: packer validate
33-
run: packer validate .
33+
run: packer validate -evaluate-datasources .

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ packer {
88
}
99

1010
variable "runner_version" {
11-
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases"
12-
type = string
13-
default = "2.295.0"
11+
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases. The latest release will be fetched from GitHub if not provided."
12+
default = null
1413
}
1514

1615
variable "region" {
@@ -78,6 +77,18 @@ variable "custom_shell_commands" {
7877
default = []
7978
}
8079

80+
data "http" github_runner_release_json {
81+
url = "https://api.github.com/repos/actions/runner/releases/latest"
82+
request_headers = {
83+
Accept = "application/vnd.github+json"
84+
X-GitHub-Api-Version : "2022-11-28"
85+
}
86+
}
87+
88+
locals {
89+
runner_version = coalesce(var.runner_version, trimprefix(jsondecode(data.http.github_runner_release_json.body).tag_name, "v"))
90+
}
91+
8192
source "amazon-ebs" "githubrunner" {
8293
ami_name = "github-runner-amzn2-x86_64-${formatdate("YYYYMMDDhhmm", timestamp())}"
8394
instance_type = var.instance_type
@@ -148,7 +159,7 @@ build {
148159

149160
provisioner "shell" {
150161
environment_vars = [
151-
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${var.runner_version}/actions-runner-linux-x64-${var.runner_version}.tar.gz"
162+
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${local.runner_version}/actions-runner-linux-x64-${local.runner_version}.tar.gz"
152163
]
153164
inline = [
154165
"sudo chmod +x /tmp/install-runner.sh",

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ packer {
88
}
99

1010
variable "runner_version" {
11-
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases"
12-
type = string
13-
default = "2.286.1"
11+
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases. The latest release will be fetched from GitHub if not provided."
12+
default = null
1413
}
1514

1615
variable "region" {
@@ -78,6 +77,18 @@ variable "custom_shell_commands" {
7877
default = []
7978
}
8079

80+
data "http" github_runner_release_json {
81+
url = "https://api.github.com/repos/actions/runner/releases/latest"
82+
request_headers = {
83+
Accept = "application/vnd.github+json"
84+
X-GitHub-Api-Version : "2022-11-28"
85+
}
86+
}
87+
88+
locals {
89+
runner_version = coalesce(var.runner_version, trimprefix(jsondecode(data.http.github_runner_release_json.body).tag_name, "v"))
90+
}
91+
8192
source "amazon-ebs" "githubrunner" {
8293
ami_name = "github-runner-ubuntu-focal-amd64-${formatdate("YYYYMMDDhhmm", timestamp())}"
8394
instance_type = var.instance_type
@@ -159,7 +170,7 @@ build {
159170

160171
provisioner "shell" {
161172
environment_vars = [
162-
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${var.runner_version}/actions-runner-linux-x64-${var.runner_version}.tar.gz"
173+
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${local.runner_version}/actions-runner-linux-x64-${local.runner_version}.tar.gz"
163174
]
164175
inline = [
165176
"sudo chmod +x /tmp/install-runner.sh",

Diff for: images/ubuntu-jammy-arm64/github_agent.ubuntu.pkr.hcl

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ packer {
88
}
99

1010
variable "runner_version" {
11-
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases"
12-
type = string
13-
default = "2.302.1"
11+
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases. The latest release will be fetched from GitHub if not provided."
12+
default = null
1413
}
1514

1615
variable "region" {
@@ -78,6 +77,18 @@ variable "custom_shell_commands" {
7877
default = []
7978
}
8079

80+
data "http" github_runner_release_json {
81+
url = "https://api.github.com/repos/actions/runner/releases/latest"
82+
request_headers = {
83+
Accept = "application/vnd.github+json"
84+
X-GitHub-Api-Version : "2022-11-28"
85+
}
86+
}
87+
88+
locals {
89+
runner_version = coalesce(var.runner_version, trimprefix(jsondecode(data.http.github_runner_release_json.body).tag_name, "v"))
90+
}
91+
8192
source "amazon-ebs" "githubrunner" {
8293
ami_name = "github-runner-ubuntu-jammy-arm64-${formatdate("YYYYMMDDhhmm", timestamp())}"
8394
instance_type = var.instance_type
@@ -159,7 +170,7 @@ build {
159170

160171
provisioner "shell" {
161172
environment_vars = [
162-
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${var.runner_version}/actions-runner-linux-arm64-${var.runner_version}.tar.gz"
173+
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${local.runner_version}/actions-runner-linux-arm64-${local.runner_version}.tar.gz"
163174
]
164175
inline = [
165176
"sudo chmod +x /tmp/install-runner.sh",

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ packer {
88
}
99

1010
variable "runner_version" {
11-
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases"
12-
type = string
13-
default = "2.294.0"
11+
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases. The latest release will be fetched from GitHub if not provided."
12+
default = null
1413
}
1514

1615
variable "region" {
@@ -78,6 +77,18 @@ variable "custom_shell_commands" {
7877
default = []
7978
}
8079

80+
data "http" github_runner_release_json {
81+
url = "https://api.github.com/repos/actions/runner/releases/latest"
82+
request_headers = {
83+
Accept = "application/vnd.github+json"
84+
X-GitHub-Api-Version : "2022-11-28"
85+
}
86+
}
87+
88+
locals {
89+
runner_version = coalesce(var.runner_version, trimprefix(jsondecode(data.http.github_runner_release_json.body).tag_name, "v"))
90+
}
91+
8192
source "amazon-ebs" "githubrunner" {
8293
ami_name = "github-runner-ubuntu-jammy-amd64-${formatdate("YYYYMMDDhhmm", timestamp())}"
8394
instance_type = var.instance_type
@@ -159,7 +170,7 @@ build {
159170

160171
provisioner "shell" {
161172
environment_vars = [
162-
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${var.runner_version}/actions-runner-linux-x64-${var.runner_version}.tar.gz"
173+
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${local.runner_version}/actions-runner-linux-x64-${local.runner_version}.tar.gz"
163174
]
164175
inline = [
165176
"sudo chmod +x /tmp/install-runner.sh",

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

+16-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ packer {
77
}
88
}
99

10-
variable "action_runner_url" {
11-
description = "The URL to the tarball of the action runner"
12-
type = string
13-
default = "https://github.com/actions/runner/releases/download/v2.285.1/actions-runner-win-x64-2.285.1.zip"
10+
variable "runner_version" {
11+
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases. The latest release will be fetched from GitHub if not provided."
12+
default = null
1413
}
1514

1615
variable "region" {
@@ -43,6 +42,18 @@ variable "custom_shell_commands" {
4342
default = []
4443
}
4544

45+
data "http" github_runner_release_json {
46+
url = "https://api.github.com/repos/actions/runner/releases/latest"
47+
request_headers = {
48+
Accept = "application/vnd.github+json"
49+
X-GitHub-Api-Version : "2022-11-28"
50+
}
51+
}
52+
53+
locals {
54+
runner_version = coalesce(var.runner_version, trimprefix(jsondecode(data.http.github_runner_release_json.body).tag_name, "v"))
55+
}
56+
4657
source "amazon-ebs" "githubrunner" {
4758
ami_name = "github-runner-windows-core-2019-${formatdate("YYYYMMDDhhmm", timestamp())}"
4859
communicator = "winrm"
@@ -92,7 +103,7 @@ build {
92103
provisioner "powershell" {
93104
inline = concat([
94105
templatefile("./windows-provisioner.ps1", {
95-
action_runner_url = var.action_runner_url
106+
action_runner_url = "https://github.com/actions/runner/releases/download/v${local.runner_version}/actions-runner-win-x64-${local.runner_version}.zip"
96107
})
97108
], var.custom_shell_commands)
98109
}

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ packer {
88
}
99

1010
variable "runner_version" {
11-
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases"
12-
type = string
13-
default = "2.286.1"
11+
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases. The latest release will be fetched from GitHub if not provided."
12+
default = null
1413
}
1514

1615
variable "region" {
@@ -54,6 +53,18 @@ variable "custom_shell_commands" {
5453
default = []
5554
}
5655

56+
data "http" github_runner_release_json {
57+
url = "https://api.github.com/repos/actions/runner/releases/latest"
58+
request_headers = {
59+
Accept = "application/vnd.github+json"
60+
X-GitHub-Api-Version : "2022-11-28"
61+
}
62+
}
63+
64+
locals {
65+
runner_version = coalesce(var.runner_version, trimprefix(jsondecode(data.http.github_runner_release_json.body).tag_name, "v"))
66+
}
67+
5768
source "amazon-ebs" "githubrunner" {
5869
ami_name = "github-runner-windows-core-2022-${formatdate("YYYYMMDDhhmm", timestamp())}"
5970
communicator = "winrm"
@@ -106,7 +117,7 @@ build {
106117
provisioner "powershell" {
107118
inline = concat([
108119
templatefile("./windows-provisioner.ps1", {
109-
action_runner_url = "https://github.com/actions/runner/releases/download/v${var.runner_version}/actions-runner-win-x64-${var.runner_version}.zip"
120+
action_runner_url = "https://github.com/actions/runner/releases/download/v${local.runner_version}/actions-runner-win-x64-${local.runner_version}.zip"
110121
})
111122
], var.custom_shell_commands)
112123
}

0 commit comments

Comments
 (0)