mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
06e40ec6e7
From https://github.com/urfave/cli/pull/1383 : > This removes the resulting binary dependency on cpuguy83/md2man and > russross/blackfriday (and a few more packages imported by those), > which saves more than 400 KB (more than 300 KB > once stripped) from the resulting binary. Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
141 lines
3.9 KiB
Bash
Executable File
141 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e -x
|
|
|
|
cd $(dirname $0)/..
|
|
|
|
. ./scripts/version.sh
|
|
|
|
GO=${GO-go}
|
|
|
|
PKG="github.com/k3s-io/k3s"
|
|
PKG_CONTAINERD="github.com/containerd/containerd"
|
|
PKG_K3S_CONTAINERD="github.com/k3s-io/containerd"
|
|
PKG_CRICTL="github.com/kubernetes-sigs/cri-tools/pkg"
|
|
PKG_K8S_BASE="k8s.io/component-base"
|
|
PKG_K8S_CLIENT="k8s.io/client-go/pkg"
|
|
PKG_CNI_PLUGINS="github.com/containernetworking/plugins"
|
|
|
|
buildDate=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
VERSIONFLAGS="
|
|
-X ${PKG}/pkg/version.Version=${VERSION}
|
|
-X ${PKG}/pkg/version.GitCommit=${COMMIT:0:8}
|
|
|
|
-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}
|
|
|
|
-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}
|
|
|
|
-X ${PKG_CRICTL}/version.Version=${VERSION_CRICTL}
|
|
|
|
-X ${PKG_CONTAINERD}/version.Version=${VERSION_CONTAINERD}
|
|
-X ${PKG_CONTAINERD}/version.Package=${PKG_K3S_CONTAINERD}
|
|
|
|
-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}
|
|
-X ${PKG_CNI_PLUGINS}/plugins/meta/flannel.Commit=${COMMIT}
|
|
-X ${PKG_CNI_PLUGINS}/plugins/meta/flannel.buildDate=${buildDate}
|
|
"
|
|
LDFLAGS="
|
|
-w -s"
|
|
|
|
STATIC="
|
|
-extldflags '-static -lm -ldl -lz -lpthread'
|
|
"
|
|
TAGS="apparmor seccomp netcgo osusergo providerless urfave_cli_no_docs"
|
|
RUNC_TAGS="apparmor seccomp"
|
|
RUNC_STATIC="static"
|
|
|
|
if [ "$SELINUX" = "true" ]; then
|
|
TAGS="$TAGS selinux"
|
|
RUNC_TAGS="$RUNC_TAGS selinux"
|
|
fi
|
|
|
|
if [ "$STATIC_BUILD" != "true" ]; then
|
|
STATIC="
|
|
"
|
|
RUNC_STATIC=""
|
|
else
|
|
TAGS="static_build libsqlite3 $TAGS"
|
|
fi
|
|
|
|
mkdir -p bin
|
|
|
|
if [ ${ARCH} = armv7l ] || [ ${ARCH} = arm ]; then
|
|
export GOARCH="arm"
|
|
export GOARM="7"
|
|
fi
|
|
|
|
if [ ${ARCH} = s390x ]; then
|
|
export GOARCH="s390x"
|
|
fi
|
|
|
|
rm -f \
|
|
bin/k3s-agent \
|
|
bin/k3s-server \
|
|
bin/k3s-etcd-snapshot \
|
|
bin/k3s-secrets-encrypt \
|
|
bin/k3s-certificate \
|
|
bin/k3s-completion \
|
|
bin/kubectl \
|
|
bin/crictl \
|
|
bin/ctr \
|
|
bin/containerd \
|
|
bin/containerd-shim \
|
|
bin/containerd-shim-runc-v2 \
|
|
bin/runc
|
|
|
|
cleanup() {
|
|
exit_status=$?
|
|
rm -rf $TMPDIR
|
|
exit ${exit_status}
|
|
}
|
|
|
|
INSTALLBIN=$(pwd)/bin
|
|
if [ ! -x ${INSTALLBIN}/cni ]; then
|
|
(
|
|
echo Building cni
|
|
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
|
|
cd $WORKDIR
|
|
GO111MODULE=off GOPATH=$TMPDIR CGO_ENABLED=0 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o $INSTALLBIN/cni
|
|
)
|
|
fi
|
|
|
|
echo Building k3s
|
|
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/k3s-completion
|
|
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/
|
|
|
|
echo Building runc
|
|
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/
|