Unverified Commit bb0b4db2 authored by Joakim Roubert's avatar Joakim Roubert Committed by GitHub

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: 's avatarJoakim Roubert <joakimr@axis.com>
parent 47e4e7b5
...@@ -5,6 +5,8 @@ cd $(dirname $0)/.. ...@@ -5,6 +5,8 @@ cd $(dirname $0)/..
. ./scripts/version.sh . ./scripts/version.sh
GO=${GO-go}
PKG="github.com/rancher/k3s" PKG="github.com/rancher/k3s"
PKG_CONTAINERD="github.com/containerd/containerd" PKG_CONTAINERD="github.com/containerd/containerd"
PKG_RANCHER_CONTAINERD="github.com/rancher/containerd" PKG_RANCHER_CONTAINERD="github.com/rancher/containerd"
...@@ -66,7 +68,7 @@ fi ...@@ -66,7 +68,7 @@ fi
mkdir -p bin mkdir -p bin
if [ -z "$GOARM" ] && [ "arm" = "$(go env GOARCH)" ]; then if [ -z "$GOARM" ] && [ "arm" = "$("${GO}" env GOARCH)" ]; then
GOARM=7 GOARM=7
fi fi
...@@ -98,24 +100,24 @@ if [ ! -x ${INSTALLBIN}/cni ]; then ...@@ -98,24 +100,24 @@ if [ ! -x ${INSTALLBIN}/cni ]; then
WORKDIR=$TMPDIR/src/github.com/containernetworking/plugins WORKDIR=$TMPDIR/src/github.com/containernetworking/plugins
git clone -b $VERSION_CNIPLUGINS https://github.com/rancher/plugins.git $WORKDIR git clone -b $VERSION_CNIPLUGINS https://github.com/rancher/plugins.git $WORKDIR
cd $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 fi
# echo Building agent # 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 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-agent
ln -s containerd ./bin/k3s-server ln -s containerd ./bin/k3s-server
ln -s containerd ./bin/kubectl ln -s containerd ./bin/kubectl
ln -s containerd ./bin/crictl ln -s containerd ./bin/crictl
ln -s containerd ./bin/ctr ln -s containerd ./bin/ctr
#echo Building hyperkube #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 #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 # 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 echo Building runc
rm -f ./vendor/github.com/opencontainers/runc/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 make EXTRA_LDFLAGS="-w -s" BUILDTAGS="$RUNC_TAGS" -C ./vendor/github.com/opencontainers/runc $RUNC_STATIC
......
...@@ -5,6 +5,8 @@ cd $(dirname $0)/.. ...@@ -5,6 +5,8 @@ cd $(dirname $0)/..
. ./scripts/setup-rancher-path.sh . ./scripts/setup-rancher-path.sh
GO=${GO-go}
# Prime sudo # Prime sudo
sudo echo Compiling sudo echo Compiling
...@@ -13,7 +15,7 @@ if [ ! -e bin/containerd ]; then ...@@ -13,7 +15,7 @@ if [ ! -e bin/containerd ]; then
./scripts/package ./scripts/package
else else
rm -f ./bin/k3s-agent 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 fi
echo Starting agent echo Starting agent
......
#!/bin/bash #!/bin/bash
set -e set -e
GO=${GO-go}
mkdir -p $(dirname $0)/../bin mkdir -p $(dirname $0)/../bin
cd $(dirname $0)/../bin cd $(dirname $0)/../bin
...@@ -10,4 +12,4 @@ if echo -- "$@" | grep -q rootless; then ...@@ -10,4 +12,4 @@ if echo -- "$@" | grep -q rootless; then
ARGS="" ARGS=""
PATH=$(pwd):$PATH PATH=$(pwd):$PATH
fi fi
go run -tags "apparmor" ../main.go server $ARGS "$@" "${GO}" run -tags "apparmor" ../main.go server $ARGS "$@"
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
umask 077 umask 077
GO=${GO-go}
TMPDIR=$(mktemp -d) TMPDIR=$(mktemp -d)
cleanup() { cleanup() {
exit_code=$? exit_code=$?
...@@ -40,7 +42,7 @@ END ...@@ -40,7 +42,7 @@ END
HOME=${TMPDIR} HOME=${TMPDIR}
PATH=$PATH:${HOME}/gsutil 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) tar -cz -f ${TMPDIR}/${LOG_TGZ} -C $(dirname $1) $(basename $1)
gsutil cp ${TMPDIR}/${LOG_TGZ} gs://k3s-ci-logs || exit 1 gsutil cp ${TMPDIR}/${LOG_TGZ} gs://k3s-ci-logs || exit 1
......
...@@ -5,6 +5,8 @@ cd $(dirname $0)/.. ...@@ -5,6 +5,8 @@ cd $(dirname $0)/..
. ./scripts/version.sh . ./scripts/version.sh
GO=${GO-go}
rm -rf bin/crictl bin/kubectl bin/k3s-agent bin/k3s-server bin/kubectl bin/k3s build/data 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-agent
ln -s containerd bin/k3s-server ln -s containerd bin/k3s-server
...@@ -49,7 +51,7 @@ fi ...@@ -49,7 +51,7 @@ fi
CMD_NAME=dist/artifacts/k3s${BIN_SUFFIX} CMD_NAME=dist/artifacts/k3s${BIN_SUFFIX}
go generate "${GO}" generate
LDFLAGS=" LDFLAGS="
-X github.com/rancher/k3s/pkg/version.Version=$VERSION -X github.com/rancher/k3s/pkg/version.Version=$VERSION
-X github.com/rancher/k3s/pkg/version.GitCommit=${COMMIT:0:8} -X github.com/rancher/k3s/pkg/version.GitCommit=${COMMIT:0:8}
...@@ -59,6 +61,6 @@ STATIC="-extldflags '-static'" ...@@ -59,6 +61,6 @@ STATIC="-extldflags '-static'"
if [ "$DQLITE" = "true" ]; then if [ "$DQLITE" = "true" ]; then
DQLITE_TAGS="dqlite" DQLITE_TAGS="dqlite"
fi 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} ./scripts/build-upload ${CMD_NAME} ${COMMIT}
...@@ -3,6 +3,8 @@ set -e ...@@ -3,6 +3,8 @@ set -e
cd $(dirname $0)/.. cd $(dirname $0)/..
GO=${GO-go}
if ! command -v golangci-lint; then if ! command -v golangci-lint; then
echo Skipping validation: no golangci-lint available echo Skipping validation: no golangci-lint available
exit exit
...@@ -13,8 +15,8 @@ if [ ! -e build/data ];then ...@@ -13,8 +15,8 @@ if [ ! -e build/data ];then
mkdir -p build/data mkdir -p build/data
fi fi
echo Running: go generate echo Running: "${GO}" generate
go generate "${GO}" generate
echo Running: golangci-lint echo Running: golangci-lint
golangci-lint run golangci-lint run
......
#!/bin/bash #!/bin/bash
ARCH=${ARCH:-$(go env GOARCH)} GO=${GO-go}
ARCH=${ARCH:-$("${GO}" env GOARCH)}
SUFFIX="-${ARCH}" SUFFIX="-${ARCH}"
GIT_TAG=$DRONE_TAG GIT_TAG=$DRONE_TAG
TREE_STATE=clean TREE_STATE=clean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment