From c390292d12b6a985f48142719b7f2cb0d0979dda Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Wed, 15 Dec 2021 16:14:27 -0800 Subject: [PATCH] Build script cleanups * Move runc and k3s-root versions into versions.sh * Remove commented-out cruft from build script * Other minor tweaks Signed-off-by: Brad Davidson (cherry picked from commit 8737e2e13f1c080cd4177e6ca79ab1cec9c4e352) --- scripts/build | 53 +++++++++++++++++++-------------------------- scripts/download | 10 ++------- scripts/package-cli | 2 +- scripts/version.sh | 9 +++++++- 4 files changed, 33 insertions(+), 41 deletions(-) diff --git a/scripts/build b/scripts/build index d2b53f2d3b..e05cee98f5 100755 --- a/scripts/build +++ b/scripts/build @@ -11,6 +11,8 @@ PKG="github.com/rancher/k3s" PKG_CONTAINERD="github.com/containerd/containerd" PKG_K3S_CONTAINERD="github.com/k3s-io/containerd" PKG_CRICTL="github.com/kubernetes-sigs/cri-tools" +PKG_K8S_BASE="k8s.io/component-base" +PKG_K8S_CLIENT="k8s.io/client-go/pkg" buildDate=$(date -u '+%Y-%m-%dT%H:%M:%SZ') @@ -19,15 +21,17 @@ VERSIONFLAGS=" -X ${PKG}/pkg/version.Version=${VERSION} -X ${PKG}/pkg/version.GitCommit=${COMMIT:0:8} - -X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitVersion=${VERSION} - -X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitCommit=${COMMIT} - -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}${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} - -X ${VENDOR_PREFIX}k8s.io/component-base/version.gitVersion=${VERSION} - -X ${VENDOR_PREFIX}k8s.io/component-base/version.gitCommit=${COMMIT} - -X ${VENDOR_PREFIX}k8s.io/component-base/version.gitTreeState=${TREE_STATE} - -X ${VENDOR_PREFIX}k8s.io/component-base/version.buildDate=${buildDate} + -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} -X ${VENDOR_PREFIX}${PKG_CONTAINERD}/version.Version=${VERSION_CONTAINERD} -X ${VENDOR_PREFIX}${PKG_CONTAINERD}/version.Package=${PKG_K3S_CONTAINERD} @@ -35,11 +39,8 @@ VERSIONFLAGS=" " LDFLAGS=" -w -s" -STATIC=" - -extldflags '-static' -" -STATIC_SQLITE=" +STATIC=" -extldflags '-static -lm -ldl -lz -lpthread' " TAGS="ctrd apparmor seccomp no_btrfs netcgo osusergo providerless" @@ -53,8 +54,6 @@ fi if [ "$STATIC_BUILD" != "true" ]; then STATIC=" -" - STATIC_SQLITE=" " RUNC_STATIC="" else @@ -70,19 +69,17 @@ 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/k3s-etcd-snapshot \ bin/k3s-secrets-encrypt \ bin/k3s-certificate \ bin/kubectl \ bin/crictl \ - bin/ctr + bin/ctr \ + bin/containerd \ + bin/containerd-shim \ + bin/containerd-shim-runc-v2 \ + bin/runc cleanup() { exit_status=$? @@ -102,10 +99,9 @@ if [ ! -x ${INSTALLBIN}/cni ]; then 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 + +echo Building k3s +CGO_ENABLED=1 "${GO}" build -tags "$TAGS" -ldflags "$VERSIONFLAGS $LDFLAGS $STATIC" -o bin/containerd ./cmd/server/main.go ln -s containerd ./bin/k3s-agent ln -s containerd ./bin/k3s-server ln -s containerd ./bin/k3s-etcd-snapshot @@ -114,12 +110,7 @@ ln -s containerd ./bin/k3s-certificate 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 rm -f ./build/src/github.com/opencontainers/runc/runc make GOPATH=$(pwd)/build EXTRA_LDFLAGS="-w -s" BUILDTAGS="$RUNC_TAGS" -C ./build/src/github.com/opencontainers/runc $RUNC_STATIC diff --git a/scripts/download b/scripts/download index b1749f8a58..a43159f308 100755 --- a/scripts/download +++ b/scripts/download @@ -4,8 +4,6 @@ cd $(dirname $0)/.. . ./scripts/version.sh -RUNC_VERSION=v1.0.3 -ROOT_VERSION=v0.10.1 TRAEFIK_CHART_VERSION=$(yq e '.spec.chart' manifests/traefik.yaml | awk 'match($0, /([0-9.]+)([0-9]{2})/, m) { print m[1]; exit; }') TRAEFIK_PACKAGE_VERSION=$(yq e '.spec.chart' manifests/traefik.yaml | awk 'match($0, /([0-9.]+)([0-9]{2})/, m) { print m[2]; exit; }') TRAEFIK_FILE=traefik-${TRAEFIK_CHART_VERSION}${TRAEFIK_PACKAGE_VERSION}.tgz @@ -22,13 +20,9 @@ rm -rf ${RUNC_DIR} mkdir -p ${CHARTS_DIR} mkdir -p ${DATA_DIR} -curl --compressed -sfL https://github.com/k3s-io/k3s-root/releases/download/${ROOT_VERSION}/k3s-root-${ARCH}.tar | tar xf - --exclude=bin/socat +curl --compressed -sfL https://github.com/k3s-io/k3s-root/releases/download/${VERSION_ROOT}/k3s-root-${ARCH}.tar | tar xf - --exclude=bin/socat -git clone --depth=1 https://github.com/opencontainers/runc ${RUNC_DIR} || true -pushd ${RUNC_DIR} -git fetch --all --tags -git checkout ${RUNC_VERSION} -b k3s -popd +git clone --single-branch --branch=${VERSION_RUNC} --depth=1 https://github.com/opencontainers/runc ${RUNC_DIR} setup_tmp() { TMP_DIR=$(mktemp -d --tmpdir=${CHARTS_DIR}) diff --git a/scripts/package-cli b/scripts/package-cli index f5638da0aa..98821416a8 100755 --- a/scripts/package-cli +++ b/scripts/package-cli @@ -35,7 +35,7 @@ mkdir -p dist/artifacts set -x ) -tar cvf ./build/out/data.tar --exclude ./bin/hyperkube ./bin ./etc +tar cvf ./build/out/data.tar ./bin ./etc zstd --no-progress -T0 -16 -f --long=25 --rm ./build/out/data.tar -o ./build/out/data.tar.zst HASH=$(sha256sum ./build/out/data.tar.zst | awk '{print $1}') diff --git a/scripts/version.sh b/scripts/version.sh index dca9a2cd02..7e0dda2f56 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -37,7 +37,14 @@ if [ -z "$VERSION_K8S" ]; then VERSION_K8S="v0.0.0" fi -VERSION_CNIPLUGINS="v0.8.6-k3s1" +VERSION_RUNC=$(grep github.com/opencontainers/runc go.mod | head -n1 | awk '{print $4}') +if [ -z "$VERSION_RUNC" ]; then + VERSION_RUNC="v0.0.0" +fi + +VERSION_CNIPLUGINS="v0.9.1-k3s1" + +VERSION_ROOT="v0.9.1" if [[ -n "$GIT_TAG" ]]; then if [[ ! "$GIT_TAG" =~ ^"$VERSION_K8S"[+-] ]]; then