Skip to content

Commit 7dd962d

Browse files
committed
chore(ci): read Go version from go.mod toolchain directive
Replace hardcoded Go version across the Taskfile and Dockerfiles with a single GO_VERSION variable extracted from go.mod's toolchain directive. This makes go.mod the single source of truth for the Go version, removing the need to keep 3 Taskfile tasks and 2 Dockerfiles in sync via Renovate's custom regex manager. Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
1 parent 28a608e commit 7dd962d

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

Taskfile.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ output: prefixed
66

77
# Variables that are shared across tasks.
88
vars:
9+
GO_VERSION:
10+
sh: sed -n 's/^toolchain go//p' go.mod
911
# renovate: datasource=docker depName=kindest/node versioning=semver
1012
E2E_KUBERNETES_VERSION: v1.35.0
1113
E2E_CLUSTER_NAME: barman-cloud-plugin-e2e-{{.E2E_KUBERNETES_VERSION}}
@@ -128,16 +130,14 @@ tasks:
128130
go-test:
129131
desc: Run go test
130132
env:
131-
# renovate: datasource=docker depName=golang versioning=semver
132-
GOLANG_IMAGE_VERSION: 1.26.1
133133
# renovate: datasource=git-refs depname=kubernetes packageName=https://github.com/kubernetes/kubernetes versioning=semver
134134
K8S_VERSION: 1.31.0
135135
# renovate: datasource=git-refs depName=controller-runtime packageName=https://github.com/kubernetes-sigs/controller-runtime versioning=semver
136136
SETUP_ENVTEST_VERSION: 0.23.1
137137
cmds:
138138
- >
139139
GITHUB_REF= dagger -s call -m ./dagger/gotest
140-
--go-version ${GOLANG_IMAGE_VERSION}
140+
--go-version {{.GO_VERSION}}
141141
--kube-version ${K8S_VERSION}
142142
--setup-envtest-version ${SETUP_ENVTEST_VERSION}
143143
unit-test --src .
@@ -231,7 +231,7 @@ tasks:
231231
cmds:
232232
- >
233233
GITHUB_REF= dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
234-
build --dir . --file containers/Dockerfile.plugin --platform linux/amd64
234+
build --dir . --file containers/Dockerfile.plugin --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64
235235
publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/plugin-barman-cloud --tags testing
236236
237237
# We build an image and push it to a local registry.
@@ -248,7 +248,7 @@ tasks:
248248
cmds:
249249
- >
250250
GITHUB_REF= dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
251-
build --dir . --file containers/Dockerfile.sidecar --platform linux/amd64
251+
build --dir . --file containers/Dockerfile.sidecar --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64
252252
publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/sidecar-barman-cloud --tags testing
253253
254254
build-images:
@@ -305,8 +305,6 @@ tasks:
305305
- build-images
306306
- start-kind-cluster
307307
vars:
308-
# renovate: datasource=docker depName=golang versioning=semver
309-
GOLANG_IMAGE_VERSION: 1.26.1
310308
KUBECONFIG_PATH:
311309
sh: mktemp -t kubeconfig-XXXXX
312310
env:
@@ -317,15 +315,12 @@ tasks:
317315
GITHUB_REF= dagger call -m dagger/e2e/ run
318316
--source .
319317
--kubeconfig {{.KUBECONFIG_PATH}}
320-
--go-version {{ .GOLANG_IMAGE_VERSION }}
318+
--go-version {{.GO_VERSION}}
321319
322320
e2e-ephemeral:
323321
desc: Run e2e tests in an ephemeral k3s cluster
324322
deps:
325323
- build-images
326-
vars:
327-
# renovate: datasource=docker depName=golang versioning=semver
328-
GOLANG_IMAGE_VERSION: 1.26.1
329324
env:
330325
_EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }}
331326
cmds:
@@ -334,7 +329,7 @@ tasks:
334329
--source .
335330
--ca certs/ca.pem
336331
--registry {{.REGISTRY_NAME}}:{{.REGISTRY_PORT}}
337-
--go-version {{ .GOLANG_IMAGE_VERSION }}
332+
--go-version {{.GO_VERSION}}
338333
339334
ci:
340335
desc: Run the CI pipeline
@@ -373,12 +368,12 @@ tasks:
373368
- >
374369
dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
375370
--registry ghcr.io --username $REGISTRY_USER --password env:REGISTRY_PASSWORD
376-
build --dir . --file containers/Dockerfile.plugin --platform linux/amd64 --platform linux/arm64
371+
build --dir . --file containers/Dockerfile.plugin --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64 --platform linux/arm64
377372
publish --ref {{.PLUGIN_IMAGE_NAME}} --tags {{.IMAGE_VERSION}}
378373
- >
379374
dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
380375
--registry ghcr.io --username $REGISTRY_USER --password env:REGISTRY_PASSWORD
381-
build --dir . --file containers/Dockerfile.sidecar --platform linux/amd64 --platform linux/arm64
376+
build --dir . --file containers/Dockerfile.sidecar --args GO_VERSION={{.GO_VERSION}} --platform linux/amd64 --platform linux/arm64
382377
publish --ref {{.SIDECAR_IMAGE_NAME}} --tags {{.IMAGE_VERSION}}
383378
384379
controller-gen:

containers/Dockerfile.plugin

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Build the manager binary
2-
FROM --platform=$BUILDPLATFORM golang:1.26.1 AS gobuilder
2+
ARG GO_VERSION
3+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS gobuilder
34
ARG TARGETOS
45
ARG TARGETARCH
56

containers/Dockerfile.sidecar

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# Both components are built before going into a distroless container
66

77
# Build the manager binary
8-
FROM --platform=$BUILDPLATFORM golang:1.26.1 AS gobuilder
8+
ARG GO_VERSION
9+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS gobuilder
910
ARG TARGETOS
1011
ARG TARGETARCH
1112

0 commit comments

Comments
 (0)