Skip to content

Commit 416d57c

Browse files
authored
validate installed golang version and honour VERSION build-args (#625)
1 parent 845d31d commit 416d57c

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

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

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

5050
find "go" -type f -name Dockerfile.tmpl -print0 |
5151
while IFS= read -r -d '' line; do
52-
${SED} -E -e "s#(ARG GOLANG_VERSION)=[0-9]+\.[0-9]+(\.[0-9]+)?#\1=${GO_RELEASE_VERSION}#g" "$line"
5352
if echo "$line" | grep -q 'arm' ; then
5453
${SED} -E -e "s#(ARG GOLANG_DOWNLOAD_SHA256)=.+#\1=${GOLANG_DOWNLOAD_SHA256_ARM}#g" "$line"
5554
if [ -n "$MSFT_DOWNLOAD_SHA256_ARM" ]; then

.github/updatecli.d/bump-microsoft.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,6 @@ conditions:
8888
command: grep 'ARG SECURITY_VERSION={{ source `securityVersion` }}' go/base/Dockerfile.tmpl && exit 1 || exit 0
8989
failwhen: false
9090

91-
# as long as the same golang version then update the security version.
92-
# if a new golang version then .github/updatecli.d/bump-golang.yml will be triggered.
93-
is-golang-available:
94-
name: Is version '{{ source "golangVersion" }}' available in 'go/base/Dockerfile.tmpl'?
95-
disablesourceinput: true
96-
kind: shell
97-
spec:
98-
command: grep 'ARG GOLANG_VERSION={{ source `golangVersion` }}' go/base/Dockerfile.tmpl && exit 0 || exit 1
99-
failwhen: false
100-
10191
targets:
10292
update-go-versions:
10393
name: 'Update go version {{ source "latestGoVersion" }}'

go/base-arm/Dockerfile.tmpl

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

60-
ARG GOLANG_VERSION=1.24.4
60+
ARG VERSION
6161
{{- if eq .FIPS "true"}}
6262
ARG SECURITY_VERSION=-1
63-
ARG GOLANG_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$GOLANG_VERSION$SECURITY_VERSION.linux-arm64.tar.gz
63+
ARG GOLANG_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$VERSION$SECURITY_VERSION.linux-arm64.tar.gz
6464
# Use a different arg name for microsoft/go sha so it can be handled seperately from the regular golang sha
6565
ARG MSFT_DOWNLOAD_SHA256=44b769dd398f8fc5f381812c2eb323b4bc6cb11010d59efdba3244184e29b3fd
6666
ARG DOWNLOAD_SHA256=$MSFT_DOWNLOAD_SHA256
6767
{{- else}}
68-
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-arm64.tar.gz
68+
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$VERSION.linux-arm64.tar.gz
6969
ARG GOLANG_DOWNLOAD_SHA256=d5501ee5aca0f258d5fe9bfaed401958445014495dc115f202d43d5210b45241
7070
ARG DOWNLOAD_SHA256=$GOLANG_DOWNLOAD_SHA256
7171
{{- end}}
@@ -82,6 +82,10 @@ ENV PATH $PATH:/usr/local/go/bin
8282
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
8383
WORKDIR $GOPATH
8484

85+
# Validate the Go installation
86+
RUN go version \
87+
&& go version | grep "go${VERSION}" || (echo "Go version mismatch: expected to contain go${VERSION}" && exit 1)
88+
8589
COPY rootfs /
8690

8791
# show the GLIBC version
@@ -91,7 +95,7 @@ WORKDIR /
9195

9296
RUN mkdir -p /root/.config/go/telemetry && echo "off 2024-08-23" > /root/.config/go/telemetry/mode
9397
ENV GOTOOLCHAIN local
94-
RUN go mod init github.com/elastic/golang-crossbuild-$GOLANG_VERSION-arm \
98+
RUN go mod init github.com/elastic/golang-crossbuild-$VERSION-arm \
9599
&& go get . \
96100
&& go env \
97101
&& echo "toolcompile=$(go tool compile -V)" \

go/base/Dockerfile.tmpl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ 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-
ARG GOLANG_VERSION=1.24.4
34+
ARG VERSION
3535
{{- if eq .FIPS "true"}}
3636
ARG SECURITY_VERSION=-1
37-
ARG GOLANG_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$GOLANG_VERSION$SECURITY_VERSION.linux-amd64.tar.gz
37+
ARG GOLANG_DOWNLOAD_URL=https://aka.ms/golang/release/latest/go$VERSION$SECURITY_VERSION.linux-amd64.tar.gz
3838
# Use a different arg name for microsoft/go sha so it can be handled seperately from the regular golang sha
3939
ARG MSFT_DOWNLOAD_SHA256=f21ddf7c3b029cf67615f6b2ca68e5aa83a50b2e2ea5952a5ea7bf9fa17e3358
4040
ARG DOWNLOAD_SHA256=$MSFT_DOWNLOAD_SHA256
4141
{{- else}}
42-
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
42+
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$VERSION.linux-amd64.tar.gz
4343
ARG GOLANG_DOWNLOAD_SHA256=77e5da33bb72aeaef1ba4418b6fe511bc4d041873cbf82e5aa6318740df98717
4444
ARG DOWNLOAD_SHA256=$GOLANG_DOWNLOAD_SHA256
4545
{{- end }}
@@ -56,6 +56,10 @@ ENV PATH $PATH:/usr/local/go/bin
5656
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
5757
WORKDIR $GOPATH
5858

59+
# Validate the Go installation
60+
RUN go version \
61+
&& go version | grep "go${VERSION}" || (echo "Go version mismatch: expected to contain go${VERSION}" && exit 1)
62+
5963
COPY rootfs /
6064

6165
# show the GLIBC version
@@ -64,7 +68,7 @@ RUN ldd --version
6468
WORKDIR /
6569
RUN mkdir -p /root/.config/go/telemetry && echo "off 2024-08-23" > /root/.config/go/telemetry/mode
6670
ENV GOTOOLCHAIN=local
67-
RUN go mod init github.com/elastic/golang-crossbuild-$GOLANG_VERSION \
71+
RUN go mod init github.com/elastic/golang-crossbuild-$VERSION \
6872
&& go get . \
6973
&& go env \
7074
&& echo "toolcompile=$(go tool compile -V)" \

0 commit comments

Comments
 (0)