force GOTOOLCHAIN="go${GO_VERSION}" for now

TODO: look at using deprecating .go-version in favor of GOTOOLCHAIN existing knobs
This commit is contained in:
Benjamin Elder
2024-02-01 16:49:36 -08:00
parent 2b793f9fce
commit 3652d39e04
6 changed files with 35 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ COMMIT_COUNT?=$(shell git describe --tags | rev | cut -d- -f2 | rev)
# ========================= Setup Go With Gimme ================================ # ========================= Setup Go With Gimme ================================
# go version to use for build etc. # go version to use for build etc.
# setup correct go version with gimme # setup correct go version with gimme
GOTOOLCHAIN:=$(shell . hack/build/gotoolchain.sh && echo "$${GOTOOLCHAIN}")
PATH:=$(shell . hack/build/setup-go.sh && echo "$${PATH}") PATH:=$(shell . hack/build/setup-go.sh && echo "$${PATH}")
# go1.9+ can autodetect GOROOT, but if some other tool sets it ... # go1.9+ can autodetect GOROOT, but if some other tool sets it ...
GOROOT:= GOROOT:=
@@ -40,7 +41,7 @@ GOROOT:=
GO111MODULE=on GO111MODULE=on
# disable CGO by default for static binaries # disable CGO by default for static binaries
CGO_ENABLED=0 CGO_ENABLED=0
export PATH GOROOT GO111MODULE CGO_ENABLED export PATH GOROOT GO111MODULE CGO_ENABLED GOTOOLCHAIN
# work around broken PATH export # work around broken PATH export
SPACE:=$(subst ,, ) SPACE:=$(subst ,, )
SHELL:=env PATH=$(subst $(SPACE),\$(SPACE),$(PATH)) $(SHELL) SHELL:=env PATH=$(subst $(SPACE),\$(SPACE),$(PATH)) $(SHELL)

23
hack/build/gotoolchain.sh Executable file
View File

@@ -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

View File

@@ -17,7 +17,8 @@
# MUST BE RUN FROM THE REPO ROOT DIRECTORY # MUST BE RUN FROM THE REPO ROOT DIRECTORY
# read go-version file unless GO_VERSION is set # 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 # we don't actually care where the .env files are
# however, GIMME_SILENT_ENV doesn't trigger re-generating a .env if it # however, GIMME_SILENT_ENV doesn't trigger re-generating a .env if it

View File

@@ -115,6 +115,7 @@ RUN dpkg --add-architecture arm64 && dpkg --add-architecture amd64 \
# set by makefile to .go-version # set by makefile to .go-version
ARG GO_VERSION ARG GO_VERSION
RUN eval "$(gimme "${GO_VERSION}")" \ RUN eval "$(gimme "${GO_VERSION}")" \
&& export GOTOOLCHAIN="go${GO_VERSION}" \
&& GOBIN=/usr/local/bin go install github.com/google/go-licenses@latest && 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 \ && cd /containerd \
&& git checkout "${CONTAINERD_VERSION}" \ && git checkout "${CONTAINERD_VERSION}" \
&& eval "$(gimme "${GO_VERSION}")" \ && eval "$(gimme "${GO_VERSION}")" \
&& export GOTOOLCHAIN="go${GO_VERSION}" \
&& export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \ && export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \
&& make bin/ctr bin/containerd bin/containerd-shim-runc-v2 \ && make bin/ctr bin/containerd bin/containerd-shim-runc-v2 \
&& GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES \ && GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES \
@@ -144,6 +146,7 @@ RUN git clone --filter=tree:0 "${RUNC_CLONE_URL}" /runc \
&& cd /runc \ && cd /runc \
&& git checkout "${RUNC_VERSION}" \ && git checkout "${RUNC_VERSION}" \
&& eval "$(gimme "${GO_VERSION}")" \ && eval "$(gimme "${GO_VERSION}")" \
&& export GOTOOLCHAIN="go${GO_VERSION}" \
&& export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \ && export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \
&& make runc \ && make runc \
&& GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES . && 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 \ && cd /cni-plugins \
&& git checkout "${CNI_PLUGINS_VERSION}" \ && git checkout "${CNI_PLUGINS_VERSION}" \
&& eval "$(gimme "${GO_VERSION}")" \ && eval "$(gimme "${GO_VERSION}")" \
&& export GOTOOLCHAIN="go${GO_VERSION}" \
&& mkdir ./bin \ && mkdir ./bin \
&& export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \ && export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \
&& go build -o ./bin/host-local -mod=vendor ./plugins/ipam/host-local \ && 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 \ && cd /fuse-overlayfs-snapshotter \
&& git checkout "${CONTAINERD_FUSE_OVERLAYFS_VERSION}" \ && git checkout "${CONTAINERD_FUSE_OVERLAYFS_VERSION}" \
&& eval "$(gimme "${GO_VERSION}")" \ && eval "$(gimme "${GO_VERSION}")" \
&& export GOTOOLCHAIN="go${GO_VERSION}" \
&& export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \ && export GOARCH=$TARGETARCH && export CC=$(target-cc) && export CGO_ENABLED=1 \
&& make bin/containerd-fuse-overlayfs-grpc \ && make bin/containerd-fuse-overlayfs-grpc \
&& GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES ./cmd/containerd-fuse-overlayfs-grpc && GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES ./cmd/containerd-fuse-overlayfs-grpc

View File

@@ -22,12 +22,14 @@ COPY go.mod go.sum ./
# set by makefile to .go-version # set by makefile to .go-version
ARG GO_VERSION ARG GO_VERSION
RUN eval "$(gimme "${GO_VERSION}")" \ RUN eval "$(gimme "${GO_VERSION}")" \
&& export GOTOOLCHAIN="go${GO_VERSION}" \
&& go mod download \ && go mod download \
&& GOBIN=/usr/local/bin go install github.com/google/go-licenses@latest && GOBIN=/usr/local/bin go install github.com/google/go-licenses@latest
# build # build
COPY . . COPY . .
ARG TARGETARCH ARG TARGETARCH
RUN eval "$(gimme "${GO_VERSION}")" \ RUN eval "$(gimme "${GO_VERSION}")" \
&& export GOTOOLCHAIN="go${GO_VERSION}" \
&& CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o ./kindnetd ./cmd/kindnetd \ && CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o ./kindnetd ./cmd/kindnetd \
&& GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES ./cmd/kindnetd && GOARCH=$TARGETARCH go-licenses save --save_path=/_LICENSES ./cmd/kindnetd

View File

@@ -20,6 +20,7 @@ ARG VERSION
# set by makefile to .go-version # set by makefile to .go-version
ARG TARGETARCH GO_VERSION ARG TARGETARCH GO_VERSION
RUN eval "$(gimme "${GO_VERSION}")" \ RUN eval "$(gimme "${GO_VERSION}")" \
&& export GOTOOLCHAIN="go${GO_VERSION}" \
&& cd local-path-provisioner \ && cd local-path-provisioner \
&& git fetch && git checkout "${VERSION}" \ && git fetch && git checkout "${VERSION}" \
&& GOARCH=$TARGETARCH scripts/build \ && GOARCH=$TARGETARCH scripts/build \