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"
|
|
|
|
PKG_RANCHER_CONTAINERD="github.com/rancher/containerd"
|
|
|
|
PKG_CRICTL="github.com/kubernetes-sigs/cri-tools"
|
|
|
|
|
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
|
|
|
|
|
|
|
-X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitVersion=${VERSION}
|
2019-12-23 19:07:34 +00:00
|
|
|
-X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitCommit=${COMMIT}
|
2019-12-17 19:21:47 +00:00
|
|
|
-X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitTreeState=${TREE_STATE}
|
|
|
|
-X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.buildDate=${buildDate}
|
|
|
|
|
|
|
|
-X ${VENDOR_PREFIX}k8s.io/component-base/version.gitVersion=${VERSION}
|
2019-12-23 19:07:34 +00:00
|
|
|
-X ${VENDOR_PREFIX}k8s.io/component-base/version.gitCommit=${COMMIT}
|
2019-12-17 19:21:47 +00:00
|
|
|
-X ${VENDOR_PREFIX}k8s.io/component-base/version.gitTreeState=${TREE_STATE}
|
|
|
|
-X ${VENDOR_PREFIX}k8s.io/component-base/version.buildDate=${buildDate}
|
|
|
|
|
2019-11-01 18:56:42 +00:00
|
|
|
-X ${VENDOR_PREFIX}${PKG_CONTAINERD}/version.Version=${VERSION_CONTAINERD}
|
|
|
|
-X ${VENDOR_PREFIX}${PKG_CONTAINERD}/version.Package=${PKG_RANCHER_CONTAINERD}
|
2019-12-17 19:21:47 +00:00
|
|
|
-X ${VENDOR_PREFIX}${PKG_CRICTL}/pkg/version.Version=${VERSION_CRICTL}
|
|
|
|
"
|
2019-10-03 17:25:05 +00:00
|
|
|
LDFLAGS="
|
|
|
|
-w -s"
|
|
|
|
STATIC="
|
|
|
|
-extldflags '-static'
|
|
|
|
"
|
2019-11-12 05:48:43 +00:00
|
|
|
|
2019-10-03 17:25:05 +00:00
|
|
|
STATIC_SQLITE="
|
2020-05-05 23:26:05 +00:00
|
|
|
-extldflags '-static -lm -ldl -lz -lpthread'
|
2019-07-10 03:54:13 +00:00
|
|
|
"
|
2020-05-05 23:26:05 +00:00
|
|
|
TAGS="ctrd apparmor seccomp no_btrfs 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="
|
|
|
|
"
|
|
|
|
STATIC_SQLITE="
|
|
|
|
"
|
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-03-25 19:35:07 +00:00
|
|
|
if [ -z "$GOARM" ] && [ "arm" = "$("${GO}" env GOARCH)" ]; then
|
2019-02-08 04:08:10 +00:00
|
|
|
GOARM=7
|
|
|
|
fi
|
|
|
|
|
2019-07-10 03:54:13 +00:00
|
|
|
rm -f \
|
|
|
|
bin/k3s-agent \
|
|
|
|
bin/hyperkube \
|
|
|
|
bin/containerd \
|
|
|
|
bin/runc \
|
|
|
|
bin/containerd-shim \
|
2019-09-20 04:15:51 +00:00
|
|
|
bin/containerd-shim-runc-v1 \
|
2019-10-18 19:29:41 +00:00
|
|
|
bin/containerd-shim-runc-v2 \
|
2019-07-10 03:54:13 +00:00
|
|
|
bin/k3s-server \
|
|
|
|
bin/kubectl \
|
|
|
|
bin/crictl \
|
|
|
|
bin/ctr
|
|
|
|
|
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
|
2019-01-09 16:54:15 +00:00
|
|
|
# echo Building agent
|
2020-03-25 19:35:07 +00:00
|
|
|
# CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/k3s-agent ./cmd/agent/main.go
|
2019-01-09 16:54:15 +00:00
|
|
|
echo Building server
|
2020-03-25 19:35:07 +00:00
|
|
|
CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/containerd ./cmd/server/main.go
|
2019-01-09 16:54:15 +00:00
|
|
|
ln -s containerd ./bin/k3s-agent
|
|
|
|
ln -s containerd ./bin/k3s-server
|
|
|
|
ln -s containerd ./bin/kubectl
|
2019-02-08 04:08:10 +00:00
|
|
|
ln -s containerd ./bin/crictl
|
2019-06-30 16:30:25 +00:00
|
|
|
ln -s containerd ./bin/ctr
|
2019-11-11 22:19:15 +00:00
|
|
|
#echo Building hyperkube
|
2020-03-25 19:35:07 +00:00
|
|
|
#CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/hyperkube ./vendor/k8s.io/kubernetes/cmd/hyperkube/
|
2019-02-08 04:08:10 +00:00
|
|
|
#echo Building ctr
|
2020-03-25 19:35:07 +00:00
|
|
|
#CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/ctr ./cmd/ctr/main.go
|
2019-01-09 16:54:15 +00:00
|
|
|
# echo Building containerd
|
2020-03-25 19:35:07 +00:00
|
|
|
# CGO_ENABLED=0 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/containerd ./cmd/containerd/
|
2019-01-09 16:54:15 +00:00
|
|
|
echo Building runc
|
2020-02-29 00:32:42 +00:00
|
|
|
rm -f ./vendor/github.com/opencontainers/runc/runc
|
2020-02-28 22:39:11 +00:00
|
|
|
make EXTRA_LDFLAGS="-w -s" BUILDTAGS="$RUNC_TAGS" -C ./vendor/github.com/opencontainers/runc $RUNC_STATIC
|
2019-01-09 16:54:15 +00:00
|
|
|
cp -f ./vendor/github.com/opencontainers/runc/runc ./bin/runc
|
2019-10-18 02:54:42 +00:00
|
|
|
|
|
|
|
echo Building containerd-shim
|
2020-02-29 00:32:42 +00:00
|
|
|
rm -f ./vendor/github.com/containerd/containerd/bin/containerd-shim
|
2019-10-18 02:54:42 +00:00
|
|
|
make -C ./vendor/github.com/containerd/containerd bin/containerd-shim
|
|
|
|
cp -f ./vendor/github.com/containerd/containerd/bin/containerd-shim ./bin/containerd-shim
|
|
|
|
|
2019-10-18 19:29:41 +00:00
|
|
|
echo Building containerd-shim-runc-v2
|
2020-02-29 00:32:42 +00:00
|
|
|
rm -f ./vendor/github.com/containerd/containerd/bin/containerd-shim-runc-v2
|
2019-10-18 19:29:41 +00:00
|
|
|
make -C ./vendor/github.com/containerd/containerd bin/containerd-shim-runc-v2
|
|
|
|
cp -f ./vendor/github.com/containerd/containerd/bin/containerd-shim-runc-v2 ./bin/containerd-shim-runc-v2
|