2019-01-01 08:23:01 +00:00
|
|
|
#!/bin/bash
|
2019-01-09 16:54:15 +00:00
|
|
|
set -e -x
|
2019-01-01 08:23:01 +00:00
|
|
|
|
|
|
|
cd $(dirname $0)/..
|
2019-11-12 23:36:04 +00:00
|
|
|
|
|
|
|
. ./scripts/version.sh
|
|
|
|
|
2020-03-25 19:35:07 +00:00
|
|
|
GO=${GO-go}
|
|
|
|
|
2022-03-02 23:47:27 +00:00
|
|
|
PKG="github.com/k3s-io/k3s"
|
2019-07-10 03:54:13 +00:00
|
|
|
PKG_CONTAINERD="github.com/containerd/containerd"
|
2021-12-02 20:51:57 +00:00
|
|
|
PKG_CRICTL="github.com/kubernetes-sigs/cri-tools/pkg"
|
2021-12-16 00:14:27 +00:00
|
|
|
PKG_K8S_BASE="k8s.io/component-base"
|
|
|
|
PKG_K8S_CLIENT="k8s.io/client-go/pkg"
|
2022-04-19 21:48:04 +00:00
|
|
|
PKG_CNI_PLUGINS="github.com/containernetworking/plugins"
|
2023-10-13 19:54:56 +00:00
|
|
|
PKG_KUBE_ROUTER="github.com/cloudnativelabs/kube-router/v2"
|
2023-01-21 01:31:16 +00:00
|
|
|
PKG_CRI_DOCKERD="github.com/Mirantis/cri-dockerd"
|
2023-03-29 21:44:23 +00:00
|
|
|
PKG_ETCD="go.etcd.io/etcd"
|
2019-07-10 03:54:13 +00:00
|
|
|
|
2019-12-12 01:28:40 +00:00
|
|
|
buildDate=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
|
2019-10-03 17:25:05 +00:00
|
|
|
VERSIONFLAGS="
|
2019-11-01 18:56:42 +00:00
|
|
|
-X ${PKG}/pkg/version.Version=${VERSION}
|
|
|
|
-X ${PKG}/pkg/version.GitCommit=${COMMIT:0:8}
|
2023-12-14 00:44:58 +00:00
|
|
|
-X ${PKG}/pkg/version.UpstreamGolang=${VERSION_GOLANG}
|
2019-12-17 19:21:47 +00:00
|
|
|
|
2021-11-09 03:50:42 +00:00
|
|
|
-X ${PKG_K8S_CLIENT}/version.gitVersion=${VERSION}
|
|
|
|
-X ${PKG_K8S_CLIENT}/version.gitCommit=${COMMIT}
|
|
|
|
-X ${PKG_K8S_CLIENT}/version.gitTreeState=${TREE_STATE}
|
|
|
|
-X ${PKG_K8S_CLIENT}/version.buildDate=${buildDate}
|
2019-12-17 19:21:47 +00:00
|
|
|
|
2021-11-09 03:50:42 +00:00
|
|
|
-X ${PKG_K8S_BASE}/version.gitVersion=${VERSION}
|
|
|
|
-X ${PKG_K8S_BASE}/version.gitCommit=${COMMIT}
|
|
|
|
-X ${PKG_K8S_BASE}/version.gitTreeState=${TREE_STATE}
|
|
|
|
-X ${PKG_K8S_BASE}/version.buildDate=${buildDate}
|
2021-12-16 00:14:27 +00:00
|
|
|
|
2021-11-09 03:50:42 +00:00
|
|
|
-X ${PKG_CRICTL}/version.Version=${VERSION_CRICTL}
|
2019-12-17 19:21:47 +00:00
|
|
|
|
2021-11-09 03:50:42 +00:00
|
|
|
-X ${PKG_CONTAINERD}/version.Version=${VERSION_CONTAINERD}
|
2023-09-19 13:18:47 +00:00
|
|
|
-X ${PKG_CONTAINERD}/version.Package=${PKG_CONTAINERD_K3S}
|
2021-12-02 20:51:57 +00:00
|
|
|
|
2022-04-19 21:48:04 +00:00
|
|
|
-X ${PKG_CNI_PLUGINS}/pkg/utils/buildversion.BuildVersion=${VERSION_CNIPLUGINS}
|
|
|
|
-X ${PKG_CNI_PLUGINS}/plugins/meta/flannel.Program=flannel
|
|
|
|
-X ${PKG_CNI_PLUGINS}/plugins/meta/flannel.Version=${VERSION_FLANNEL}
|
2023-01-21 01:31:16 +00:00
|
|
|
-X ${PKG_CNI_PLUGINS}/plugins/meta/flannel.Commit=HEAD
|
2022-04-19 21:48:04 +00:00
|
|
|
-X ${PKG_CNI_PLUGINS}/plugins/meta/flannel.buildDate=${buildDate}
|
2022-11-02 14:29:50 +00:00
|
|
|
|
|
|
|
-X ${PKG_KUBE_ROUTER}/pkg/version.Version=${VERSION_KUBE_ROUTER}
|
|
|
|
-X ${PKG_KUBE_ROUTER}/pkg/version.BuildDate=${buildDate}
|
2023-01-21 01:31:16 +00:00
|
|
|
|
|
|
|
-X ${PKG_CRI_DOCKERD}/cmd/version.Version=${VERSION_CRI_DOCKERD}
|
|
|
|
-X ${PKG_CRI_DOCKERD}/cmd/version.GitCommit=HEAD
|
|
|
|
-X ${PKG_CRI_DOCKERD}/cmd/version.BuildTime=${buildDate}
|
2023-03-29 21:44:23 +00:00
|
|
|
|
|
|
|
-X ${PKG_ETCD}/api/version.GitSHA=HEAD
|
2019-12-17 19:21:47 +00:00
|
|
|
"
|
2022-10-28 16:17:49 +00:00
|
|
|
if [ -n "${DEBUG}" ]; then
|
|
|
|
GCFLAGS="-N -l"
|
|
|
|
else
|
|
|
|
LDFLAGS="-w -s"
|
|
|
|
fi
|
2019-11-12 05:48:43 +00:00
|
|
|
|
2021-12-16 00:14:27 +00:00
|
|
|
STATIC="
|
2020-05-05 23:26:05 +00:00
|
|
|
-extldflags '-static -lm -ldl -lz -lpthread'
|
2019-07-10 03:54:13 +00:00
|
|
|
"
|
2023-05-02 23:14:35 +00:00
|
|
|
TAGS="ctrd apparmor seccomp netcgo osusergo providerless urfave_cli_no_docs"
|
2020-02-24 20:13:59 +00:00
|
|
|
RUNC_TAGS="apparmor seccomp"
|
2020-02-28 22:39:11 +00:00
|
|
|
RUNC_STATIC="static"
|
2020-02-24 20:13:59 +00:00
|
|
|
|
2023-10-16 18:53:09 +00:00
|
|
|
if [ ${OS} = windows ]; then
|
|
|
|
TAGS="ctrd netcgo osusergo providerless"
|
|
|
|
fi
|
|
|
|
|
2020-02-24 20:13:59 +00:00
|
|
|
if [ "$SELINUX" = "true" ]; then
|
|
|
|
TAGS="$TAGS selinux"
|
|
|
|
RUNC_TAGS="$RUNC_TAGS selinux"
|
|
|
|
fi
|
2019-01-01 08:23:01 +00:00
|
|
|
|
2019-01-09 16:54:15 +00:00
|
|
|
if [ "$STATIC_BUILD" != "true" ]; then
|
2019-10-03 17:25:05 +00:00
|
|
|
STATIC="
|
|
|
|
"
|
2020-02-28 22:39:11 +00:00
|
|
|
RUNC_STATIC=""
|
2019-01-09 16:54:15 +00:00
|
|
|
else
|
|
|
|
TAGS="static_build libsqlite3 $TAGS"
|
2019-01-01 08:23:01 +00:00
|
|
|
fi
|
|
|
|
|
2023-05-08 19:46:51 +00:00
|
|
|
if [ -n "${GOCOVER}" ]; then
|
|
|
|
BLDFLAGS="-cover"
|
|
|
|
TAGS="cover $TAGS"
|
|
|
|
fi
|
|
|
|
|
2019-01-09 16:54:15 +00:00
|
|
|
mkdir -p bin
|
2019-01-01 08:23:01 +00:00
|
|
|
|
2020-11-17 20:21:12 +00:00
|
|
|
if [ ${ARCH} = armv7l ] || [ ${ARCH} = arm ]; then
|
|
|
|
export GOARCH="arm"
|
|
|
|
export GOARM="7"
|
2022-09-01 17:20:32 +00:00
|
|
|
# Context: https://github.com/golang/go/issues/58425#issuecomment-1426415912
|
|
|
|
export GOEXPERIMENT=nounified
|
2019-02-08 04:08:10 +00:00
|
|
|
fi
|
|
|
|
|
2022-04-15 16:41:40 +00:00
|
|
|
if [ ${ARCH} = s390x ]; then
|
|
|
|
export GOARCH="s390x"
|
|
|
|
fi
|
|
|
|
|
2023-10-16 18:53:09 +00:00
|
|
|
k3s_binaries=(
|
|
|
|
"bin/k3s-agent"
|
|
|
|
"bin/k3s-server"
|
|
|
|
"bin/k3s-token"
|
|
|
|
"bin/k3s-etcd-snapshot"
|
|
|
|
"bin/k3s-secrets-encrypt"
|
|
|
|
"bin/k3s-certificate"
|
|
|
|
"bin/k3s-completion"
|
|
|
|
"bin/kubectl"
|
|
|
|
"bin/containerd"
|
|
|
|
"bin/crictl"
|
|
|
|
"bin/ctr"
|
|
|
|
)
|
|
|
|
|
|
|
|
containerd_binaries=(
|
|
|
|
"bin/containerd-shim"
|
|
|
|
"bin/containerd-shim-runc-v2"
|
|
|
|
"bin/runc"
|
|
|
|
"bin/containerd-shim-runhcs-v1"
|
|
|
|
"bin/runhcs"
|
|
|
|
)
|
|
|
|
|
|
|
|
for i in "${k3s_binaries[@]}"; do
|
|
|
|
if [ -f "$i${BINARY_POSTFIX}" ]; then
|
|
|
|
echo "Removing $i${BINARY_POSTFIX}"
|
|
|
|
rm -f "$i${BINARY_POSTFIX}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in "${containerd_binaries[@]}"; do
|
|
|
|
if [ -f "$i${BINARY_POSTFIX}" ]; then
|
|
|
|
echo "Removing $i${BINARY_POSTFIX}"
|
|
|
|
rm -f "$i${BINARY_POSTFIX}"
|
|
|
|
fi
|
|
|
|
done
|
2019-07-10 03:54:13 +00:00
|
|
|
|
2019-10-03 17:25:05 +00:00
|
|
|
cleanup() {
|
|
|
|
exit_status=$?
|
|
|
|
rm -rf $TMPDIR
|
|
|
|
exit ${exit_status}
|
|
|
|
}
|
|
|
|
|
2019-10-02 22:55:04 +00:00
|
|
|
INSTALLBIN=$(pwd)/bin
|
2023-10-16 18:53:09 +00:00
|
|
|
if [ ! -x ${INSTALLBIN}/cni${BINARY_POSTFIX} ]; then
|
2019-10-02 22:55:04 +00:00
|
|
|
(
|
|
|
|
echo Building cni
|
2019-10-03 17:25:05 +00:00
|
|
|
TMPDIR=$(mktemp -d)
|
|
|
|
trap cleanup EXIT
|
|
|
|
WORKDIR=$TMPDIR/src/github.com/containernetworking/plugins
|
|
|
|
git clone -b $VERSION_CNIPLUGINS https://github.com/rancher/plugins.git $WORKDIR
|
2019-10-02 22:55:04 +00:00
|
|
|
cd $WORKDIR
|
2023-10-16 18:53:09 +00:00
|
|
|
GO111MODULE=off GOPATH=$TMPDIR CGO_ENABLED=0 "${GO}" build -tags "$TAGS" -gcflags="all=${GCFLAGS}" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o $INSTALLBIN/cni${BINARY_POSTFIX}
|
2019-10-02 22:55:04 +00:00
|
|
|
)
|
2019-11-11 22:19:39 +00:00
|
|
|
fi
|
2021-12-16 00:14:27 +00:00
|
|
|
|
|
|
|
echo Building k3s
|
2023-10-16 18:53:09 +00:00
|
|
|
CGO_ENABLED=1 "${GO}" build $BLDFLAGS -tags "$TAGS" -buildvcs=false -gcflags="all=${GCFLAGS}" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/k3s${BINARY_POSTFIX} ./cmd/server
|
|
|
|
|
|
|
|
for i in "${k3s_binaries[@]}"; do
|
|
|
|
ln -s "k3s${BINARY_POSTFIX}" "$i${BINARY_POSTFIX}"
|
|
|
|
done
|
2021-12-02 20:51:57 +00:00
|
|
|
|
|
|
|
export GOPATH=$(pwd)/build
|
|
|
|
|
2023-10-16 18:53:09 +00:00
|
|
|
case ${OS} in
|
|
|
|
linux)
|
|
|
|
echo Building containerd-shim
|
|
|
|
pushd ./build/src/github.com/containerd/containerd
|
|
|
|
TAGS="${TAGS/netcgo/netgo}"
|
|
|
|
CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -gcflags="all=${GCFLAGS}" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/containerd-shim-runc-v2 ./cmd/containerd-shim-runc-v2
|
|
|
|
popd
|
|
|
|
cp -vf ./build/src/github.com/containerd/containerd/bin/* ./bin/
|
|
|
|
|
|
|
|
echo Building runc
|
|
|
|
pushd ./build/src/github.com/opencontainers/runc
|
|
|
|
rm -f runc
|
|
|
|
make EXTRA_FLAGS="-gcflags=\"all=${GCFLAGS}\"" EXTRA_LDFLAGS="$LDFLAGS" BUILDTAGS="$RUNC_TAGS" $RUNC_STATIC
|
|
|
|
popd
|
|
|
|
cp -vf ./build/src/github.com/opencontainers/runc/runc ./bin/
|
|
|
|
;;
|
|
|
|
windows)
|
|
|
|
echo Building containerd-shim-runhcs-v1
|
|
|
|
pushd ./build/src/github.com/microsoft/hcsshim
|
|
|
|
TAGS="${TAGS/netcgo/netgo}"
|
|
|
|
CGO_ENABLED=0 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/containerd-shim-runhcs-v1${BINARY_POSTFIX} ./cmd/containerd-shim-runhcs-v1
|
|
|
|
CGO_ENABLED=0 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/runhcs${BINARY_POSTFIX} ./cmd/runhcs
|
|
|
|
popd
|
|
|
|
cp -vf ./build/src/github.com/microsoft/hcsshim/bin/*${BINARY_POSTFIX} ./bin/
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "[ERROR] unrecognized opertaing system: ${OS}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|