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}
|
|
|
|
|
2019-07-10 03:54:13 +00:00
|
|
|
PKG="github.com/rancher/k3s"
|
|
|
|
PKG_CONTAINERD="github.com/containerd/containerd"
|
2020-11-30 17:40:54 +00:00
|
|
|
PKG_K3S_CONTAINERD="github.com/k3s-io/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"
|
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-11-12 23:36:04 +00:00
|
|
|
VENDOR_PREFIX="${PKG}/vendor/"
|
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}
|
2019-12-17 19:21:47 +00:00
|
|
|
|
2021-12-16 00:14:27 +00:00
|
|
|
-X ${VENDOR_PREFIX}${PKG_K8S_CLIENT}/version.gitVersion=${VERSION}
|
|
|
|
-X ${VENDOR_PREFIX}${PKG_K8S_CLIENT}/version.gitCommit=${COMMIT}
|
|
|
|
-X ${VENDOR_PREFIX}${PKG_K8S_CLIENT}/version.gitTreeState=${TREE_STATE}
|
|
|
|
-X ${VENDOR_PREFIX}${PKG_K8S_CLIENT}/version.buildDate=${buildDate}
|
2019-12-17 19:21:47 +00:00
|
|
|
|
2021-12-16 00:14:27 +00:00
|
|
|
-X ${VENDOR_PREFIX}${PKG_K8S_BASE}/version.gitVersion=${VERSION}
|
|
|
|
-X ${VENDOR_PREFIX}${PKG_K8S_BASE}/version.gitCommit=${COMMIT}
|
|
|
|
-X ${VENDOR_PREFIX}${PKG_K8S_BASE}/version.gitTreeState=${TREE_STATE}
|
|
|
|
-X ${VENDOR_PREFIX}${PKG_K8S_BASE}/version.buildDate=${buildDate}
|
|
|
|
|
|
|
|
-X ${VENDOR_PREFIX}${PKG_CRICTL}/version.Version=${VERSION_CRICTL}
|
2019-12-17 19:21:47 +00:00
|
|
|
|
2019-11-01 18:56:42 +00:00
|
|
|
-X ${VENDOR_PREFIX}${PKG_CONTAINERD}/version.Version=${VERSION_CONTAINERD}
|
2020-11-30 17:40:54 +00:00
|
|
|
-X ${VENDOR_PREFIX}${PKG_CONTAINERD}/version.Package=${PKG_K3S_CONTAINERD}
|
2021-12-02 20:51:57 +00:00
|
|
|
|
|
|
|
-X ${PKG_CONTAINERD}/version.Version=${VERSION_CONTAINERD}
|
|
|
|
-X ${PKG_CONTAINERD}/version.Package=${PKG_K3S_CONTAINERD}
|
2019-12-17 19:21:47 +00:00
|
|
|
"
|
2019-10-03 17:25:05 +00:00
|
|
|
LDFLAGS="
|
|
|
|
-w -s"
|
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
|
|
|
"
|
2021-12-02 20:51:57 +00:00
|
|
|
TAGS="apparmor seccomp netcgo osusergo providerless"
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
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"
|
2019-02-08 04:08:10 +00:00
|
|
|
fi
|
|
|
|
|
2019-07-10 03:54:13 +00:00
|
|
|
rm -f \
|
|
|
|
bin/k3s-agent \
|
|
|
|
bin/k3s-server \
|
2021-01-21 21:09:15 +00:00
|
|
|
bin/k3s-etcd-snapshot \
|
2021-12-07 22:31:32 +00:00
|
|
|
bin/k3s-secrets-encrypt \
|
2021-12-02 21:19:16 +00:00
|
|
|
bin/k3s-certificate \
|
2019-07-10 03:54:13 +00:00
|
|
|
bin/kubectl \
|
|
|
|
bin/crictl \
|
2021-12-16 00:14:27 +00:00
|
|
|
bin/ctr \
|
|
|
|
bin/containerd \
|
|
|
|
bin/containerd-shim \
|
|
|
|
bin/containerd-shim-runc-v2 \
|
|
|
|
bin/runc
|
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
|
2019-11-11 22:19:39 +00:00
|
|
|
if [ ! -x ${INSTALLBIN}/cni ]; 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
|
2020-03-25 19:35:07 +00:00
|
|
|
GOPATH=$TMPDIR CGO_ENABLED=0 "${GO}" build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o $INSTALLBIN/cni
|
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
|
2021-12-02 20:51:57 +00:00
|
|
|
CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/k3s ./cmd/server/main.go
|
|
|
|
ln -s k3s ./bin/k3s-agent
|
|
|
|
ln -s k3s ./bin/k3s-server
|
|
|
|
ln -s k3s ./bin/k3s-etcd-snapshot
|
|
|
|
ln -s k3s ./bin/k3s-secrets-encrypt
|
|
|
|
ln -s k3s ./bin/k3s-certificate
|
|
|
|
ln -s k3s ./bin/kubectl
|
|
|
|
ln -s k3s ./bin/crictl
|
|
|
|
ln -s k3s ./bin/ctr
|
|
|
|
|
|
|
|
export GOPATH=$(pwd)/build
|
|
|
|
|
|
|
|
echo Building containerd
|
|
|
|
pushd ./build/src/github.com/containerd/containerd
|
|
|
|
TAGS="${TAGS/netcgo/netgo}"
|
|
|
|
CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/containerd ./cmd/containerd
|
|
|
|
CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -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/
|
2021-12-16 00:14:27 +00:00
|
|
|
|
2019-01-09 16:54:15 +00:00
|
|
|
echo Building runc
|
2021-12-02 20:51:57 +00:00
|
|
|
pushd ./build/src/github.com/opencontainers/runc
|
|
|
|
rm -f runc
|
|
|
|
make EXTRA_LDFLAGS="-w -s" BUILDTAGS="$RUNC_TAGS" $RUNC_STATIC
|
|
|
|
popd
|
|
|
|
cp -vf ./build/src/github.com/opencontainers/runc/runc ./bin/
|