Skip to content

Commit 15d0e7f

Browse files
v1vmergify[bot]
authored andcommitted
validate installed golang version and honour VERSION build-args (#625)
(cherry picked from commit 416d57c) # Conflicts: # .github/updatecli.d/bump-microsoft.yml # go/base-arm/Dockerfile.tmpl # go/base/Dockerfile.tmpl
1 parent 97b8a4a commit 15d0e7f

File tree

4 files changed

+134
-3
lines changed

4 files changed

+134
-3
lines changed

.github/updatecli.d/bump-go-release-version.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ echo "Update go version ${GO_RELEASE_VERSION}"
4343

4444
find "go" -type f -name Dockerfile.tmpl -print0 |
4545
while IFS= read -r -d '' line; do
46-
${SED} -E -e "s#(ARG GOLANG_VERSION)=[0-9]+\.[0-9]+(\.[0-9]+)?#\1=${GO_RELEASE_VERSION}#g" "$line"
4746
if echo "$line" | grep -q 'arm' ; then
4847
${SED} -E -e "s#(ARG GOLANG_DOWNLOAD_SHA256)=.+#\1=${GOLANG_DOWNLOAD_SHA256_ARM}#g" "$line"
4948
${SED} -E -e "s#(ARG MSFT_DOWNLOAD_SHA256)=.+#\1=${MSFT_DOWNLOAD_SHA256_ARM}#g" "$line"
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
name: Bump golang-microsoft to latest version
3+
pipelineid: 'bump-golang-microsoft-version-{{ requiredEnv "BRANCH" }}'
4+
5+
scms:
6+
githubConfig:
7+
kind: github
8+
spec:
9+
user: '{{ requiredEnv "GITHUB_ACTOR" }}'
10+
username: '{{ requiredEnv "GITHUB_ACTOR" }}'
11+
owner: elastic
12+
repository: golang-crossbuild
13+
token: '{{ requiredEnv "GITHUB_TOKEN" }}'
14+
branch: '{{ requiredEnv "BRANCH" }}'
15+
commitusingapi: true
16+
17+
actions:
18+
default:
19+
title: '[Automation] Bump Microsoft version to {{ source "latestGoVersion" }}'
20+
kind: github/pullrequest
21+
scmid: githubConfig
22+
spec:
23+
automerge: true
24+
labels:
25+
- automation
26+
- dependencies
27+
- backport-skip
28+
description: |
29+
See https://github.com/microsoft/go/releases/v{{ source "latestGoVersion" }}
30+
31+
sources:
32+
minor:
33+
name: Get minor version
34+
kind: shell
35+
transformers:
36+
- findsubmatch:
37+
pattern: '^\d+.(\d+)'
38+
captureindex: 1
39+
spec:
40+
command: echo {{ requiredEnv "GO_MINOR" }}
41+
42+
latestGoVersion:
43+
name: Get Latest Go Release
44+
kind: githubrelease
45+
dependson:
46+
- minor
47+
transformers:
48+
- trimprefix: v
49+
spec:
50+
owner: microsoft
51+
repository: go
52+
token: '{{ requiredEnv "GITHUB_TOKEN" }}'
53+
username: '{{ requiredEnv "GITHUB_ACTOR" }}'
54+
versionfilter:
55+
kind: regex
56+
pattern: v1\.{{ source "minor" }}\.(\d*)(-\d*)$
57+
58+
securityVersion:
59+
name: Get security version
60+
dependson:
61+
- latestGoVersion
62+
kind: shell
63+
transformers:
64+
- findsubmatch:
65+
pattern: '^1.{{ source "minor" }}.\d+(-\d+)'
66+
captureindex: 1
67+
spec:
68+
command: echo {{ source "latestGoVersion" }}
69+
70+
golangVersion:
71+
name: Get golang version
72+
dependson:
73+
- latestGoVersion
74+
kind: shell
75+
transformers:
76+
- findsubmatch:
77+
pattern: '^(\d+.\d+.\d+)-(\d+)'
78+
captureindex: 1
79+
spec:
80+
command: echo {{ source "latestGoVersion" }}
81+
82+
conditions:
83+
is-security-already-updated:
84+
name: Is security version '{{ source "securityVersion" }}' not updated in 'go/base/Dockerfile.tmpl'?
85+
disablesourceinput: true
86+
kind: shell
87+
spec:
88+
command: grep 'ARG SECURITY_VERSION={{ source `securityVersion` }}' go/base/Dockerfile.tmpl && exit 1 || exit 0
89+
failwhen: false
90+
91+
targets:
92+
update-go-versions:
93+
name: 'Update go version {{ source "latestGoVersion" }}'
94+
kind: shell
95+
sourceid: latestGoVersion
96+
scmid: githubConfig
97+
spec:
98+
command: .github/updatecli.d/bump-go-microsoft-version.sh
99+
environments:
100+
- name: PATH

go/base-arm/Dockerfile.tmpl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,27 @@ RUN \
5757
libsqlite3-0 \
5858
&& rm -rf /var/lib/apt/lists/*
5959

60+
<<<<<<< HEAD
6061
ARG GOLANG_VERSION=1.23.10
6162
{{- if eq .FIPS "true"}}
6263
ARG GOLANG_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$GOLANG_VERSION-1.linux-arm64.tar.gz
64+
=======
65+
ARG VERSION
66+
{{- if eq .FIPS "true"}}
67+
ARG SECURITY_VERSION=-1
68+
ARG GOLANG_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$VERSION$SECURITY_VERSION.linux-arm64.tar.gz
69+
>>>>>>> 416d57c (validate installed golang version and honour VERSION build-args (#625))
6370
# Use a different arg name for microsoft/go sha so it can be handled seperately from the regular golang sha
6471
ARG MSFT_DOWNLOAD_SHA256=901f023a7ad01b743f4f1f7c6e5dd12c03c2aaaebedd70f7eef415caae79510d
6572
ARG DOWNLOAD_SHA256=$MSFT_DOWNLOAD_SHA256
6673
{{- else}}
74+
<<<<<<< HEAD
6775
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-arm64.tar.gz
6876
ARG GOLANG_DOWNLOAD_SHA256=bfb1f1df7173f44648ee070a39ab0481068632f595305a699d89cd56a33b8081
77+
=======
78+
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$VERSION.linux-arm64.tar.gz
79+
ARG GOLANG_DOWNLOAD_SHA256=d5501ee5aca0f258d5fe9bfaed401958445014495dc115f202d43d5210b45241
80+
>>>>>>> 416d57c (validate installed golang version and honour VERSION build-args (#625))
6981
ARG DOWNLOAD_SHA256=$GOLANG_DOWNLOAD_SHA256
7082
{{- end}}
7183

@@ -81,6 +93,10 @@ ENV PATH $PATH:/usr/local/go/bin
8193
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
8294
WORKDIR $GOPATH
8395

96+
# Validate the Go installation
97+
RUN go version \
98+
&& go version | grep "go${VERSION}" || (echo "Go version mismatch: expected to contain go${VERSION}" && exit 1)
99+
84100
COPY rootfs /
85101

86102
# show the GLIBC version
@@ -90,7 +106,7 @@ WORKDIR /
90106

91107
RUN mkdir -p /root/.config/go/telemetry && echo "off 2024-08-23" > /root/.config/go/telemetry/mode
92108
ENV GOTOOLCHAIN local
93-
RUN go mod init github.com/elastic/golang-crossbuild-$GOLANG_VERSION-arm \
109+
RUN go mod init github.com/elastic/golang-crossbuild-$VERSION-arm \
94110
&& go get . \
95111
&& go env \
96112
&& echo "toolcompile=$(go tool compile -V)" \

go/base/Dockerfile.tmpl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,27 @@ RUN apt-get -o Acquire::Check-Valid-Until=false update -y --no-install-recommend
3131
RUN ln -s /usr/bin/pip3 /usr/bin/pip
3232
{{- end }}
3333

34+
<<<<<<< HEAD
3435
ARG GOLANG_VERSION=1.23.10
3536
{{- if eq .FIPS "true"}}
3637
ARG GOLANG_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$GOLANG_VERSION-1.linux-amd64.tar.gz
38+
=======
39+
ARG VERSION
40+
{{- if eq .FIPS "true"}}
41+
ARG SECURITY_VERSION=-1
42+
ARG GOLANG_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$VERSION$SECURITY_VERSION.linux-amd64.tar.gz
43+
>>>>>>> 416d57c (validate installed golang version and honour VERSION build-args (#625))
3744
# Use a different arg name for microsoft/go sha so it can be handled seperately from the regular golang sha
3845
ARG MSFT_DOWNLOAD_SHA256=c4ee22c0de9fd2ff2c0d0d1a446e5aac75c9e3a3bfdc16e25e32d2461c5347ed
3946
ARG DOWNLOAD_SHA256=$MSFT_DOWNLOAD_SHA256
4047
{{- else}}
48+
<<<<<<< HEAD
4149
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
4250
ARG GOLANG_DOWNLOAD_SHA256=535f9f81802499f2a7dbfa70abb8fda3793725fcc29460f719815f6e10b5fd60
51+
=======
52+
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$VERSION.linux-amd64.tar.gz
53+
ARG GOLANG_DOWNLOAD_SHA256=77e5da33bb72aeaef1ba4418b6fe511bc4d041873cbf82e5aa6318740df98717
54+
>>>>>>> 416d57c (validate installed golang version and honour VERSION build-args (#625))
4355
ARG DOWNLOAD_SHA256=$GOLANG_DOWNLOAD_SHA256
4456
{{- end }}
4557

@@ -55,6 +67,10 @@ ENV PATH $PATH:/usr/local/go/bin
5567
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
5668
WORKDIR $GOPATH
5769

70+
# Validate the Go installation
71+
RUN go version \
72+
&& go version | grep "go${VERSION}" || (echo "Go version mismatch: expected to contain go${VERSION}" && exit 1)
73+
5874
COPY rootfs /
5975

6076
# show the GLIBC version
@@ -63,7 +79,7 @@ RUN ldd --version
6379
WORKDIR /
6480
RUN mkdir -p /root/.config/go/telemetry && echo "off 2024-08-23" > /root/.config/go/telemetry/mode
6581
ENV GOTOOLCHAIN=local
66-
RUN go mod init github.com/elastic/golang-crossbuild-$GOLANG_VERSION \
82+
RUN go mod init github.com/elastic/golang-crossbuild-$VERSION \
6783
&& go get . \
6884
&& go env \
6985
&& echo "toolcompile=$(go tool compile -V)" \

0 commit comments

Comments
 (0)