From 3652d39e049f41455524d7f3eb48fe26b181f33f Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Thu, 1 Feb 2024 16:49:36 -0800 Subject: [PATCH] force GOTOOLCHAIN="go${GO_VERSION}" for now TODO: look at using deprecating .go-version in favor of GOTOOLCHAIN existing knobs --- Makefile | 3 ++- hack/build/gotoolchain.sh | 23 +++++++++++++++++++++++ hack/build/setup-go.sh | 3 ++- images/base/Dockerfile | 5 +++++ images/kindnetd/Dockerfile | 2 ++ images/local-path-provisioner/Dockerfile | 1 + 6 files changed, 35 insertions(+), 2 deletions(-) create mode 100755 hack/build/gotoolchain.sh diff --git a/Makefile b/Makefile index 566da0ea..c7ec3ac6 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ COMMIT_COUNT?=$(shell git describe --tags | rev | cut -d- -f2 | rev) # ========================= Setup Go With Gimme ================================ # go version to use for build etc. # setup correct go version with gimme +GOTOOLCHAIN:=$(shell . hack/build/gotoolchain.sh && echo "$${GOTOOLCHAIN}") PATH:=$(shell . hack/build/setup-go.sh && echo "$${PATH}") # go1.9+ can autodetect GOROOT, but if some other tool sets it ... GOROOT:= @@ -40,7 +41,7 @@ GOROOT:= GO111MODULE=on # disable CGO by default for static binaries CGO_ENABLED=0 -export PATH GOROOT GO111MODULE CGO_ENABLED +export PATH GOROOT GO111MODULE CGO_ENABLED GOTOOLCHAIN # work around broken PATH export SPACE:=$(subst ,, ) SHELL:=env PATH=$(subst $(SPACE),\$(SPACE),$(PATH)) $(SHELL) diff --git a/hack/build/gotoolchain.sh b/hack/build/gotoolchain.sh new file mode 100755 index 00000000..96f4c757 --- /dev/null +++ b/hack/build/gotoolchain.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Copyright 2020 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# script to set GOTOOLCHAIN as needed +# MUST BE RUN FROM THE REPO ROOT DIRECTORY + +# read go-version file unless GO_VERSION is set +GO_VERSION="${GO_VERSION:-"$(cat .go-version)"}" + +GOTOOLCHAIN="go${GO_VERSION}" +export GOTOOLCHAIN GO_VERSION diff --git a/hack/build/setup-go.sh b/hack/build/setup-go.sh index b1b48a4e..e55f2da4 100755 --- a/hack/build/setup-go.sh +++ b/hack/build/setup-go.sh @@ -17,7 +17,8 @@ # MUST BE RUN FROM THE REPO ROOT DIRECTORY # read go-version file unless GO_VERSION is set -GO_VERSION="${GO_VERSION:-"$(cat .go-version)"}" +# override GOTOOLCHAIN unless set as well +. ./hack/build/gotoolchain.sh # we don't actually care where the .env files are # however, GIMME_SILENT_ENV doesn't trigger re-generating a .env if it diff --git a/images/base/Dockerfile b/images/base/Dockerfile index e0ba668f..5198ce9b 100644 --- a/images/base/Dockerfile +++ b/images/base/Dockerfile @@ -115,6 +115,7 @@ RUN dpkg --add-architecture arm64 && dpkg --add-architecture amd64 \ # set by makefile to .go-version ARG GO_VERSION RUN eval "$(gimme "${GO_VERSION}")" \ + && export GOTOOLCHAIN="go${GO_VERSION}" \ && GOBIN=/usr/local/bin go install github.com/google/go-licenses@latest @@ -130,6 +131,7 @@ RUN git clone --filter=tree:0 "${CONTAINERD_CLONE_URL}" /containerd \ && cd /containerd \ && git checkout "${CONTAINERD_VERSION}" \ && eval "$(gimme "${GO_VERSION}")" \ + && export GOTOOLCHAIN="go${GO_VERSION}" \ && export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \ && make bin/ctr bin/containerd bin/containerd-shim-runc-v2 \ && GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES \ @@ -144,6 +146,7 @@ RUN git clone --filter=tree:0 "${RUNC_CLONE_URL}" /runc \ && cd /runc \ && git checkout "${RUNC_VERSION}" \ && eval "$(gimme "${GO_VERSION}")" \ + && export GOTOOLCHAIN="go${GO_VERSION}" \ && export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \ && make runc \ && GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES . @@ -170,6 +173,7 @@ RUN git clone --filter=tree:0 "${CNI_PLUGINS_CLONE_URL}" /cni-plugins \ && cd /cni-plugins \ && git checkout "${CNI_PLUGINS_VERSION}" \ && eval "$(gimme "${GO_VERSION}")" \ + && export GOTOOLCHAIN="go${GO_VERSION}" \ && mkdir ./bin \ && export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \ && go build -o ./bin/host-local -mod=vendor ./plugins/ipam/host-local \ @@ -190,6 +194,7 @@ RUN git clone --filter=tree:0 "${CONTAINERD_FUSE_OVERLAYFS_CLONE_URL}" /fuse-ove && cd /fuse-overlayfs-snapshotter \ && git checkout "${CONTAINERD_FUSE_OVERLAYFS_VERSION}" \ && eval "$(gimme "${GO_VERSION}")" \ + && export GOTOOLCHAIN="go${GO_VERSION}" \ && export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \ && make bin/containerd-fuse-overlayfs-grpc \ && GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES ./cmd/containerd-fuse-overlayfs-grpc diff --git a/images/kindnetd/Dockerfile b/images/kindnetd/Dockerfile index 3d695130..1411f3f3 100644 --- a/images/kindnetd/Dockerfile +++ b/images/kindnetd/Dockerfile @@ -22,12 +22,14 @@ COPY go.mod go.sum ./ # set by makefile to .go-version ARG GO_VERSION RUN eval "$(gimme "${GO_VERSION}")" \ + && export GOTOOLCHAIN="go${GO_VERSION}" \ && go mod download \ && GOBIN=/usr/local/bin go install github.com/google/go-licenses@latest # build COPY . . ARG TARGETARCH RUN eval "$(gimme "${GO_VERSION}")" \ + && export GOTOOLCHAIN="go${GO_VERSION}" \ && CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o ./kindnetd ./cmd/kindnetd \ && GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES ./cmd/kindnetd diff --git a/images/local-path-provisioner/Dockerfile b/images/local-path-provisioner/Dockerfile index 5c14e881..e4c4d717 100644 --- a/images/local-path-provisioner/Dockerfile +++ b/images/local-path-provisioner/Dockerfile @@ -20,6 +20,7 @@ ARG VERSION # set by makefile to .go-version ARG TARGETARCH GO_VERSION RUN eval "$(gimme "${GO_VERSION}")" \ + && export GOTOOLCHAIN="go${GO_VERSION}" \ && cd local-path-provisioner \ && git fetch && git checkout "${VERSION}" \ && GOARCH=$TARGETARCH scripts/build \