Let variable handle go binary name in scripts (#1532)

During e.g. cross-compiling, it is sometimes useful to be able to have
another binary than the default one as the compiler. This patch for the
build scripts lets "go" be the default value for the variable GO, and
the latter is then used as the go compiler.

Change-Id: I0adf7a661b26593d9b0ea902a61b631b80e76ae7
Signed-off-by: Joakim Roubert <joakimr@axis.com>
This commit is contained in:
Joakim Roubert 2020-03-25 20:35:07 +01:00 committed by GitHub
parent 47e4e7b582
commit bb0b4db228
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 15 deletions

View File

@ -5,6 +5,8 @@ cd $(dirname $0)/..
. ./scripts/version.sh
GO=${GO-go}
PKG="github.com/rancher/k3s"
PKG_CONTAINERD="github.com/containerd/containerd"
PKG_RANCHER_CONTAINERD="github.com/rancher/containerd"
@ -66,7 +68,7 @@ fi
mkdir -p bin
if [ -z "$GOARM" ] && [ "arm" = "$(go env GOARCH)" ]; then
if [ -z "$GOARM" ] && [ "arm" = "$("${GO}" env GOARCH)" ]; then
GOARM=7
fi
@ -98,24 +100,24 @@ if [ ! -x ${INSTALLBIN}/cni ]; then
WORKDIR=$TMPDIR/src/github.com/containernetworking/plugins
git clone -b $VERSION_CNIPLUGINS https://github.com/rancher/plugins.git $WORKDIR
cd $WORKDIR
GOPATH=$TMPDIR CGO_ENABLED=0 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o $INSTALLBIN/cni
GOPATH=$TMPDIR CGO_ENABLED=0 "${GO}" build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o $INSTALLBIN/cni
)
fi
# echo Building agent
# CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/k3s-agent ./cmd/agent/main.go
# CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/k3s-agent ./cmd/agent/main.go
echo Building server
CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/containerd ./cmd/server/main.go
CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/containerd ./cmd/server/main.go
ln -s containerd ./bin/k3s-agent
ln -s containerd ./bin/k3s-server
ln -s containerd ./bin/kubectl
ln -s containerd ./bin/crictl
ln -s containerd ./bin/ctr
#echo Building hyperkube
#CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/hyperkube ./vendor/k8s.io/kubernetes/cmd/hyperkube/
#CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/hyperkube ./vendor/k8s.io/kubernetes/cmd/hyperkube/
#echo Building ctr
#CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/ctr ./cmd/ctr/main.go
#CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/ctr ./cmd/ctr/main.go
# echo Building containerd
# CGO_ENABLED=0 go build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/containerd ./cmd/containerd/
# CGO_ENABLED=0 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/containerd ./cmd/containerd/
echo Building runc
rm -f ./vendor/github.com/opencontainers/runc/runc
make EXTRA_LDFLAGS="-w -s" BUILDTAGS="$RUNC_TAGS" -C ./vendor/github.com/opencontainers/runc $RUNC_STATIC

View File

@ -5,6 +5,8 @@ cd $(dirname $0)/..
. ./scripts/setup-rancher-path.sh
GO=${GO-go}
# Prime sudo
sudo echo Compiling
@ -13,7 +15,7 @@ if [ ! -e bin/containerd ]; then
./scripts/package
else
rm -f ./bin/k3s-agent
go build -tags "apparmor seccomp" -o ./bin/k3s-agent ./cmd/agent/main.go
"${GO}" build -tags "apparmor seccomp" -o ./bin/k3s-agent ./cmd/agent/main.go
fi
echo Starting agent

View File

@ -1,6 +1,8 @@
#!/bin/bash
set -e
GO=${GO-go}
mkdir -p $(dirname $0)/../bin
cd $(dirname $0)/../bin
@ -10,4 +12,4 @@ if echo -- "$@" | grep -q rootless; then
ARGS=""
PATH=$(pwd):$PATH
fi
go run -tags "apparmor" ../main.go server $ARGS "$@"
"${GO}" run -tags "apparmor" ../main.go server $ARGS "$@"

View File

@ -7,6 +7,8 @@
umask 077
GO=${GO-go}
TMPDIR=$(mktemp -d)
cleanup() {
exit_code=$?
@ -40,7 +42,7 @@ END
HOME=${TMPDIR}
PATH=$PATH:${HOME}/gsutil
LOG_TGZ=k3s-log-$(date +%s)-$(go env GOARCH)-$(git rev-parse --short HEAD)-$(basename $1).tgz
LOG_TGZ=k3s-log-$(date +%s)-$("${GO}" env GOARCH)-$(git rev-parse --short HEAD)-$(basename $1).tgz
tar -cz -f ${TMPDIR}/${LOG_TGZ} -C $(dirname $1) $(basename $1)
gsutil cp ${TMPDIR}/${LOG_TGZ} gs://k3s-ci-logs || exit 1

View File

@ -5,6 +5,8 @@ cd $(dirname $0)/..
. ./scripts/version.sh
GO=${GO-go}
rm -rf bin/crictl bin/kubectl bin/k3s-agent bin/k3s-server bin/kubectl bin/k3s build/data
ln -s containerd bin/k3s-agent
ln -s containerd bin/k3s-server
@ -49,7 +51,7 @@ fi
CMD_NAME=dist/artifacts/k3s${BIN_SUFFIX}
go generate
"${GO}" generate
LDFLAGS="
-X github.com/rancher/k3s/pkg/version.Version=$VERSION
-X github.com/rancher/k3s/pkg/version.GitCommit=${COMMIT:0:8}
@ -59,6 +61,6 @@ STATIC="-extldflags '-static'"
if [ "$DQLITE" = "true" ]; then
DQLITE_TAGS="dqlite"
fi
CGO_ENABLED=0 go build -tags "$DQLITE_TAGS" -ldflags "$LDFLAGS $STATIC" -o ${CMD_NAME} ./cmd/k3s/main.go
CGO_ENABLED=0 "${GO}" build -tags "$DQLITE_TAGS" -ldflags "$LDFLAGS $STATIC" -o ${CMD_NAME} ./cmd/k3s/main.go
./scripts/build-upload ${CMD_NAME} ${COMMIT}

View File

@ -3,6 +3,8 @@ set -e
cd $(dirname $0)/..
GO=${GO-go}
if ! command -v golangci-lint; then
echo Skipping validation: no golangci-lint available
exit
@ -13,8 +15,8 @@ if [ ! -e build/data ];then
mkdir -p build/data
fi
echo Running: go generate
go generate
echo Running: "${GO}" generate
"${GO}" generate
echo Running: golangci-lint
golangci-lint run

View File

@ -1,6 +1,7 @@
#!/bin/bash
ARCH=${ARCH:-$(go env GOARCH)}
GO=${GO-go}
ARCH=${ARCH:-$("${GO}" env GOARCH)}
SUFFIX="-${ARCH}"
GIT_TAG=$DRONE_TAG
TREE_STATE=clean