Skip to content

Commit

Permalink
force GOTOOLCHAIN="go${GO_VERSION}" for now
Browse files Browse the repository at this point in the history
TODO: look at using deprecating .go-version in favor of GOTOOLCHAIN existing knobs
  • Loading branch information
BenTheElder committed Feb 2, 2024
1 parent f022b08 commit 4368aad
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ 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:=
# enable modules
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)
Expand Down
23 changes: 23 additions & 0 deletions hack/build/gotoolchain.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion hack/build/setup-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions images/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,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


Expand All @@ -127,6 +128,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 \
Expand All @@ -141,6 +143,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 .
Expand All @@ -167,6 +170,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 \
Expand All @@ -187,6 +191,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
Expand Down
2 changes: 2 additions & 0 deletions images/kindnetd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions images/local-path-provisioner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 4368aad

Please sign in to comment.