2016-12-13 14:48:12 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2019-06-07 09:36:14 +00:00
|
|
|
DEST_DIR="bin"
|
|
|
|
|
|
|
|
if [ ! -d ${DEST_DIR} ]; then
|
|
|
|
mkdir ${DEST_DIR}
|
|
|
|
fi
|
2016-12-13 14:48:12 +00:00
|
|
|
|
2018-12-06 03:52:30 +00:00
|
|
|
# Add version/commit/date into binary
|
|
|
|
# In case of TravisCI, need to check error code of 'git describe'.
|
2019-10-25 07:43:31 +00:00
|
|
|
if [ -z "$VERSION" ]; then
|
|
|
|
set +e
|
|
|
|
git describe --tags --abbrev=0 > /dev/null 2>&1
|
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
VERSION="master"
|
|
|
|
else
|
|
|
|
VERSION=$(git describe --tags --abbrev=0)
|
|
|
|
fi
|
|
|
|
set -e
|
2018-12-06 03:52:30 +00:00
|
|
|
fi
|
2020-07-08 03:05:52 +00:00
|
|
|
DATE=$(date -u -d "@${SOURCE_DATE_EPOCH:-$(date +%s)}" --iso-8601=seconds)
|
2019-10-25 07:43:31 +00:00
|
|
|
COMMIT=${COMMIT:-$(git rev-parse --verify HEAD)}
|
2021-10-14 14:40:49 +00:00
|
|
|
LDFLAGS="-X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.version=${VERSION:-master} -X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.commit=${COMMIT} -X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.date=${DATE}"
|
2019-04-18 14:11:26 +00:00
|
|
|
export CGO_ENABLED=0
|
2016-12-13 14:48:12 +00:00
|
|
|
|
2019-06-14 06:30:11 +00:00
|
|
|
# this if... will be removed when gomodules goes default
|
2019-06-14 06:36:44 +00:00
|
|
|
if [ "$GO111MODULE" == "off" ]; then
|
2019-06-14 06:30:11 +00:00
|
|
|
echo "Building plugin without go module"
|
|
|
|
echo "Warning: this will be deprecated in near future so please use go modules!"
|
|
|
|
|
2021-03-16 07:08:53 +00:00
|
|
|
ORG_PATH="gopkg.in/k8snetworkplumbingwg"
|
2020-05-14 15:54:24 +00:00
|
|
|
REPO_PATH="${ORG_PATH}/multus-cni.v3"
|
2019-06-14 06:30:11 +00:00
|
|
|
|
|
|
|
if [ ! -h gopath/src/${REPO_PATH} ]; then
|
|
|
|
mkdir -p gopath/src/${ORG_PATH}
|
|
|
|
ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
|
|
|
|
fi
|
|
|
|
|
|
|
|
export GO15VENDOREXPERIMENT=1
|
|
|
|
export GOBIN=${PWD}/bin
|
|
|
|
export GOPATH=${PWD}/gopath
|
2020-05-28 20:43:59 +00:00
|
|
|
go build -o ${PWD}/bin/multus -tags no_openssl -ldflags "${LDFLAGS}" "$@" ${REPO_PATH}/cmd
|
2019-06-14 06:30:11 +00:00
|
|
|
else
|
|
|
|
# build with go modules
|
|
|
|
export GO111MODULE=on
|
2020-06-24 19:14:36 +00:00
|
|
|
BUILD_ARGS=(-o ${DEST_DIR}/multus -tags no_openssl)
|
|
|
|
if [ -n "$MODMODE" ]; then
|
|
|
|
BUILD_ARGS+=(-mod "$MODMODE")
|
|
|
|
fi
|
2019-06-14 06:30:11 +00:00
|
|
|
|
|
|
|
echo "Building plugins"
|
2020-05-28 20:43:59 +00:00
|
|
|
go build ${BUILD_ARGS[*]} -ldflags "${LDFLAGS}" "$@" ./cmd
|
2019-06-14 06:30:11 +00:00
|
|
|
fi
|