From 2cd93a8efff2e442be7c441e58108e2aae0f6ba9 Mon Sep 17 00:00:00 2001 From: Angelos Kolaitis Date: Thu, 21 Jul 2022 13:28:28 +0300 Subject: [PATCH] Refactor snapcraft build pipeline (#3324) --- CODEOWNERS | 2 - build-scripts/.gitignore | 2 + build-scripts/addon-repositories.sh | 7 + build-scripts/build-component.sh | 63 ++ build-scripts/build-k8s-binaries.sh | 45 -- build-scripts/components/README.md | 25 + .../components/cluster-agent/build.sh | 7 + .../components/cluster-agent/repository | 1 + .../components/cluster-agent/version.sh | 3 + build-scripts/components/cni/build.sh | 8 + build-scripts/components/cni/repository | 1 + build-scripts/components/cni/version.sh | 4 + build-scripts/components/containerd/build.sh | 9 + .../components/containerd/repository | 1 + .../components/containerd/version.sh | 3 + build-scripts/components/crictl/build.sh | 7 + .../crictl/patches/0001-Add-s-w-ldflags.patch | 25 + build-scripts/components/crictl/repository | 1 + build-scripts/components/crictl/version.sh | 3 + .../components/dqlite-client/build.sh | 11 + .../components/dqlite-client/repository | 1 + .../components/dqlite-client/version.sh | 3 + build-scripts/components/dqlite/build.sh | 24 + build-scripts/components/dqlite/repository | 1 + build-scripts/components/dqlite/version.sh | 3 + build-scripts/components/etcd/build.sh | 10 + build-scripts/components/etcd/repository | 1 + build-scripts/components/etcd/version.sh | 3 + build-scripts/components/flanneld/build.sh | 19 + build-scripts/components/flanneld/repository | 1 + build-scripts/components/flanneld/version.sh | 3 + build-scripts/components/helm/build.sh | 20 + ...-warnings-for-kubeconfig-permissions.patch | 24 + build-scripts/components/helm/repository | 1 + build-scripts/components/helm/version.sh | 3 + build-scripts/components/k8s-dqlite/build.sh | 11 + .../components/k8s-dqlite/repository | 1 + .../components/k8s-dqlite/version.sh | 3 + build-scripts/components/kubernetes/build.sh | 15 + .../patches/0000-Kubelite-integration.patch | 0 ...-skip-validation-in-component-status.patch | 0 .../0000-Kubelite-integration.patch | 0 ...-skip-validation-in-component-status.patch | 0 .../components/kubernetes/repository | 1 + .../components/kubernetes/version.sh | 15 + .../components/microk8s-completion/build.sh | 8 + .../0001-microk8s-autocompleter-script.patch | 84 +++ .../components/microk8s-completion/repository | 1 + .../components/microk8s-completion/version.sh | 3 + build-scripts/components/migrator/build.sh | 8 + build-scripts/components/migrator/repository | 1 + build-scripts/components/migrator/version.sh | 3 + build-scripts/components/raft/build.sh | 19 + build-scripts/components/raft/repository | 1 + build-scripts/components/raft/version.sh | 4 + build-scripts/components/runc/build.sh | 7 + build-scripts/components/runc/repository | 1 + ...ange-profile-immediately-not-on-exec.patch | 0 ...-set-the-NNP-flag-after-changing-the.patch | 0 ...nux-change-AppArmor-profile-as-late-.patch | 0 build-scripts/components/runc/version.sh | 3 + build-scripts/components/sqlite/build.sh | 22 + build-scripts/components/sqlite/repository | 1 + build-scripts/components/sqlite/version.sh | 3 + build-scripts/components/traefik/build.sh | 12 + build-scripts/components/traefik/repository | 1 + build-scripts/components/traefik/version.sh | 3 + build-scripts/fetch-k8s-binaries.sh | 21 - build-scripts/set-env-binaries-location.sh | 4 - build-scripts/set-env-variables.sh | 80 --- microk8s-resources/actions/common/utils.sh | 2 +- .../default-hooks/post-refresh.d/30-helm | 6 + .../wrappers/microk8s-add-node.wrapper | 6 +- .../wrappers/microk8s-helm.wrapper | 14 +- .../wrappers/microk8s-helm3.wrapper | 14 +- .../wrappers/microk8s-images.wrapper | 2 +- scripts/wrappers/join.py | 6 +- scripts/wrappers/leave.py | 4 +- snap/hooks/configure | 7 +- snap/hooks/install | 2 +- snap/hooks/post-refresh | 0 snap/snapcraft.yaml | 546 +++++------------- 82 files changed, 703 insertions(+), 587 deletions(-) delete mode 100644 CODEOWNERS create mode 100644 build-scripts/.gitignore create mode 100755 build-scripts/addon-repositories.sh create mode 100755 build-scripts/build-component.sh delete mode 100755 build-scripts/build-k8s-binaries.sh create mode 100644 build-scripts/components/README.md create mode 100755 build-scripts/components/cluster-agent/build.sh create mode 100644 build-scripts/components/cluster-agent/repository create mode 100755 build-scripts/components/cluster-agent/version.sh create mode 100755 build-scripts/components/cni/build.sh create mode 100644 build-scripts/components/cni/repository create mode 100755 build-scripts/components/cni/version.sh create mode 100755 build-scripts/components/containerd/build.sh create mode 100644 build-scripts/components/containerd/repository create mode 100755 build-scripts/components/containerd/version.sh create mode 100755 build-scripts/components/crictl/build.sh create mode 100644 build-scripts/components/crictl/patches/0001-Add-s-w-ldflags.patch create mode 100644 build-scripts/components/crictl/repository create mode 100755 build-scripts/components/crictl/version.sh create mode 100755 build-scripts/components/dqlite-client/build.sh create mode 100644 build-scripts/components/dqlite-client/repository create mode 100755 build-scripts/components/dqlite-client/version.sh create mode 100755 build-scripts/components/dqlite/build.sh create mode 100644 build-scripts/components/dqlite/repository create mode 100755 build-scripts/components/dqlite/version.sh create mode 100755 build-scripts/components/etcd/build.sh create mode 100644 build-scripts/components/etcd/repository create mode 100755 build-scripts/components/etcd/version.sh create mode 100755 build-scripts/components/flanneld/build.sh create mode 100644 build-scripts/components/flanneld/repository create mode 100755 build-scripts/components/flanneld/version.sh create mode 100755 build-scripts/components/helm/build.sh create mode 100644 build-scripts/components/helm/patches/0001-disable-warnings-for-kubeconfig-permissions.patch create mode 100644 build-scripts/components/helm/repository create mode 100755 build-scripts/components/helm/version.sh create mode 100755 build-scripts/components/k8s-dqlite/build.sh create mode 100644 build-scripts/components/k8s-dqlite/repository create mode 100755 build-scripts/components/k8s-dqlite/version.sh create mode 100755 build-scripts/components/kubernetes/build.sh rename build-scripts/{ => components/kubernetes}/patches/0000-Kubelite-integration.patch (100%) rename build-scripts/{ => components/kubernetes}/patches/0001-Unix-socket-skip-validation-in-component-status.patch (100%) rename build-scripts/{ => components/kubernetes}/pre-patches/0000-Kubelite-integration.patch (100%) rename build-scripts/{ => components/kubernetes}/pre-patches/0001-Unix-socket-skip-validation-in-component-status.patch (100%) create mode 100644 build-scripts/components/kubernetes/repository create mode 100755 build-scripts/components/kubernetes/version.sh create mode 100755 build-scripts/components/microk8s-completion/build.sh create mode 100644 build-scripts/components/microk8s-completion/patches/0001-microk8s-autocompleter-script.patch create mode 100644 build-scripts/components/microk8s-completion/repository create mode 100755 build-scripts/components/microk8s-completion/version.sh create mode 100755 build-scripts/components/migrator/build.sh create mode 100644 build-scripts/components/migrator/repository create mode 100755 build-scripts/components/migrator/version.sh create mode 100755 build-scripts/components/raft/build.sh create mode 100644 build-scripts/components/raft/repository create mode 100755 build-scripts/components/raft/version.sh create mode 100755 build-scripts/components/runc/build.sh create mode 100644 build-scripts/components/runc/repository rename build-scripts/{patches/runc => components/runc/strict-patches}/0001-apparmor-change-profile-immediately-not-on-exec.patch (100%) rename build-scripts/{patches/runc => components/runc/strict-patches}/0002-setns_init_linux-set-the-NNP-flag-after-changing-the.patch (100%) rename build-scripts/{patches/runc => components/runc/strict-patches}/0003-standard_init_linux-change-AppArmor-profile-as-late-.patch (100%) create mode 100755 build-scripts/components/runc/version.sh create mode 100755 build-scripts/components/sqlite/build.sh create mode 100644 build-scripts/components/sqlite/repository create mode 100755 build-scripts/components/sqlite/version.sh create mode 100755 build-scripts/components/traefik/build.sh create mode 100644 build-scripts/components/traefik/repository create mode 100755 build-scripts/components/traefik/version.sh delete mode 100755 build-scripts/fetch-k8s-binaries.sh delete mode 100644 build-scripts/set-env-binaries-location.sh delete mode 100755 build-scripts/set-env-variables.sh create mode 100644 microk8s-resources/default-hooks/post-refresh.d/30-helm mode change 100644 => 100755 snap/hooks/post-refresh diff --git a/CODEOWNERS b/CODEOWNERS deleted file mode 100644 index 16fdee6e2a..0000000000 --- a/CODEOWNERS +++ /dev/null @@ -1,2 +0,0 @@ -* @ktsakalozos -/installer/ @joedborg diff --git a/build-scripts/.gitignore b/build-scripts/.gitignore new file mode 100644 index 0000000000..37554b0aa4 --- /dev/null +++ b/build-scripts/.gitignore @@ -0,0 +1,2 @@ +.build +.install diff --git a/build-scripts/addon-repositories.sh b/build-scripts/addon-repositories.sh new file mode 100755 index 0000000000..b03cfcb0ff --- /dev/null +++ b/build-scripts/addon-repositories.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +ADDONS_REPOS=" +core,${CORE_ADDONS_REPO:-https://github.com/canonical/microk8s-core-addons},${CORE_ADDONS_REPO_BRANCH:-main} +community,${COMMUNITY_ADDONS_REPO:-https://github.com/canonical/microk8s-community-addons},${COMMUNITY_ADDONS_REPO_BRANCH:-main} +" +ADDONS_REPOS_ENABLED="core" diff --git a/build-scripts/build-component.sh b/build-scripts/build-component.sh new file mode 100755 index 0000000000..a9ec41678b --- /dev/null +++ b/build-scripts/build-component.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +set -ex + +DIR=`realpath $(dirname "${0}")` + +BUILD_DIRECTORY="${SNAPCRAFT_PART_BUILD:-${DIR}/.build}" +INSTALL_DIRECTORY="${SNAPCRAFT_PART_INSTALL:-${DIR}/.install}" + +STRICT="${STRICT:-false}" +if [ "x${STRICT}" == "xfalse" ]; then + PROJECT_DIR="${SNAPCRAFT_PROJECT_DIR:-${DIR}/..}" + if cat "${PROJECT_DIR}/snap/snapcraft.yaml" | grep "confinement:" | grep strict > /dev/null; then + STRICT="true" + fi +fi + +mkdir -p "${BUILD_DIRECTORY}" "${INSTALL_DIRECTORY}" + +COMPONENT_NAME="${1}" +COMPONENT_DIRECTORY="${DIR}/components/${COMPONENT_NAME}" + +GIT_REPOSITORY="$(cat "${COMPONENT_DIRECTORY}/repository")" +GIT_TAG="$("${COMPONENT_DIRECTORY}/version.sh")" + +COMPONENT_BUILD_DIRECTORY="${BUILD_DIRECTORY}/${COMPONENT_NAME}" + +# cleanup git repository if we cannot git checkout to the build tag +if [ -d "${COMPONENT_BUILD_DIRECTORY}" ]; then + cd "${COMPONENT_BUILD_DIRECTORY}" + if ! git checkout "${GIT_TAG}"; then + cd "${BUILD_DIRECTORY}" + rm -rf "${COMPONENT_BUILD_DIRECTORY}" + fi +fi + +if [ ! -d "${COMPONENT_BUILD_DIRECTORY}" ]; then + git clone "${GIT_REPOSITORY}" --depth 1 -b "${GIT_TAG}" "${COMPONENT_BUILD_DIRECTORY}" +fi + +cd "${COMPONENT_BUILD_DIRECTORY}" +git config user.name "MicroK8s builder bot" +git config user.email "microk8s-builder-bot@canonical.com" +if echo "${GIT_TAG}" | grep -e rc -e alpha -e beta; then + if [ -d "${COMPONENT_DIRECTORY}/pre-patches" ]; then + for patch in "${COMPONENT_DIRECTORY}"/pre-patches/*; do + git am < "${patch}" + done + fi +else + if [ -d "${COMPONENT_DIRECTORY}/patches" ]; then + for patch in "${COMPONENT_DIRECTORY}"/patches/*; do + git am < "${patch}" + done + fi +fi +if [ "x${STRICT}" == "xtrue" ] && [ -d "${COMPONENT_DIRECTORY}/strict-patches" ]; then + for patch in "${COMPONENT_DIRECTORY}"/strict-patches/*; do + git am < "${patch}" + done +fi + +bash -xe "${COMPONENT_DIRECTORY}/build.sh" "${INSTALL_DIRECTORY}" diff --git a/build-scripts/build-k8s-binaries.sh b/build-scripts/build-k8s-binaries.sh deleted file mode 100755 index 0156e65a07..0000000000 --- a/build-scripts/build-k8s-binaries.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -set -eux - -echo "Building k8s binaries from $KUBERNETES_REPOSITORY tag $KUBERNETES_TAG" -apps="kubelite kubectl" -path_apps="cmd/kubelite cmd/kubectl" -export KUBE_SNAP_BINS="build/kube_bins/$KUBE_VERSION" -mkdir -p $KUBE_SNAP_BINS/$KUBE_ARCH -echo $KUBE_VERSION > $KUBE_SNAP_BINS/version - -export GOPATH=$SNAPCRAFT_PART_BUILD/go - -rm -rf $GOPATH -mkdir -p $GOPATH - -git clone --depth 1 https://github.com/kubernetes/kubernetes $GOPATH/src/github.com/kubernetes/kubernetes/ -b $KUBERNETES_TAG - -(cd $GOPATH/src/$KUBERNETES_REPOSITORY - git config user.email "microk8s-builder-bot@ubuntu.com" - git config user.name "MicroK8s builder bot" - - PATCHES="patches" - if echo "$KUBE_VERSION" | grep -e beta -e rc -e alpha - then - PATCHES="pre-patches" - fi - - for patch in "${SNAPCRAFT_PART_SRC}"/"$PATCHES"/*.patch - do - echo "Applying patch $patch" - git am < "$patch" - done - - rm -rf $GOPATH/src/$KUBERNETES_REPOSITORY/_output/ - make clean - for app in ${path_apps} - do - make WHAT="${app}" - done -) -for app in $apps; do - cp $GOPATH/src/$KUBERNETES_REPOSITORY/_output/bin/$app $KUBE_SNAP_BINS/$KUBE_ARCH/ -done - -rm -rf $GOPATH/src/$KUBERNETES_REPOSITORY/_output/ diff --git a/build-scripts/components/README.md b/build-scripts/components/README.md new file mode 100644 index 0000000000..8d48260362 --- /dev/null +++ b/build-scripts/components/README.md @@ -0,0 +1,25 @@ +# Parts directory + +This directory contains the build scripts for Go components built into MicroK8s. + +The directory structure looks like this: + +``` +build-scripts/ + build-component.sh <-- runs as `build-component.sh $component_name` + checks out the git repository, applies the specified + patches, then runs the `build.sh` step for the component + component/ + $component_name/ + repository <-- git repository to clone + version.sh <-- prints the repository tag or commit to checkout + build.sh <-- runs as `build.sh $output` + first argument is the output directory where + binaries should be placed. + patches/ + ... <-- list of patches to apply after checkout (for stable versions) + pre-patches/ + ... <-- list of patches to apply after checkout (for pre-releases) + strict-patches/ + ... <-- list of patches to apply when building strictly confined snap +``` diff --git a/build-scripts/components/cluster-agent/build.sh b/build-scripts/components/cluster-agent/build.sh new file mode 100755 index 0000000000..86282e7f67 --- /dev/null +++ b/build-scripts/components/cluster-agent/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export INSTALL="${1}/bin" +mkdir -p "${INSTALL}" + +make cluster-agent +cp cluster-agent "${INSTALL}" diff --git a/build-scripts/components/cluster-agent/repository b/build-scripts/components/cluster-agent/repository new file mode 100644 index 0000000000..661ffe684f --- /dev/null +++ b/build-scripts/components/cluster-agent/repository @@ -0,0 +1 @@ +https://github.com/canonical/microk8s-cluster-agent diff --git a/build-scripts/components/cluster-agent/version.sh b/build-scripts/components/cluster-agent/version.sh new file mode 100755 index 0000000000..f4e34e2190 --- /dev/null +++ b/build-scripts/components/cluster-agent/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "main" diff --git a/build-scripts/components/cni/build.sh b/build-scripts/components/cni/build.sh new file mode 100755 index 0000000000..298394ba66 --- /dev/null +++ b/build-scripts/components/cni/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +INSTALL="${1}/opt/cni/bin" +mkdir -p "${INSTALL}" + +./build_linux.sh + +cp bin/* "${INSTALL}/" diff --git a/build-scripts/components/cni/repository b/build-scripts/components/cni/repository new file mode 100644 index 0000000000..4c32da97df --- /dev/null +++ b/build-scripts/components/cni/repository @@ -0,0 +1 @@ +https://github.com/containernetworking/plugins diff --git a/build-scripts/components/cni/version.sh b/build-scripts/components/cni/version.sh new file mode 100755 index 0000000000..8df7377d79 --- /dev/null +++ b/build-scripts/components/cni/version.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Match https://github.com/kubernetes/kubernetes/blob/master/build/dependencies.yaml#L20 +echo "v0.9.1" diff --git a/build-scripts/components/containerd/build.sh b/build-scripts/components/containerd/build.sh new file mode 100755 index 0000000000..215b8cf423 --- /dev/null +++ b/build-scripts/components/containerd/build.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +INSTALL="${1}/bin" +mkdir -p "${INSTALL}" + +for bin in ctr containerd containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2; do + make "bin/${bin}" + cp "bin/${bin}" "${INSTALL}/${bin}" +done diff --git a/build-scripts/components/containerd/repository b/build-scripts/components/containerd/repository new file mode 100644 index 0000000000..2df75561b8 --- /dev/null +++ b/build-scripts/components/containerd/repository @@ -0,0 +1 @@ +https://github.com/containerd/containerd diff --git a/build-scripts/components/containerd/version.sh b/build-scripts/components/containerd/version.sh new file mode 100755 index 0000000000..f6451a831a --- /dev/null +++ b/build-scripts/components/containerd/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v1.6.6" diff --git a/build-scripts/components/crictl/build.sh b/build-scripts/components/crictl/build.sh new file mode 100755 index 0000000000..4f42291ef4 --- /dev/null +++ b/build-scripts/components/crictl/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export INSTALL="${1}/bin" +mkdir -p "${INSTALL}" + +make crictl +cp build/bin/crictl "${INSTALL}/crictl" diff --git a/build-scripts/components/crictl/patches/0001-Add-s-w-ldflags.patch b/build-scripts/components/crictl/patches/0001-Add-s-w-ldflags.patch new file mode 100644 index 0000000000..b71f683624 --- /dev/null +++ b/build-scripts/components/crictl/patches/0001-Add-s-w-ldflags.patch @@ -0,0 +1,25 @@ +From facd1c26a641d2e6664bda7b5e1aaf9ff2c3309a Mon Sep 17 00:00:00 2001 +From: Angelos Kolaitis +Date: Fri, 15 Jul 2022 10:40:10 +0300 +Subject: [PATCH] Add -s -w ldflags + +--- + Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index f5a1160..49b314f 100644 +--- a/Makefile ++++ b/Makefile +@@ -34,7 +34,7 @@ BINDIR ?= /usr/local/bin + + VERSION := $(shell git describe --tags --dirty --always) + VERSION := $(VERSION:v%=%) +-GO_LDFLAGS := -X $(PROJECT)/pkg/version.Version=$(VERSION) ++GO_LDFLAGS := -X $(PROJECT)/pkg/version.Version=$(VERSION) -s -w + + BUILD_PATH := $(shell pwd)/build + BUILD_BIN_PATH := $(BUILD_PATH)/bin +-- +2.25.1 + diff --git a/build-scripts/components/crictl/repository b/build-scripts/components/crictl/repository new file mode 100644 index 0000000000..c999674b5f --- /dev/null +++ b/build-scripts/components/crictl/repository @@ -0,0 +1 @@ +https://github.com/kubernetes-sigs/cri-tools diff --git a/build-scripts/components/crictl/version.sh b/build-scripts/components/crictl/version.sh new file mode 100755 index 0000000000..3a82be6269 --- /dev/null +++ b/build-scripts/components/crictl/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v1.24.2" diff --git a/build-scripts/components/dqlite-client/build.sh b/build-scripts/components/dqlite-client/build.sh new file mode 100755 index 0000000000..ea70d43aad --- /dev/null +++ b/build-scripts/components/dqlite-client/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +INSTALL="${1}/bin" +mkdir -p "${INSTALL}" + +export CGO_LDFLAGS_ALLOW="-Wl,-z,now" +export CGO_CFLAGS="-I${SNAPCRAFT_STAGE}/usr/include/" +export CGO_LDFLAGS="-L${SNAPCRAFT_STAGE}/lib" +go build -ldflags "-s -w" -tags libsqlite3 ./cmd/dqlite + +cp dqlite "${INSTALL}/dqlite" diff --git a/build-scripts/components/dqlite-client/repository b/build-scripts/components/dqlite-client/repository new file mode 100644 index 0000000000..5a62ae7e51 --- /dev/null +++ b/build-scripts/components/dqlite-client/repository @@ -0,0 +1 @@ +https://github.com/canonical/go-dqlite diff --git a/build-scripts/components/dqlite-client/version.sh b/build-scripts/components/dqlite-client/version.sh new file mode 100755 index 0000000000..efe8084880 --- /dev/null +++ b/build-scripts/components/dqlite-client/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v1.11.1" diff --git a/build-scripts/components/dqlite/build.sh b/build-scripts/components/dqlite/build.sh new file mode 100755 index 0000000000..f7b8da8c12 --- /dev/null +++ b/build-scripts/components/dqlite/build.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +INSTALL="${1}" + +[ ! -f ./configure ] && [ -f ./autogen.sh ] && env NOCONFIGURE=1 ./autogen.sh +[ ! -f ./configure ] && [ -f ./bootstrap ] && env NOCONFIGURE=1 ./bootstrap +[ ! -f ./configure ] && autoreconf --install + +export SQLITE_CFLAGS="-I${SNAPCRAFT_STAGE}/usr/include" +export SQLITE_LIBS="-L${SNAPCRAFT_STAGE}/lib -lsqlite3" +export RAFT_CFLAGS="-I${SNAPCRAFT_STAGE}/usr/include" +export RAFT_LIBS="-L${SNAPCRAFT_STAGE}/lib -lraft" + +./configure + +mkdir -p build + +make -j"${SNAPCRAFT_PARALLEL_BUILD_COUNT}" +make install DESTDIR="${PWD}/build" + +mkdir -p "${INSTALL}/lib" "${INSTALL}/usr/include" + +cp -r "build/usr/local/lib/libdqlite"*"so"* "${INSTALL}/lib/" +cp -r "build/usr/local/include/"* "${INSTALL}/usr/include/" diff --git a/build-scripts/components/dqlite/repository b/build-scripts/components/dqlite/repository new file mode 100644 index 0000000000..c4f5967458 --- /dev/null +++ b/build-scripts/components/dqlite/repository @@ -0,0 +1 @@ +https://github.com/canonical/dqlite diff --git a/build-scripts/components/dqlite/version.sh b/build-scripts/components/dqlite/version.sh new file mode 100755 index 0000000000..efe8084880 --- /dev/null +++ b/build-scripts/components/dqlite/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v1.11.1" diff --git a/build-scripts/components/etcd/build.sh b/build-scripts/components/etcd/build.sh new file mode 100755 index 0000000000..e0b15343fd --- /dev/null +++ b/build-scripts/components/etcd/build.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +export INSTALL="${1}" +mkdir -p "${INSTALL}" + +GO_LDFLAGS="-s -w" make + +for bin in etcd etcdctl; do + cp "bin/${bin}" "${INSTALL}/${bin}" +done diff --git a/build-scripts/components/etcd/repository b/build-scripts/components/etcd/repository new file mode 100644 index 0000000000..cece2938c2 --- /dev/null +++ b/build-scripts/components/etcd/repository @@ -0,0 +1 @@ +https://github.com/etcd-io/etcd diff --git a/build-scripts/components/etcd/version.sh b/build-scripts/components/etcd/version.sh new file mode 100755 index 0000000000..f556d65cc0 --- /dev/null +++ b/build-scripts/components/etcd/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v3.4.3" diff --git a/build-scripts/components/flanneld/build.sh b/build-scripts/components/flanneld/build.sh new file mode 100755 index 0000000000..888127df66 --- /dev/null +++ b/build-scripts/components/flanneld/build.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +INSTALL="${1}/opt/cni/bin" +mkdir -p "${INSTALL}" + +# TODO(neoaggelos): update to a non-ancient version of flanneld that we can actually build +FLANNELD_VERSION="v0.11.0" +ARCH="${ARCH:-`dpkg --print-architecture`}" +if [ "$ARCH" = "ppc64el" ]; then + ARCH="ppc64le" +elif [ "$ARCH" = "armhf" ]; then + ARCH="arm" +fi +mkdir -p download +cd download +curl -LO https://github.com/coreos/flannel/releases/download/${FLANNELD_VERSION}/flannel-${FLANNELD_VERSION}-linux-${ARCH}.tar.gz +tar xvzf flannel-*.tar.gz + +cp flanneld "${INSTALL}/flanneld" diff --git a/build-scripts/components/flanneld/repository b/build-scripts/components/flanneld/repository new file mode 100644 index 0000000000..6c300bbb7e --- /dev/null +++ b/build-scripts/components/flanneld/repository @@ -0,0 +1 @@ +https://github.com/flannel-io/flannel diff --git a/build-scripts/components/flanneld/version.sh b/build-scripts/components/flanneld/version.sh new file mode 100755 index 0000000000..af6ee6148b --- /dev/null +++ b/build-scripts/components/flanneld/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v0.11.0" diff --git a/build-scripts/components/helm/build.sh b/build-scripts/components/helm/build.sh new file mode 100755 index 0000000000..2672359cdd --- /dev/null +++ b/build-scripts/components/helm/build.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +INSTALL="${1}" +mkdir -p "${INSTALL}/bin" + +make +cp bin/helm "${INSTALL}/bin/helm" + +./bin/helm completion bash \ + | sed "s/complete -o default -F __start_helm helm/complete -o default -F __start_helm microk8s.helm/g" \ + | sed "s/complete -o default -o nospace -F __start_helm helm/complete -o default -o nospace -F __start_helm microk8s.helm/g" \ + > bin/helm.bash + +./bin/helm completion bash \ + | sed "s/complete -o default -F __start_helm helm/complete -o default -F __start_helm microk8s.helm3/g" \ + | sed "s/complete -o default -o nospace -F __start_helm helm/complete -o default -o nospace -F __start_helm microk8s.helm3/g" \ + > bin/helm3.bash + +cp bin/helm.bash "${INSTALL}/helm.bash" +cp bin/helm3.bash "${INSTALL}/helm3.bash" diff --git a/build-scripts/components/helm/patches/0001-disable-warnings-for-kubeconfig-permissions.patch b/build-scripts/components/helm/patches/0001-disable-warnings-for-kubeconfig-permissions.patch new file mode 100644 index 0000000000..8726a62f7a --- /dev/null +++ b/build-scripts/components/helm/patches/0001-disable-warnings-for-kubeconfig-permissions.patch @@ -0,0 +1,24 @@ +From d08d2604a9f0f925b93b87d74ee0a2c26c785467 Mon Sep 17 00:00:00 2001 +From: Angelos Kolaitis +Date: Thu, 14 Jul 2022 18:18:09 +0300 +Subject: [PATCH] disable warnings for kubeconfig permissions + +--- + cmd/helm/root.go | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/cmd/helm/root.go b/cmd/helm/root.go +index ef92fea9..512f823f 100644 +--- a/cmd/helm/root.go ++++ b/cmd/helm/root.go +@@ -206,7 +206,7 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string + loadPlugins(cmd, out) + + // Check permissions on critical files +- checkPerms() ++ // checkPerms() + + // Check for expired repositories + checkForExpiredRepos(settings.RepositoryConfig) +-- +2.25.1 diff --git a/build-scripts/components/helm/repository b/build-scripts/components/helm/repository new file mode 100644 index 0000000000..e7c0fbd488 --- /dev/null +++ b/build-scripts/components/helm/repository @@ -0,0 +1 @@ +https://github.com/helm/helm diff --git a/build-scripts/components/helm/version.sh b/build-scripts/components/helm/version.sh new file mode 100755 index 0000000000..4382fc4905 --- /dev/null +++ b/build-scripts/components/helm/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v3.9.1" diff --git a/build-scripts/components/k8s-dqlite/build.sh b/build-scripts/components/k8s-dqlite/build.sh new file mode 100755 index 0000000000..9c5f63c56d --- /dev/null +++ b/build-scripts/components/k8s-dqlite/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +INSTALL="${1}/bin" +mkdir -p "${INSTALL}" + +export CGO_LDFLAGS_ALLOW="-Wl,-z,now" +export CGO_CFLAGS="-I${SNAPCRAFT_STAGE}/usr/include/" +export CGO_LDFLAGS="-L${SNAPCRAFT_STAGE}/lib" +go build -ldflags "-s -w" -tags libsqlite3,dqlite . + +cp k8s-dqlite "${INSTALL}/k8s-dqlite" diff --git a/build-scripts/components/k8s-dqlite/repository b/build-scripts/components/k8s-dqlite/repository new file mode 100644 index 0000000000..87e2f7f5ed --- /dev/null +++ b/build-scripts/components/k8s-dqlite/repository @@ -0,0 +1 @@ +https://github.com/canonical/k8s-dqlite diff --git a/build-scripts/components/k8s-dqlite/version.sh b/build-scripts/components/k8s-dqlite/version.sh new file mode 100755 index 0000000000..83ae2d026b --- /dev/null +++ b/build-scripts/components/k8s-dqlite/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v1.0.4" diff --git a/build-scripts/components/kubernetes/build.sh b/build-scripts/components/kubernetes/build.sh new file mode 100755 index 0000000000..9e44de916f --- /dev/null +++ b/build-scripts/components/kubernetes/build.sh @@ -0,0 +1,15 @@ +#!/bin/bash -x + +INSTALL="${1}" + +for app in kubelite kubectl; do + make WHAT="cmd/${app}" + cp _output/bin/"${app}" "${INSTALL}/${app}" +done + +_output/bin/kubectl completion bash \ + | sed "s/complete -o default -F __start_kubectl kubectl/complete -o default -F __start_kubectl microk8s.kubectl/g" \ + | sed "s/complete -o default -o nospace -F __start_kubectl kubectl/complete -o default -o nospace -F __start_kubectl microk8s.kubectl/g" \ + > _output/kubectl.bash + +cp _output/kubectl.bash "${INSTALL}/kubectl.bash" diff --git a/build-scripts/patches/0000-Kubelite-integration.patch b/build-scripts/components/kubernetes/patches/0000-Kubelite-integration.patch similarity index 100% rename from build-scripts/patches/0000-Kubelite-integration.patch rename to build-scripts/components/kubernetes/patches/0000-Kubelite-integration.patch diff --git a/build-scripts/patches/0001-Unix-socket-skip-validation-in-component-status.patch b/build-scripts/components/kubernetes/patches/0001-Unix-socket-skip-validation-in-component-status.patch similarity index 100% rename from build-scripts/patches/0001-Unix-socket-skip-validation-in-component-status.patch rename to build-scripts/components/kubernetes/patches/0001-Unix-socket-skip-validation-in-component-status.patch diff --git a/build-scripts/pre-patches/0000-Kubelite-integration.patch b/build-scripts/components/kubernetes/pre-patches/0000-Kubelite-integration.patch similarity index 100% rename from build-scripts/pre-patches/0000-Kubelite-integration.patch rename to build-scripts/components/kubernetes/pre-patches/0000-Kubelite-integration.patch diff --git a/build-scripts/pre-patches/0001-Unix-socket-skip-validation-in-component-status.patch b/build-scripts/components/kubernetes/pre-patches/0001-Unix-socket-skip-validation-in-component-status.patch similarity index 100% rename from build-scripts/pre-patches/0001-Unix-socket-skip-validation-in-component-status.patch rename to build-scripts/components/kubernetes/pre-patches/0001-Unix-socket-skip-validation-in-component-status.patch diff --git a/build-scripts/components/kubernetes/repository b/build-scripts/components/kubernetes/repository new file mode 100644 index 0000000000..e2536ceb44 --- /dev/null +++ b/build-scripts/components/kubernetes/repository @@ -0,0 +1 @@ +https://github.com/kubernetes/kubernetes diff --git a/build-scripts/components/kubernetes/version.sh b/build-scripts/components/kubernetes/version.sh new file mode 100755 index 0000000000..dc1c4f2f05 --- /dev/null +++ b/build-scripts/components/kubernetes/version.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +KUBE_TRACK="${KUBE_TRACK:-}" # example: "1.24" +KUBE_VERSION="${KUBE_VERSION:-}" # example: "v1.24.2" + +if [ -z "${KUBE_VERSION}" ]; then + if [ -z "${KUBE_TRACK}" ]; then + KUBE_VERSION="$(curl -L --silent "https://dl.k8s.io/release/stable.txt")" + else + KUBE_TRACK="${KUBE_TRACK#v}" + KUBE_VERSION="$(curl -L --silent "https://dl.k8s.io/release/stable-${KUBE_TRACK}.txt")" + fi +fi + +echo "${KUBE_VERSION}" diff --git a/build-scripts/components/microk8s-completion/build.sh b/build-scripts/components/microk8s-completion/build.sh new file mode 100755 index 0000000000..d020f3961e --- /dev/null +++ b/build-scripts/components/microk8s-completion/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +INSTALL="${1}" + +go mod tidy -compat=1.17 +go run -tags microk8s_hack ./cmd/helm 2> /dev/null + +cp microk8s.bash "${INSTALL}/microk8s.bash" diff --git a/build-scripts/components/microk8s-completion/patches/0001-microk8s-autocompleter-script.patch b/build-scripts/components/microk8s-completion/patches/0001-microk8s-autocompleter-script.patch new file mode 100644 index 0000000000..1a5a5e55ba --- /dev/null +++ b/build-scripts/components/microk8s-completion/patches/0001-microk8s-autocompleter-script.patch @@ -0,0 +1,84 @@ +From f154f915fe39d6b929dbe1e513011fd271fcd12c Mon Sep 17 00:00:00 2001 +From: Angelos Kolaitis +Date: Fri, 15 Jul 2022 15:07:18 +0300 +Subject: [PATCH] microk8s autocompleter script + +--- + cmd/helm/hack_microk8s_autocompleter.go | 51 +++++++++++++++++++++++++ + cmd/helm/helm.go | 2 +- + 2 files changed, 52 insertions(+), 1 deletion(-) + create mode 100644 cmd/helm/hack_microk8s_autocompleter.go + +diff --git a/cmd/helm/hack_microk8s_autocompleter.go b/cmd/helm/hack_microk8s_autocompleter.go +new file mode 100644 +index 00000000..e819f44b +--- /dev/null ++++ b/cmd/helm/hack_microk8s_autocompleter.go +@@ -0,0 +1,51 @@ ++// go:build microk8s_hack ++ ++package main ++ ++import ( ++ "bytes" ++ "log" ++ "os" ++ "strings" ++ ++ "github.com/spf13/cobra" ++ "helm.sh/helm/v3/pkg/action" ++ "k8s.io/kubectl/pkg/cmd" ++) ++ ++func main() { ++ command := &cobra.Command{Use: "microk8s"} ++ command.AddCommand(cmd.NewDefaultKubectlCommand()) ++ helmCmd, _ := newRootCmd(&action.Configuration{}, nil, nil) ++ helmCmd.Use = "helm" ++ helm3Cmd, _ := newRootCmd(&action.Configuration{}, nil, nil) ++ helm3Cmd.Use = "helm3" ++ command.AddCommand(&cobra.Command{Use: "addons", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "add-node", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "config", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "enable", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "disable", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(helmCmd) ++ command.AddCommand(helm3Cmd) ++ command.AddCommand(&cobra.Command{Use: "helm3", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "images", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "inspect", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "join", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "refresh-certs", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "remove-node", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "reset", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "start", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "status", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "stop", Run: func(cmd *cobra.Command, args []string) {}}) ++ command.AddCommand(&cobra.Command{Use: "version", Run: func(cmd *cobra.Command, args []string) {}}) ++ ++ var b bytes.Buffer ++ if err := command.GenBashCompletion(&b); err != nil { ++ log.Fatalf("failed to generate completion script: %v", err) ++ } ++ completionScript := b.String() ++ completionScript = strings.ReplaceAll(completionScript, `args=("${words[@]:1}")`, `args=("${words[@]:2}")`) ++ completionScript = strings.ReplaceAll(completionScript, `requestComp="${words[0]} __completeNoDesc ${args[*]}"`, `requestComp="${words[0]} ${words[1]} __completeNoDesc ${args[*]}"`) ++ ++ os.WriteFile("microk8s.bash", []byte(completionScript), 0644) ++} +diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go +index 15b0d5c7..6499d4ca 100644 +--- a/cmd/helm/helm.go ++++ b/cmd/helm/helm.go +@@ -55,7 +55,7 @@ func warning(format string, v ...interface{}) { + fmt.Fprintf(os.Stderr, format, v...) + } + +-func main() { ++func Main() { + // Setting the name of the app for managedFields in the Kubernetes client. + // It is set here to the full name of "helm" so that renaming of helm to + // another name (e.g., helm2 or helm3) does not change the name of the +-- +2.25.1 + diff --git a/build-scripts/components/microk8s-completion/repository b/build-scripts/components/microk8s-completion/repository new file mode 100644 index 0000000000..e7c0fbd488 --- /dev/null +++ b/build-scripts/components/microk8s-completion/repository @@ -0,0 +1 @@ +https://github.com/helm/helm diff --git a/build-scripts/components/microk8s-completion/version.sh b/build-scripts/components/microk8s-completion/version.sh new file mode 100755 index 0000000000..4382fc4905 --- /dev/null +++ b/build-scripts/components/microk8s-completion/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v3.9.1" diff --git a/build-scripts/components/migrator/build.sh b/build-scripts/components/migrator/build.sh new file mode 100755 index 0000000000..51b6996346 --- /dev/null +++ b/build-scripts/components/migrator/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +INSTALL="${1}/bin" +mkdir -p "${INSTALL}" + +go build -ldflags "-s -w" -o migrator ./main.go + +cp migrator "${INSTALL}/migrator" diff --git a/build-scripts/components/migrator/repository b/build-scripts/components/migrator/repository new file mode 100644 index 0000000000..39c6082333 --- /dev/null +++ b/build-scripts/components/migrator/repository @@ -0,0 +1 @@ +https://github.com/canonical/go-migrator diff --git a/build-scripts/components/migrator/version.sh b/build-scripts/components/migrator/version.sh new file mode 100755 index 0000000000..04baebd67c --- /dev/null +++ b/build-scripts/components/migrator/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "master" diff --git a/build-scripts/components/raft/build.sh b/build-scripts/components/raft/build.sh new file mode 100755 index 0000000000..626be929b0 --- /dev/null +++ b/build-scripts/components/raft/build.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +INSTALL="${1}" + +[ ! -f ./configure ] && [ -f ./autogen.sh ] && env NOCONFIGURE=1 ./autogen.sh +[ ! -f ./configure ] && [ -f ./bootstrap ] && env NOCONFIGURE=1 ./bootstrap +[ ! -f ./configure ] && autoreconf --install + +./configure + +mkdir -p build + +make -j"${SNAPCRAFT_PARALLEL_BUILD_COUNT}" +make install DESTDIR="${PWD}/build" + +mkdir -p "${INSTALL}/lib" "${INSTALL}/usr/include" + +cp -r "build/usr/local/lib/libraft"*"so"* "${INSTALL}/lib/" +cp -r "build/usr/local/include/"* "${INSTALL}/usr/include/" diff --git a/build-scripts/components/raft/repository b/build-scripts/components/raft/repository new file mode 100644 index 0000000000..f3ef47d84d --- /dev/null +++ b/build-scripts/components/raft/repository @@ -0,0 +1 @@ +https://github.com/canonical/raft diff --git a/build-scripts/components/raft/version.sh b/build-scripts/components/raft/version.sh new file mode 100755 index 0000000000..6df8112683 --- /dev/null +++ b/build-scripts/components/raft/version.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Matching https://github.com/canonical/dqlite/blob/master/configure.ac#L52 +echo "v0.14.0" diff --git a/build-scripts/components/runc/build.sh b/build-scripts/components/runc/build.sh new file mode 100755 index 0000000000..24559fa48d --- /dev/null +++ b/build-scripts/components/runc/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export INSTALL="${1}/bin" +mkdir -p "${INSTALL}" + +make BUILDTAGS="seccomp apparmor" EXTRA_LDFLAGS="-s -w" +cp runc "${INSTALL}/runc" diff --git a/build-scripts/components/runc/repository b/build-scripts/components/runc/repository new file mode 100644 index 0000000000..e8bdb4d77e --- /dev/null +++ b/build-scripts/components/runc/repository @@ -0,0 +1 @@ +https://github.com/opencontainers/runc diff --git a/build-scripts/patches/runc/0001-apparmor-change-profile-immediately-not-on-exec.patch b/build-scripts/components/runc/strict-patches/0001-apparmor-change-profile-immediately-not-on-exec.patch similarity index 100% rename from build-scripts/patches/runc/0001-apparmor-change-profile-immediately-not-on-exec.patch rename to build-scripts/components/runc/strict-patches/0001-apparmor-change-profile-immediately-not-on-exec.patch diff --git a/build-scripts/patches/runc/0002-setns_init_linux-set-the-NNP-flag-after-changing-the.patch b/build-scripts/components/runc/strict-patches/0002-setns_init_linux-set-the-NNP-flag-after-changing-the.patch similarity index 100% rename from build-scripts/patches/runc/0002-setns_init_linux-set-the-NNP-flag-after-changing-the.patch rename to build-scripts/components/runc/strict-patches/0002-setns_init_linux-set-the-NNP-flag-after-changing-the.patch diff --git a/build-scripts/patches/runc/0003-standard_init_linux-change-AppArmor-profile-as-late-.patch b/build-scripts/components/runc/strict-patches/0003-standard_init_linux-change-AppArmor-profile-as-late-.patch similarity index 100% rename from build-scripts/patches/runc/0003-standard_init_linux-change-AppArmor-profile-as-late-.patch rename to build-scripts/components/runc/strict-patches/0003-standard_init_linux-change-AppArmor-profile-as-late-.patch diff --git a/build-scripts/components/runc/version.sh b/build-scripts/components/runc/version.sh new file mode 100755 index 0000000000..370ee9feb5 --- /dev/null +++ b/build-scripts/components/runc/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v1.1.2" diff --git a/build-scripts/components/sqlite/build.sh b/build-scripts/components/sqlite/build.sh new file mode 100755 index 0000000000..d747e96081 --- /dev/null +++ b/build-scripts/components/sqlite/build.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +INSTALL="${1}" + +export CFLAGS="-DSQLITE_ENABLE_DBSTAT_VTAB=1" + +[ ! -f ./configure ] && [ -f ./autogen.sh ] && env NOCONFIGURE=1 ./autogen.sh +[ ! -f ./configure ] && [ -f ./bootstrap ] && env NOCONFIGURE=1 ./bootstrap +[ ! -f ./configure ] && autoreconf --install + +./configure + +mkdir -p build + +make -j"${SNAPCRAFT_PARALLEL_BUILD_COUNT}" +make install DESTDIR="${PWD}/build" + +mkdir -p "${INSTALL}/bin" "${INSTALL}/lib" "${INSTALL}/usr/include" + +cp "build/usr/local/bin/sqlite3" "${INSTALL}/bin/sqlite3" +cp -r "build/usr/local/lib/libsqlite3"*"so"* "${INSTALL}/lib/" +cp -r "build/usr/local/include/"* "${INSTALL}/usr/include/" diff --git a/build-scripts/components/sqlite/repository b/build-scripts/components/sqlite/repository new file mode 100644 index 0000000000..eef38753c1 --- /dev/null +++ b/build-scripts/components/sqlite/repository @@ -0,0 +1 @@ +https://github.com/sqlite/sqlite diff --git a/build-scripts/components/sqlite/version.sh b/build-scripts/components/sqlite/version.sh new file mode 100755 index 0000000000..d2abb351d6 --- /dev/null +++ b/build-scripts/components/sqlite/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "version-3.33.0" diff --git a/build-scripts/components/traefik/build.sh b/build-scripts/components/traefik/build.sh new file mode 100755 index 0000000000..e15d7b495e --- /dev/null +++ b/build-scripts/components/traefik/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash -x + +INSTALL="${1}/bin" +mkdir -p "${INSTALL}" + +export PATH="${PATH}:$(go env GOPATH)/bin" +GO111MODULE=off go get github.com/containous/go-bindata/... + +go generate +go build -ldflags "-s -w" ./cmd/traefik + +cp traefik "${INSTALL}/traefik" diff --git a/build-scripts/components/traefik/repository b/build-scripts/components/traefik/repository new file mode 100644 index 0000000000..9c7f112c84 --- /dev/null +++ b/build-scripts/components/traefik/repository @@ -0,0 +1 @@ +https://github.com/traefik/traefik diff --git a/build-scripts/components/traefik/version.sh b/build-scripts/components/traefik/version.sh new file mode 100755 index 0000000000..0cc9425d8f --- /dev/null +++ b/build-scripts/components/traefik/version.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "v2.4.9" diff --git a/build-scripts/fetch-k8s-binaries.sh b/build-scripts/fetch-k8s-binaries.sh deleted file mode 100755 index c7b46252fe..0000000000 --- a/build-scripts/fetch-k8s-binaries.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -set -eu - -apps="kubectl kube-apiserver kube-controller-manager kube-scheduler kubelet kube-proxy" -mkdir -p $KUBE_SNAP_BINS -echo $KUBE_VERSION > $KUBE_SNAP_BINS/version -(cd $KUBE_SNAP_BINS - for app in $apps; do - mkdir -p $KUBE_ARCH - (cd $KUBE_ARCH - echo "Fetching $app $KUBE_VERSION $KUBE_ARCH" - curl -LO \ - https://dl.k8s.io/${KUBE_VERSION}/bin/linux/$KUBE_ARCH/$app - chmod +x $app - if ! file ${app} 2>&1 | grep -q 'executable'; then - echo "${app} is not an executable" - exit 1 - fi - ) - done -) diff --git a/build-scripts/set-env-binaries-location.sh b/build-scripts/set-env-binaries-location.sh deleted file mode 100644 index 247d7e4fe2..0000000000 --- a/build-scripts/set-env-binaries-location.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -eu - -export KUBE_SNAP_BINS="build/kube_bins/$KUBE_VERSION" diff --git a/build-scripts/set-env-variables.sh b/build-scripts/set-env-variables.sh deleted file mode 100755 index 978275738e..0000000000 --- a/build-scripts/set-env-variables.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env bash -set -eu - -export ARCH="${KUBE_ARCH:-`dpkg --print-architecture`}" -KUBE_ARCH=${ARCH} -SNAP_ARCH=${KUBE_ARCH} -if [ "$ARCH" = "ppc64el" ]; then - KUBE_ARCH="ppc64le" -elif [ "$ARCH" = "armhf" ]; then - KUBE_ARCH="arm" -fi -export KUBE_ARCH -export ETCD_VERSION="${ETCD_VERSION:-v3.4.3}" -export FLANNELD_VERSION="${FLANNELD_VERSION:-v0.11.0}" -export CNI_VERSION="${CNI_VERSION:-v0.8.7}" -export KNATIVE_SERVING_VERSION="${KNATIVE_SERVING_VERSION:-v0.13.0}" -export KNATIVE_EVENTING_VERSION="${KNATIVE_EVENTING_VERSION:-v0.13.0}" -export TRAEFIK_VERSION="${TRAEFIK_VERSION:-v2.4.9}" -# RUNC commit matching the containerd release commit -# Tag 1.6.6 -export CONTAINERD_COMMIT="${CONTAINERD_COMMIT:-10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1}" -# Release v1.1.2 -export RUNC_COMMIT="${RUNC_COMMIT:-a916309fff0f838eb94e928713dbc3c0d0ac7aa4}" -# Set this to the kubernetes fork you want to build binaries from -export KUBERNETES_REPOSITORY="${KUBERNETES_REPOSITORY:-github.com/kubernetes/kubernetes}" - -export KUBE_TRACK="${KUBE_TRACK:-}" - -export KUBE_VERSION="${KUBE_VERSION:-}" -export KUBE_SNAP_BINS="${KUBE_SNAP_BINS:-}" -if [ -e "$KUBE_SNAP_BINS/version" ]; then - export KUBE_VERSION=`cat $KUBE_SNAP_BINS/version` -else - # KUBE_SNAP_BINS is not set meaning we will either build the binaries OR fetch them from upstream - # eitherway the k8s binaries should land at build/kube_bins/$KUBE_VERSION - if [ -z "$KUBE_VERSION" ]; then - # KUBE_VERSION is not set we will probably need the one from the upstream repo. If we build from - # source the KUBE_VERSION should be provided - if [ -z "$KUBE_TRACK" ]; then - export KUBE_VERSION="${KUBE_VERSION:-`curl -L https://dl.k8s.io/release/stable.txt`}" - else - export KUBE_VERSION="${KUBE_VERSION:-`curl -L https://dl.k8s.io/release/stable-${KUBE_TRACK}.txt`}" - fi - fi -fi - -export KUBERNETES_TAG="${KUBE_VERSION}" -export K8S_DQLITE_TAG="${K8S_DQLITE_TAG:-v1.0.4}" - -export KUBE_SNAP_ROOT="$(readlink -f .)" - -export ADDONS_REPOS=" -core,${CORE_ADDONS_REPO:-https://github.com/canonical/microk8s-core-addons},${CORE_ADDONS_REPO_BRANCH:-main} -community,${COMMUNITY_ADDONS_REPO:-https://github.com/canonical/microk8s-community-addons},${COMMUNITY_ADDONS_REPO_BRANCH:-main} -" -export ADDONS_REPOS_ENABLED="core" - -export CLUSTER_AGENT_REPO="${CLUSTER_AGENT_REPO:-https://github.com/canonical/microk8s-cluster-agent}" -export CLUSTER_AGENT_TAG="${CLUSTER_AGENT_TAG:-main}" - -echo "Building with:" -echo "KUBE_VERSION=${KUBE_VERSION}" -echo "ETCD_VERSION=${ETCD_VERSION}" -echo "FLANNELD_VERSION=${FLANNELD_VERSION}" -echo "CNI_VERSION=${CNI_VERSION}" -echo "KUBE_ARCH=${KUBE_ARCH}" -echo "KUBE_SNAP_BINS=${KUBE_SNAP_BINS}" -echo "KNATIVE_SERVING_VERSION=${KNATIVE_SERVING_VERSION}" -echo "KNATIVE_EVENTING_VERSION=${KNATIVE_EVENTING_VERSION}" -echo "TRAEFIK_VERSION=${TRAEFIK_VERSION}" -echo "RUNC_COMMIT=${RUNC_COMMIT}" -echo "CONTAINERD_COMMIT=${CONTAINERD_COMMIT}" -echo "KUBERNETES_REPOSITORY=${KUBERNETES_REPOSITORY}" -echo "KUBERNETES_TAG=${KUBERNETES_TAG}" -echo "K8S_DQLITE_TAG=${K8S_DQLITE_TAG}" -echo "CLUSTER_AGENT_REPO=${CLUSTER_AGENT_REPO}" -echo "CLUSTER_AGENT_TAG=${CLUSTER_AGENT_TAG}" - -echo "ADDONS_REPOS=${ADDONS_REPOS}" -echo "ADDONS_REPOS_ENABLED=${ADDONS_REPOS_ENABLED}" diff --git a/microk8s-resources/actions/common/utils.sh b/microk8s-resources/actions/common/utils.sh index 0e3a2f85bd..0e792c49b2 100644 --- a/microk8s-resources/actions/common/utils.sh +++ b/microk8s-resources/actions/common/utils.sh @@ -583,7 +583,7 @@ init_cluster() { echo "Address: $IP:19001" > ${SNAP_DATA}/var/kubernetes/backend/init.yaml DNS=$($SNAP/bin/hostname) mkdir -p $SNAP_DATA/var/tmp/ - cp $SNAP/microk8s-resources/certs/csr-dqlite.conf.template $SNAP_DATA/var/tmp/csr-dqlite.conf + cp $SNAP/certs/csr-dqlite.conf.template $SNAP_DATA/var/tmp/csr-dqlite.conf $SNAP/bin/sed -i 's/HOSTNAME/'"${DNS}"'/g' $SNAP_DATA/var/tmp/csr-dqlite.conf $SNAP/bin/sed -i 's/HOSTIP/'"${IP}"'/g' $SNAP_DATA/var/tmp/csr-dqlite.conf ${SNAP}/usr/bin/openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout ${SNAP_DATA}/var/kubernetes/backend/cluster.key -out ${SNAP_DATA}/var/kubernetes/backend/cluster.crt -subj "/CN=k8s" -config $SNAP_DATA/var/tmp/csr-dqlite.conf -extensions v3_ext diff --git a/microk8s-resources/default-hooks/post-refresh.d/30-helm b/microk8s-resources/default-hooks/post-refresh.d/30-helm new file mode 100644 index 0000000000..2cea9dfce4 --- /dev/null +++ b/microk8s-resources/default-hooks/post-refresh.d/30-helm @@ -0,0 +1,6 @@ +#!/bin/bash + +# Install helm binaries in SNAP_DATA to maintain backwards-compatibility +if [ -d "${SNAP_DATA}/bin" ]; then + cp "${SNAP}/bin/helm" "${SNAP_DATA}/bin/helm3" +fi diff --git a/microk8s-resources/wrappers/microk8s-add-node.wrapper b/microk8s-resources/wrappers/microk8s-add-node.wrapper index fadc6d776a..df1052d8f0 100755 --- a/microk8s-resources/wrappers/microk8s-add-node.wrapper +++ b/microk8s-resources/wrappers/microk8s-add-node.wrapper @@ -17,14 +17,14 @@ then exit 1 fi -if [ -e "$SNAP_DATA/args/cni-network/cni.yaml.disabled" ] && [ -e "$SNAP_DATA/args/cni-network/05-cilium-cni.conf" ] ; then +if [ -e "$SNAP_DATA/args/cni-network/cni.yaml.disabled" ] && [ -e "$SNAP_DATA/args/cni-network/05-cilium-cni.conf" ] ; then echo "Cilium is enabled and is not suitable for multi node clusters." exit 1 fi if echo "$*" | grep -q -- 'help'; then # Call add_token.py help - LD_LIBRARY_PATH=$IN_SNAP_LD_LIBRARY_PATH ${SNAP}/usr/bin/python3 ${SNAP}/scripts/cluster/add_token.py --help + LD_LIBRARY_PATH=$IN_SNAP_LD_LIBRARY_PATH ${SNAP}/usr/bin/python3 ${SNAP}/scripts/wrappers/add_token.py --help exit 0 fi @@ -48,7 +48,7 @@ fi exit_if_stopped if [ ! -f "$SNAP_DATA/credentials/cluster-tokens.txt" ]; then - touch $SNAP_DATA/credentials/cluster-tokens.txt + touch $SNAP_DATA/credentials/cluster-tokens.txt fi group=$(get_microk8s_group) diff --git a/microk8s-resources/wrappers/microk8s-helm.wrapper b/microk8s-resources/wrappers/microk8s-helm.wrapper index addab43244..58db7a9a33 100755 --- a/microk8s-resources/wrappers/microk8s-helm.wrapper +++ b/microk8s-resources/wrappers/microk8s-helm.wrapper @@ -1,15 +1,3 @@ #!/bin/bash -set -eu - -export PATH="$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH" -ARCH="$($SNAP/bin/uname -m)" -export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$ARCH-linux-gnu:$SNAP/usr/lib/$ARCH-linux-gnu" - -if [ ! -f "${SNAP_DATA}/bin/helm" ]; then - echo "Helm not available, try enabling it with 'microk8s enable helm'" >&2 - exit 0 -fi - -source $SNAP/actions/common/utils.sh -"${SNAP_DATA}/bin/helm" --kubeconfig="${SNAP_DATA}"/credentials/client.config "$@" +"${SNAP}/bin/helm" --kubeconfig="${SNAP_DATA}"/credentials/client.config "$@" diff --git a/microk8s-resources/wrappers/microk8s-helm3.wrapper b/microk8s-resources/wrappers/microk8s-helm3.wrapper index 3070eba1aa..58db7a9a33 100755 --- a/microk8s-resources/wrappers/microk8s-helm3.wrapper +++ b/microk8s-resources/wrappers/microk8s-helm3.wrapper @@ -1,15 +1,3 @@ #!/bin/bash -set -eu - -export PATH="$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH" -ARCH="$($SNAP/bin/uname -m)" -export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$ARCH-linux-gnu:$SNAP/usr/lib/$ARCH-linux-gnu" - -if [ ! -f "${SNAP_DATA}/bin/helm3" ]; then - echo "Helm 3 not available, try enabling it with 'microk8s enable helm3'" >&2 - exit 0 -fi - -source $SNAP/actions/common/utils.sh -"${SNAP_DATA}/bin/helm3" --kubeconfig="${SNAP_DATA}"/credentials/client.config "$@" +"${SNAP}/bin/helm" --kubeconfig="${SNAP_DATA}"/credentials/client.config "$@" diff --git a/microk8s-resources/wrappers/microk8s-images.wrapper b/microk8s-resources/wrappers/microk8s-images.wrapper index bfb95ea857..495138a53b 100755 --- a/microk8s-resources/wrappers/microk8s-images.wrapper +++ b/microk8s-resources/wrappers/microk8s-images.wrapper @@ -12,4 +12,4 @@ export PYTHONNOUSERSITE=false exit_if_no_permissions -LD_LIBRARY_PATH=$IN_SNAP_LD_LIBRARY_PATH ${SNAP}/usr/bin/python3 ${SNAP}/scripts/cluster/images.py $@ +LD_LIBRARY_PATH=$IN_SNAP_LD_LIBRARY_PATH ${SNAP}/usr/bin/python3 ${SNAP}/scripts/wrappers/images.py $@ diff --git a/scripts/wrappers/join.py b/scripts/wrappers/join.py index 02a308ee75..1a1bf4b55d 100755 --- a/scripts/wrappers/join.py +++ b/scripts/wrappers/join.py @@ -343,7 +343,7 @@ def create_kubeconfig(token, ca, master_ip, api_port, filename, user): :param user: the user to use al login """ snap_path = os.environ.get("SNAP") - config_template = "{}/microk8s-resources/{}".format(snap_path, "kubelet.config.template") + config_template = "{}/{}".format(snap_path, "kubelet.config.template") config = "{}/credentials/{}".format(snapdata_path, filename) shutil.copyfile(config, "{}.backup".format(config)) try_set_file_permissions("{}.backup".format(config)) @@ -373,7 +373,7 @@ def create_x509_kubeconfig(ca, master_ip, api_port, filename, user, path_to_cert :param path_to_cert_key: path to certificate key file """ snap_path = os.environ.get("SNAP") - config_template = "{}/microk8s-resources/{}".format(snap_path, "client-x509.config.template") + config_template = "{}/{}".format(snap_path, "client-x509.config.template") config = "{}/credentials/{}".format(snapdata_path, filename) shutil.copyfile(config, "{}.backup".format(config)) try_set_file_permissions("{}.backup".format(config)) @@ -628,7 +628,7 @@ def create_admin_kubeconfig(ca, ha_admin_token=None): else: token = ha_admin_token assert token is not None - config_template = "{}/microk8s-resources/{}".format(snap_path, "client.config.template") + config_template = "{}/{}".format(snap_path, "client.config.template") config = "{}/credentials/client.config".format(snapdata_path) shutil.copyfile(config, "{}.backup".format(config)) try_set_file_permissions("{}.backup".format(config)) diff --git a/scripts/wrappers/leave.py b/scripts/wrappers/leave.py index aadb1ea5c2..82e4c5cc65 100755 --- a/scripts/wrappers/leave.py +++ b/scripts/wrappers/leave.py @@ -73,7 +73,7 @@ def rebuild_client_config(): print("Error, could not locate admin token. Resetting the node failed.") exit(2) - config_template = "{}/microk8s-resources/{}".format(snap_path, "client.config.template") + config_template = "{}/{}".format(snap_path, "client.config.template") config = "{}/credentials/client.config".format(snapdata_path) shutil.copyfile(config, "{}.backup".format(config)) try_set_file_permissions("{}.backup".format(config)) @@ -239,7 +239,7 @@ def reinit_cluster(): hostname = socket.gethostname() # type: str ip = "127.0.0.1" # type: str shutil.copy( - "{}/microk8s-resources/certs/csr-dqlite.conf.template".format(snap_path), + "{}/certs/csr-dqlite.conf.template".format(snap_path), "{}/var/tmp/csr-dqlite.conf".format(snapdata_path), ) subprocess.check_call( diff --git a/snap/hooks/configure b/snap/hooks/configure index ebeaa80acc..860f0eb15d 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -48,6 +48,7 @@ fi # and make sure the respective services use them. # Without this patch the user would have to remove and reainstall microk8s. # This patch can be removed at a later stage. +# TODO(neoaggelos): investigate if this is needed if [ ! -d ${SNAP_DATA}/certs ] && grep -e "\-\-client-ca-file=\${SNAP}/certs/ca.crt" ${SNAP_DATA}/args/kube-apiserver then echo "Patching certificates location" @@ -65,6 +66,7 @@ then fi #Allow the ability to add external IPs to the csr, by moving the csr.conf.template to SNAP_DATA +# TODO(neoaggelos): investigate if this is needed if [ ! -f ${SNAP_DATA}/certs/csr.conf.template ] then cp ${SNAP}/certs/csr.conf.template ${SNAP_DATA}/certs/csr.conf.template @@ -114,11 +116,12 @@ mkdir -p ${SNAP_DATA}/tmp/ # This will allow us to refresh the snap to the more secure version. # We need to make sure the client certificate used in microk8s kubectl is available under $SNAP_DATA +# TODO(neoaggelos): investigate whether this is needed if [ ! -f ${SNAP_DATA}/credentials/client.config ] then echo "Patching client config location" mkdir -p ${SNAP_DATA}/credentials/ - cp ${SNAP}/microk8s-resources/client.config ${SNAP_DATA}/credentials/ + cp ${SNAP}/client.config ${SNAP_DATA}/credentials/ fi # copy kubectl-env @@ -183,7 +186,7 @@ fi # Install default-hooks if ! [ -d "${SNAP_COMMON}/hooks" ] then - cp -r --preserve=mode ${SNAP}/microk8s-resources/default-hooks ${SNAP_COMMON}/hooks + cp -r --preserve=mode ${SNAP}/default-hooks ${SNAP_COMMON}/hooks fi # Make sure the server certificate includes the IP we are using diff --git a/snap/hooks/install b/snap/hooks/install index 8c43c4ab0c..66bc691a2c 100755 --- a/snap/hooks/install +++ b/snap/hooks/install @@ -91,7 +91,7 @@ $SNAP/bin/sed -i 's/AUTHTYPE/token/g' ${SNAP_DATA}/credentials/proxy.config $SNAP/bin/sed -i 's/PASSWORD/'"${proxy_token}"'/g' ${SNAP_DATA}/credentials/proxy.config # Install default-hooks -cp -r --preserve=mode ${SNAP}/microk8s-resources/default-hooks ${SNAP_COMMON}/hooks +cp -r --preserve=mode ${SNAP}/default-hooks ${SNAP_COMMON}/hooks for dir in ${SNAP_DATA}/credentials/ ${SNAP_DATA}/certs/ ${SNAP_DATA}/args/ ${SNAP_COMMON}/hooks do diff --git a/snap/hooks/post-refresh b/snap/hooks/post-refresh old mode 100644 new mode 100755 diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 7c39ccbe2f..5d171d8a8f 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: microk8s -adopt-info: microk8s +adopt-info: kubernetes summary: Kubernetes for workstations and appliances description: |- MicroK8s is a small, fast, secure, single node Kubernetes that installs on @@ -15,6 +15,7 @@ base: core18 apps: microk8s: command: microk8s.wrapper + completer: microk8s.bash daemon-etcd: command: run-etcd-with-args daemon: simple @@ -105,8 +106,10 @@ apps: command: microk8s-linkerd.wrapper helm: command: microk8s-helm.wrapper + completer: helm.bash helm3: command: microk8s-helm3.wrapper + completer: helm3.bash cilium: command: microk8s-cilium.wrapper dbctl: @@ -115,343 +118,143 @@ apps: command: microk8s-version.wrapper parts: + build-deps: + plugin: nil + override-build: | + snap install go --classic + snap refresh go --channel 1.18 + build-packages: + - autoconf + - automake + - autopoint + - autotools-dev + - bison + - btrfs-tools + - build-essential + - curl + - flex + - git + - libjansson-dev + - liblz4-dev + - libnetfilter-conntrack-dev + - libnetfilter-conntrack3 + - libnfnetlink-dev + - libseccomp-dev + - libtool + - libuv1-dev + - pkg-config + - rsync + - tcl + raft: - source: https://github.com/canonical/raft - source-tag: v0.13.0 + after: [build-deps] + source: build-scripts/ build-attributes: [no-patchelf] - source-type: git - plugin: autotools + plugin: nil + override-build: ./build-component.sh raft stage-packages: - libuv1 - build-packages: - - liblz4-dev - organize: - usr/lib/: lib/ - include/: usr/include/ - prime: - - lib/libraft*so* - - usr/include/ + stage: + - -usr/share/doc + - -usr/share/man sqlite: - source: https://github.com/sqlite/sqlite - source-type: git - source-depth: 1 - source-tag: version-3.33.0 + after: [build-deps] + source: build-scripts/ build-attributes: [no-patchelf] - build-environment: - - CFLAGS: "-DSQLITE_ENABLE_DBSTAT_VTAB=1" - plugin: autotools - build-packages: - - tcl - override-build: |- - set -ex - git log -1 --format=format:%ci%n | sed -e 's/ [-+].*$//;s/ /T/;s/^/D /' > manifest - git log -1 --format=format:%H > manifest.uuid - cp /usr/share/misc/config.guess . - cp /usr/share/misc/config.sub . - autoreconf -f -i - set +ex - snapcraftctl build - organize: - include/: usr/include/ - prime: - - bin/sqlite3 - - lib/libsqlite3*so* - - usr/include/ + plugin: nil + override-build: ./build-component.sh sqlite dqlite: - after: - - raft - - sqlite - source: https://github.com/canonical/dqlite - source-tag: v1.10.0 + after: [sqlite, raft] + source: build-scripts/ build-attributes: [no-patchelf] - source-type: git - plugin: autotools - stage-packages: - - libuv1 - build-packages: - - libuv1-dev - - pkg-config - organize: - usr/lib/: lib/ - include/: usr/include/ - prime: - - lib/libdqlite*so* - - lib/*/libuv* - - usr/include/ + plugin: nil + override-build: ./build-component.sh dqlite dqlite-client: - build-snaps: [go] - after: [sqlite, dqlite] + after: [dqlite] + plugin: nil source: build-scripts/ - plugin: dump - override-build: | - set -eux - snap refresh go --channel=1.15/stable || true - go version - export TAG=v1.11.1 - export GOPATH=${SNAPCRAFT_STAGE} - export CGO_CFLAGS="-I${SNAPCRAFT_STAGE}/usr/include/" - export CGO_LDFLAGS="-L${SNAPCRAFT_STAGE}/lib" - export CGO_LDFLAGS_ALLOW="-Wl,-z,now" - mkdir -p $SNAPCRAFT_PART_INSTALL/bin - mkdir -p $GOPATH/src/github.com/canonical/ - ( - cd $GOPATH/src/github.com/canonical/ - rm -rf go-dqlite - git clone https://github.com/canonical/go-dqlite - cd go-dqlite - git checkout tags/"${TAG}" -b build - go build -v -tags libsqlite3 ./cmd/dqlite - cd .. - ) - cp $GOPATH/src/github.com/canonical/go-dqlite/dqlite $SNAPCRAFT_PART_INSTALL/bin/ + override-build: ./build-component.sh dqlite-client k8s-dqlite: - build-snaps: [go] - after: [dqlite-client, dqlite] + after: [dqlite] source: build-scripts/ - plugin: dump - override-build: | - set -eux - . $SNAPCRAFT_PART_SRC/set-env-variables.sh - snap refresh go --channel=1.15/stable || true - go version - export GOPATH=${SNAPCRAFT_STAGE} - export CGO_LDFLAGS_ALLOW="-Wl,-z,now" - export CGO_CFLAGS="-I${SNAPCRAFT_STAGE}/usr/include/" - export CGO_LDFLAGS="-L${SNAPCRAFT_STAGE}/lib" - mkdir -p $GOPATH/src/github.com/canonical/ - ( - cd $GOPATH/src/github.com/canonical/ - rm -rf k8s-dqlite - git clone https://github.com/canonical/k8s-dqlite - cd k8s-dqlite - git checkout tags/"${K8S_DQLITE_TAG}" -b build - go build -tags libsqlite3,dqlite . - cd .. - ) - mkdir -p $SNAPCRAFT_PART_INSTALL/bin - cp $GOPATH/src/github.com/canonical/k8s-dqlite/k8s-dqlite $SNAPCRAFT_PART_INSTALL/bin/ - stage-packages: - - openssl + plugin: nil + override-build: ./build-component.sh k8s-dqlite etcd: - plugin: dump + after: [build-deps] + plugin: nil source: build-scripts/ - build-snaps: [go] - override-build: | - . ./set-env-variables.sh - case ${SNAPCRAFT_ARCH_TRIPLET%%-*} in - x86_64|aarch64) - echo "Supported arch by etcd - use official binary" - curl -LO https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-$KUBE_ARCH.tar.gz - tar -xzvf etcd-*.tar.gz --strip-components=1 - ;; - *) - echo "Unsupported arch by etcd - build from sources" - curl -LO https://github.com/etcd-io/etcd/archive/${ETCD_VERSION}.tar.gz - tar -xzf *.tar.gz - cd etcd-* - go mod vendor - ./build - cp -av bin/* ../ - echo "End of build" - esac - snapcraftctl build - stage: - - etcd - - etcdctl + override-build: ./build-component.sh etcd traefik: - plugin: dump + after: [build-deps] + plugin: nil source: build-scripts/ - build-snaps: [go] + override-build: ./build-component.sh traefik build-attributes: [no-patchelf] - override-build: | - . ./set-env-variables.sh - mkdir -p $SNAPCRAFT_PART_INSTALL/bin - case ${SNAPCRAFT_ARCH_TRIPLET%%-*} in - x86_64|aarch64) - echo "Supported arch by traefik - use official binary" - curl -LO https://github.com/traefik/traefik/releases/download/${TRAEFIK_VERSION}/traefik_${TRAEFIK_VERSION}_linux_${KUBE_ARCH}.tar.gz - tar -xzvf traefik_*.tar.gz - cp traefik $SNAPCRAFT_PART_INSTALL/bin/ - ;; - *) - echo "Unsupported arch by traefik - building from sources" - snap refresh go --channel=1.16/stable || true - go version - export GOPATH=$(realpath ../go) - mkdir -p $SNAPCRAFT_PART_INSTALL/bin - rm -rf $GOPATH - mkdir -p $GOPATH - curl -LO https://github.com/traefik/traefik/releases/download/${TRAEFIK_VERSION}/traefik-${TRAEFIK_VERSION}.src.tar.gz - mkdir -p $GOPATH/src/github.com/traefik/traefik - mv traefik*.tar.gz $GOPATH/src/github.com/traefik/traefik - ( - cd $GOPATH/src/github.com/traefik/traefik - GO111MODULE=off go get github.com/containous/go-bindata/... - export GO111MODULE=on - tar -zxvf traefik*.tar.gz - rm -rf static/ autogen/; - #make generate-webui - export PATH=$PATH:$GOPATH/bin - go generate - go build ./cmd/traefik - ) - cp $GOPATH/src/github.com/traefik/traefik/traefik $SNAPCRAFT_PART_INSTALL/bin/ - esac - stage: - - bin/traefik cni: - plugin: dump + after: [build-deps] + plugin: nil source: build-scripts/ - override-build: | - . ./set-env-variables.sh - rm -rf cni* - curl -LO https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-$KUBE_ARCH-${CNI_VERSION}.tgz - mkdir cni - tar -xzvf cni-*.tgz -C cni/ - snapcraftctl build - organize: - ./cni/*: opt/cni/bin/ - filesets: - bins: [./opt/cni/bin/*] - stage: [$bins] + override-build: ./build-component.sh cni flanneld: - plugin: dump + after: [build-deps] + plugin: nil source: build-scripts/ - override-build: | - . ./set-env-variables.sh - curl -LO https://github.com/coreos/flannel/releases/download/${FLANNELD_VERSION}/flannel-${FLANNELD_VERSION}-linux-${KUBE_ARCH}.tar.gz - tar -xzvf flannel-*.tar.gz - snapcraftctl build - organize: - flanneld: opt/cni/bin/ - stage: - - opt/cni/bin/flanneld + override-build: ./build-component.sh flanneld - k8s-binaries: - after: [dqlite] - build-snaps: [go] - plugin: dump + kubernetes: + after: [build-deps] + plugin: nil build-attributes: [no-patchelf] source: build-scripts/ - build-packages: - - build-essential - - curl - - git override-build: | - set -eux - snap refresh go --channel=1.18/stable || true - . ./set-env-variables.sh - - # if "${KUBE_SNAP_BINS}" exist we have to use the binaries from there - # if "${KUBE_SNAP_BINS}" does not exist but it is set we will put the k8s binaries there - # if "${KUBE_SNAP_BINS}" does not exist and it is not set we do not need to keep the created binaries - if [ ! -e "${KUBE_SNAP_BINS}" ]; then - if [ -z "${KUBE_SNAP_BINS}" ]; then - . ./set-env-binaries-location.sh - fi - echo "Building k8s binaries" - . ./build-k8s-binaries.sh - else - echo "Binaries provided in $KUBE_SNAP_BINS" - fi - mkdir -p bins/ - cp build/kube_bins/$KUBERNETES_TAG/$KUBE_ARCH/* bins/ - - # Add bash completion for microk8s kubectl. - bins/kubectl completion bash | sed "s/complete -o default -F __start_kubectl kubectl/complete -o default -F __start_kubectl microk8s kubectl/g" | sed "s/complete -o default -o nospace -F __start_kubectl kubectl/complete -o default -o nospace -F __start_kubectl kubectl/g" > kubectl.bash - bins/kubectl completion bash | sed "s/complete -o default -F __start_kubectl kubectl/complete -o default -F __start_kubectl microk8s.kubectl/g" | sed "s/complete -o default -o nospace -F __start_kubectl kubectl/complete -o default -o nospace -F __start_kubectl kubectl/g" > kubectl.bash + ./build-component.sh kubernetes + snapcraftctl set-version "$(components/kubernetes/version.sh)" - snapcraftctl build - organize: - bins/*: . - stage: - - kubelite - - kubectl - - kubectl.bash + helm: + after: [build-deps] + plugin: nil + source: build-scripts/ + override-build: ./build-component.sh helm libmnl: + after: [build-deps] plugin: autotools source: https://www.netfilter.org/pub/libmnl/libmnl-1.0.4.tar.bz2 libnftnl: - after: - - libmnl + after: [libmnl] plugin: autotools source: https://www.netfilter.org/projects/libnftnl/files/libnftnl-1.1.8.tar.bz2 - build-packages: - - libjansson-dev iptables: - after: - - libnftnl + after: [libnftnl] source: https://www.netfilter.org/projects/iptables/files/iptables-1.8.6.tar.bz2 plugin: autotools - build-packages: - - bison - - flex - - libnfnetlink-dev - - libnetfilter-conntrack3 - - libnetfilter-conntrack-dev configflags: - "--disable-shared" - "--enable-static" prime: [-bin/iptables-xml] migrator: - build-snaps: [go] - source: https://github.com/canonical/go-migrator - source-type: git - plugin: go - go-channel: 1.15/stable - go-importpath: github.com/canonical/go-migrator - build-packages: - - gcc - prime: - - bin/migrator + after: [build-deps] + plugin: nil + source: build-scripts/ + override-build: ./build-component.sh migrator containerd: - build-snaps: [go] - after: [iptables, runc] - build-attributes: [no-patchelf] + after: [runc] + plugin: nil source: build-scripts/ - plugin: dump - build-packages: - - btrfs-tools - - libseccomp-dev - override-build: | - set -eux - . $SNAPCRAFT_PART_SRC/set-env-variables.sh - snap refresh go --channel=1.18/stable || true - go version - export GOPATH=$(realpath ../go) - mkdir -p $SNAPCRAFT_PART_INSTALL/bin - - # Build containerd - rm -rf $GOPATH - mkdir -p $GOPATH - git clone https://github.com/containerd/containerd $GOPATH/containerd - ( - cd $GOPATH/containerd - git checkout -f ${CONTAINERD_COMMIT} - # building the btrfs driver can be disabled via the - # build tag no_btrfs, removing this dependency - make - ) - cp $GOPATH/containerd/bin/* $SNAPCRAFT_PART_INSTALL/bin/ - rm $SNAPCRAFT_PART_INSTALL/bin/containerd-stress - - # Assemble the snap - snapcraftctl build - organize: - containerd/install/bin/*: bin/ + override-build: ./build-component.sh containerd + build-attributes: [no-patchelf] stage-packages: - libnss-myhostname - libnss-resolve @@ -462,45 +265,17 @@ parts: - -sbin/xtables-multi - -sbin/iptables* - -lib/xtables + - -usr/share/doc + - -usr/share/man runc: - build-snaps: [go] - after: [iptables] + after: [iptables, build-deps] source: build-scripts/ - plugin: dump - build-packages: - - btrfs-tools - - libseccomp-dev - override-build: | - set -eux - . $SNAPCRAFT_PART_SRC/set-env-variables.sh - - snap refresh go --channel=1.18/stable || true - go version - export GOPATH=$(realpath ../go) - - mkdir -p $SNAPCRAFT_PART_INSTALL/bin - if [ -d ${GOPATH}/runc ]; then - rm -rf ${GOPATH}/runc - fi - git clone https://github.com/opencontainers/runc ${GOPATH}/runc - ( - cd $GOPATH/runc - git checkout ${RUNC_COMMIT} - make BUILDTAGS='seccomp apparmor' - ) - cp $GOPATH/runc/runc $SNAPCRAFT_PART_INSTALL/bin/ - - # Assemble the snap - snapcraftctl build - stage: - - -sbin/xtables-multi - - -sbin/iptables* - - -lib/xtables + plugin: nil + override-build: ./build-component.sh runc bash-utils: - source: snap - plugin: dump + plugin: nil stage-packages: - aufs-tools - coreutils @@ -517,61 +292,39 @@ parts: - libatm1 - members - net-tools + - openssl - sed - socat - squashfs-tools - tar - util-linux - zfsutils-linux + stage: + - -usr/share/doc + - -usr/share/man cluster-agent: - build-snaps: [go] - build-packages: [make] + after: [build-deps] build-attributes: [no-patchelf] - plugin: dump - source: . - override-build: | - set -eux - snap refresh go --channel=1.18/stable || true - - mkdir -p $SNAPCRAFT_PART_INSTALL/bin - . build-scripts/set-env-variables.sh - - go version - export GOPATH=$(realpath ../go) - - mkdir -p $SNAPCRAFT_PART_INSTALL/bin - if [ -d ${GOPATH}/cluster-agent ]; then - rm -rf ${GOPATH}/cluster-agent - fi - git clone ${CLUSTER_AGENT_REPO} -b ${CLUSTER_AGENT_TAG} ${GOPATH}/cluster-agent - ( - cd ${GOPATH}/cluster-agent - make cluster-agent - ) - cp ${GOPATH}/cluster-agent/cluster-agent $SNAPCRAFT_PART_INSTALL/bin - - # Assemble the snap - snapcraftctl build + plugin: nil + source: build-scripts/ + override-build: ./build-component.sh cluster-agent microk8s-addons: - plugin: dump + plugin: nil build-attributes: [no-patchelf] - build-packages: - - python3 - - python3-yaml - - python3-click - - git - source: . + source: build-scripts/ override-build: | set -eux - . build-scripts/set-env-variables.sh + . ./addon-repositories.sh - if [ -d "addons" ]; then + if [ -d "${SNAPCRAFT_PART_INSTALL}" ]; then + rm -rf "${SNAPCRAFT_PART_INSTALL}/*" + fi + if [ -d addons ]; then rm -rf addons fi - mkdir -p addons IFS=';' echo "${ADDONS_REPOS}" | while read line; do @@ -585,72 +338,73 @@ parts: done echo "${ADDONS_REPOS_ENABLED}" > addons/.auto-add - snapcraftctl build + cp -r "addons" "${SNAPCRAFT_PART_INSTALL}/addons" - microk8s: - plugin: dump - build-attributes: [no-patchelf] - build-packages: - - make - - mercurial - - git - - rsync - - openssl - - file - - dpkg - source: . - prime: - - -README* - - -installer* - - -tests* - - -docs* - - -build* - - -go* - - -snap* + microk8s-scripts: + plugin: nil + source: scripts/ override-build: | - set -eux - - . build-scripts/set-env-variables.sh + if [ -d "${SNAPCRAFT_PART_INSTALL}" ]; then + rm -rf "${SNAPCRAFT_PART_INSTALL}/*" + fi - snapcraftctl set-version "${KUBE_VERSION}" + cp -r . "${SNAPCRAFT_PART_INSTALL}/scripts" + cp inspect.sh "${SNAPCRAFT_PART_INSTALL}/inspect.sh" - echo "Setting default daemon configs" - cp -r $KUBE_SNAP_ROOT/microk8s-resources/default-args . + microk8s-upgrade-scripts: + plugin: nil + source: upgrade-scripts/ + override-build: | + if [ -d "${SNAPCRAFT_PART_INSTALL}" ]; then + rm -rf "${SNAPCRAFT_PART_INSTALL}/*" + fi - echo "Building certs" - cp -r $KUBE_SNAP_ROOT/microk8s-resources/certs . - cp -r $KUBE_SNAP_ROOT/microk8s-resources/certs-beta . + cp -r . "${SNAPCRAFT_PART_INSTALL}/upgrade-scripts" - echo "Preparing containerd" - cp $KUBE_SNAP_ROOT/microk8s-resources/containerd-profile . + microk8s: + plugin: nil + source: microk8s-resources/ + override-build: | + if [ -d "${SNAPCRAFT_PART_INSTALL}" ]; then + rm -rf "${SNAPCRAFT_PART_INSTALL}/*" + fi - echo "Preparing user config" - cp $KUBE_SNAP_ROOT/microk8s-resources/client.config.template . + cp -r default-args "${SNAPCRAFT_PART_INSTALL}/default-args" + cp -r default-hooks "${SNAPCRAFT_PART_INSTALL}/default-hooks" + cp -r certs "${SNAPCRAFT_PART_INSTALL}/certs" + cp -r certs-beta "${SNAPCRAFT_PART_INSTALL}/certs-beta" - echo "Creating commands and wrappers" - cp $KUBE_SNAP_ROOT/microk8s-resources/wrappers/* . + cp containerd-profile "${SNAPCRAFT_PART_INSTALL}/containerd-profile" - cp -r $KUBE_SNAP_ROOT/microk8s-resources/actions . + cp client.config "${SNAPCRAFT_PART_INSTALL}/client.config" + cp client.config.template "${SNAPCRAFT_PART_INSTALL}/client.config.template" + cp kubelet.config.template "${SNAPCRAFT_PART_INSTALL}/kubelet.config.template" + cp client-x509.config.template "${SNAPCRAFT_PART_INSTALL}/client-x509.config.template" - echo "Creating inspect hook" - cp $KUBE_SNAP_ROOT/scripts/inspect.sh . + cp -r wrappers/* "${SNAPCRAFT_PART_INSTALL}/" + cp -r actions/ "${SNAPCRAFT_PART_INSTALL}/actions" - snapcraftctl build + microk8s-completion: + after: [build-deps] + plugin: nil + source: build-scripts/ + override-build: ./build-component.sh microk8s-completion python-requirements: plugin: python python-version: python3 - source: . python-packages: - PyYAML == 5.3.1 - netifaces == 0.10.9 - jsonschema == 4.0.0 stage-packages: - - openssl - python3-openssl - python3-requests - python3-click - python3-dateutil + stage: + - -usr/share/doc + - -usr/share/man slots: microk8s: