mirror of https://github.com/k3s-io/k3s
110 lines
3.4 KiB
Bash
Executable File
110 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e -x
|
|
|
|
source $(dirname $0)/version.sh
|
|
|
|
cd $(dirname $0)/..
|
|
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"
|
|
VENDOR_PREFIX=
|
|
if [ -z "$(go mod why 2>/dev/null)" ]; then
|
|
VENDOR_PREFIX="${PKG}/vendor/"
|
|
fi
|
|
|
|
VERSIONFLAGS="
|
|
-X ${PKG}/pkg/version.Version=${VERSION}
|
|
-X ${PKG}/pkg/version.GitCommit=${COMMIT:0:8}
|
|
-X ${VENDOR_PREFIX}${PKG_CONTAINERD}/version.Version=${VERSION_CONTAINERD}
|
|
-X ${VENDOR_PREFIX}${PKG_CONTAINERD}/version.Package=${PKG_RANCHER_CONTAINERD}
|
|
-X ${VENDOR_PREFIX}${PKG_CRICTL}/pkg/version.Version=${VERSION_CRICTL}"
|
|
LDFLAGS="
|
|
-w -s"
|
|
STATIC="
|
|
-extldflags '-static'
|
|
"
|
|
|
|
if [ "$DQLITE" = "true" ]; then
|
|
DQLITE_TAGS="dqlite"
|
|
DQLITE_STATIC_SQLITE="-luv -lraft -lco"
|
|
fi
|
|
|
|
STATIC_SQLITE="
|
|
-extldflags '-static -lm -ldl -lz -lpthread $DQLITE_STATIC_SQLITE'
|
|
"
|
|
TAGS="ctrd apparmor seccomp no_btrfs netgo osusergo providerless $DQLITE_TAGS"
|
|
|
|
if [ "$STATIC_BUILD" != "true" ]; then
|
|
STATIC="
|
|
"
|
|
STATIC_SQLITE="
|
|
"
|
|
else
|
|
TAGS="static_build libsqlite3 $TAGS"
|
|
fi
|
|
|
|
mkdir -p bin
|
|
|
|
if [ -z "$GOARM" ] && [ "arm" = "$(go env GOARCH)" ]; then
|
|
GOARM=7
|
|
fi
|
|
|
|
rm -f \
|
|
bin/k3s-agent \
|
|
bin/hyperkube \
|
|
bin/containerd \
|
|
bin/runc \
|
|
bin/containerd-shim \
|
|
bin/containerd-shim-runc-v1 \
|
|
bin/containerd-shim-runc-v2 \
|
|
bin/k3s-server \
|
|
bin/kubectl \
|
|
bin/crictl \
|
|
bin/ctr
|
|
|
|
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
|
|
GOPATH=$TMPDIR CGO_ENABLED=0 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o $INSTALLBIN/cni
|
|
)
|
|
fi
|
|
# echo Building agent
|
|
# CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/k3s-agent ./cmd/agent/main.go
|
|
echo Building server
|
|
CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/containerd ./cmd/server/main.go
|
|
ln -s containerd ./bin/k3s-agent
|
|
ln -s containerd ./bin/k3s-server
|
|
ln -s containerd ./bin/kubectl
|
|
ln -s containerd ./bin/crictl
|
|
ln -s containerd ./bin/ctr
|
|
#echo Building hyperkube
|
|
#CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/hyperkube ./vendor/k8s.io/kubernetes/cmd/hyperkube/
|
|
#echo Building ctr
|
|
#CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC_SQLITE" -o bin/ctr ./cmd/ctr/main.go
|
|
# echo Building containerd
|
|
# CGO_ENABLED=0 go build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/containerd ./cmd/containerd/
|
|
echo Building runc
|
|
make EXTRA_LDFLAGS="-w -s" BUILDTAGS="apparmor seccomp" -C ./vendor/github.com/opencontainers/runc static
|
|
cp -f ./vendor/github.com/opencontainers/runc/runc ./bin/runc
|
|
|
|
echo Building containerd-shim
|
|
make -C ./vendor/github.com/containerd/containerd bin/containerd-shim
|
|
cp -f ./vendor/github.com/containerd/containerd/bin/containerd-shim ./bin/containerd-shim
|
|
|
|
echo Building containerd-shim-runc-v2
|
|
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
|