Lightweight Kubernetes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.7 KiB

6 years ago
#!/bin/bash
set -e -x
6 years ago
source $(dirname $0)/version.sh
6 years ago
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"
LDFLAGS="
-X $PKG/pkg/version.Version=$VERSION
-X $PKG/pkg/version.GitCommit=${COMMIT:0:8}
-X $PKG/vendor/$PKG_CONTAINERD/version.Version=$VERSION_CONTAINERD
-X $PKG/vendor/$PKG_CONTAINERD/version.Package=$PKG_RANCHER_CONTAINERD
-X $PKG/vendor/$PKG_CRICTL/pkg/version.Version=$VERSION_CRICTL
-w -s
"
6 years ago
STATIC="-extldflags '-static'"
6 years ago
STATIC_SQLITE="-extldflags '-static -lm -ldl -lz -lpthread'"
TAGS="ctrd apparmor seccomp no_btrfs netgo osusergo providerless"
6 years ago
if [ "$STATIC_BUILD" != "true" ]; then
STATIC=""
STATIC_SQLITE=""
else
TAGS="static_build libsqlite3 $TAGS"
6 years ago
fi
mkdir -p bin
6 years ago
6 years ago
if [ -z "$GOARM" ] && [ "arm" = "$(go env GOARCH)" ]; then
GOARM=7
fi
rm -f \
bin/k3s-agent \
bin/hyperkube \
bin/containerd \
bin/cni \
bin/runc \
bin/containerd-shim \
bin/containerd-shim-runc-v1 \
bin/k3s-server \
bin/kubectl \
bin/crictl \
bin/ctr
INSTALLBIN=$(pwd)/bin
(
echo Building cni
WORKDIR=$(go env GOPATH)/src/github.com/containernetworking/plugins
[ -d $WORKDIR ] || git clone https://github.com/rancher/plugins.git $WORKDIR
cd $WORKDIR
git fetch -f
git checkout $VERSION_CNIPLUGINS
CGO_ENABLED=0 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o $INSTALLBIN/cni
)
# echo Building agent
# CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o bin/k3s-agent ./cmd/agent/main.go
echo Building server
CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$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
6 years ago
ln -s containerd ./bin/crictl
ln -s containerd ./bin/ctr
echo Building hyperkube
CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC_SQLITE" -o bin/hyperkube ./vendor/k8s.io/kubernetes/cmd/hyperkube/
6 years ago
#echo Building ctr
#CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC_SQLITE" -o bin/ctr ./cmd/ctr/main.go
# echo Building containerd
# CGO_ENABLED=0 go build -tags "$TAGS" -ldflags "$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-runc-v1
make -C ./vendor/github.com/containerd/containerd bin/containerd-shim-runc-v1
cp -f ./vendor/github.com/containerd/containerd/bin/containerd-shim-runc-v1 ./bin/containerd-shim-runc-v1