diff --git a/.github/scripts/kubernetes.sh b/.github/scripts/kubernetes.sh index edc606f..37c25f1 100755 --- a/.github/scripts/kubernetes.sh +++ b/.github/scripts/kubernetes.sh @@ -1,11 +1,12 @@ #!/bin/bash -set -eu +set -eux readonly ERR_CODE=127 readonly ARCH=${arch?} readonly CRI_TYPE=${criType?} +readonly KUBE_TYPE=${kubeType:-k8s} readonly KUBE=${kubeVersion?} readonly SEALOS=${sealoslatest?} @@ -25,7 +26,7 @@ mkdir -p "$ROOT" "$PATCH" cp -a "$CRI_TYPE"/* "$ROOT" cp -a registry/* "$ROOT" -cp -a k8s/* "$ROOT" +cp -a "$KUBE_TYPE"/* "$ROOT" # debug for sealos run { @@ -56,7 +57,7 @@ else fi # crictl helm kubeadm,kubectl,kubelet conntrack registry and cri(kubelet) -MOUNT_KUBE=$(sudo buildah mount "$(sudo buildah from "$IMAGE_CACHE_NAME:kubernetes-v$KUBE-$ARCH")") +MOUNT_KUBE=$(sudo buildah mount "$(sudo buildah from "$IMAGE_CACHE_NAME:kubernetes-v${KUBE%+*}-$ARCH")") MOUNT_CRIO=$(sudo buildah mount "$(sudo buildah from "$IMAGE_CACHE_NAME:cri-v$KUBE_XY-$ARCH")") MOUNT_TOOLS=$(sudo buildah mount "$(sudo buildah from "$IMAGE_CACHE_NAME:tools-$ARCH")") sudo tar -xzf "$MOUNT_CRIO"/cri/crictl.tar.gz -C bin/ @@ -92,6 +93,10 @@ docker) esac ;; esac +if grep k3s <<<"$KUBE"; then + IMAGE_KUBE=k3s + rm -f bin/crictl cri/cri-containerd.tar.gz +fi # define ImageTag for kube if [[ "${SEALOS//./}" =~ ^[0-9]+$ ]] && [[ -z "$sealosPatch" ]]; then @@ -100,12 +105,12 @@ if [[ "${SEALOS//./}" =~ ^[0-9]+$ ]] && [[ -z "$sealosPatch" ]]; then until curl -sL "https://api.github.com/repos/labring/sealos/releases/latest"; do sleep 3; done | grep tarball_url | awk -F\" '{print $(NF-1)}' | awk -F/ '{print $NF}' | cut -dv -f2 )" ]]; then IMAGE_PUSH_NAME=( - "$IMAGE_HUB_REGISTRY/$IMAGE_HUB_REPO/$IMAGE_KUBE:v$KUBE-$ARCH" - "$IMAGE_HUB_REGISTRY/$IMAGE_HUB_REPO/$IMAGE_KUBE:v$KUBE-$SEALOS-$ARCH" + "$IMAGE_HUB_REGISTRY/$IMAGE_HUB_REPO/$IMAGE_KUBE:v${KUBE%+*}-$ARCH" + "$IMAGE_HUB_REGISTRY/$IMAGE_HUB_REPO/$IMAGE_KUBE:v${KUBE%+*}-$SEALOS-$ARCH" ) else IMAGE_PUSH_NAME=( - "$IMAGE_HUB_REGISTRY/$IMAGE_HUB_REPO/$IMAGE_KUBE:v$KUBE-$SEALOS-$ARCH" + "$IMAGE_HUB_REGISTRY/$IMAGE_HUB_REPO/$IMAGE_KUBE:v${KUBE%+*}-$SEALOS-$ARCH" ) fi else @@ -130,10 +135,23 @@ echo "$ipvsImage" >images/shim/LvscareImageList # update Kubefile pauseImage=$(sudo grep /pause: "$MOUNT_KUBE/images/shim/DefaultImageList") -# shellcheck disable=SC2002 -cat Kubefile | - sed -E "s#^FROM .+#FROM $IMAGE_CACHE_NAME:kubernetes-v$KUBE-$ARCH#" >"Kubefile.$(uname)" -mv -fv "Kubefile.$(uname)" Kubefile +if grep k3s <<<"$KUBE"; then + case $ARCH in + amd64) + readonly K3S_DL="https://github.com/k3s-io/k3s/releases/download/v$KUBE/k3s" + ;; + arm64) + readonly K3S_DL="https://github.com/k3s-io/k3s/releases/download/v$KUBE/k3s-$ARCH" + ;; + esac + curl -fsSLo bin/k3s "$K3S_DL" + chmod a+x bin/k3s + curl -fsSL "https://github.com/k3s-io/k3s/releases/download/v$KUBE/k3s-images.txt" | sed "/pause:/d" >images/shim/DefaultImageList + echo "$pauseImage" >>images/shim/DefaultImageList +else + sed -E "s#^FROM .+#FROM $IMAGE_CACHE_NAME:kubernetes-v${KUBE%+*}-$ARCH#" Kubefile >"Kubefile.$(uname)" + mv -fv "Kubefile.$(uname)" Kubefile +fi #### building ### IMAGE_BUILD="$IMAGE_HUB_REGISTRY/$IMAGE_HUB_REPO/$IMAGE_KUBE:build-$(date +%s)" @@ -144,11 +162,12 @@ sudo sealos build $( cat <".versions/$K8S_MD.cached" head -n 1 ".versions/$K8S_MD.cached" >".versions/$K8S_MD.latest" + case $KUBE_TYPE in + k3s) + git ls-remote --refs --sort="-version:refname" --tags "https://github.com/k3s-io/k3s.git" | cut -d/ -f3- | grep -E "^$(cat ".versions/$K8S_MD.latest")\+k3s[0-9]$" >".versions/$K8S_MD.cached" + cp ".versions/$K8S_MD.cached" ".versions/$K8S_MD.latest" + ;; + esac cat ".versions/$K8S_MD.cached" ) [[ -s ".versions/$K8S_MD" ]] || cp ".versions/$K8S_MD.latest" ".versions/$K8S_MD" diff --git a/.github/scripts/versions/versions_arch.sh b/.github/scripts/versions/versions_arch.sh index 922111b..43b2100 100755 --- a/.github/scripts/versions/versions_arch.sh +++ b/.github/scripts/versions/versions_arch.sh @@ -3,6 +3,7 @@ set -e readonly CRI_TYPE=${criType?} +readonly KUBE_TYPE=${kubeType:-k8s} readonly IMAGE_HUB_REGISTRY=${registry:-} readonly IMAGE_HUB_REPO=${repo?} @@ -66,6 +67,12 @@ for file in $(pwd)/.github/versions/${part:-*}/CHANGELOG*; do until curl -sL "https://github.com/kubernetes/kubernetes/raw/master/CHANGELOG/$K8S_MD"; do sleep 3; done | grep -E '^- \[v[0-9\.]+\]' | awk '{print $2}' | awk -F\[ '{print $2}' | awk -F\] '{print $1}' >".versions/$K8S_MD.cached" head -n 1 ".versions/$K8S_MD.cached" >".versions/$K8S_MD.latest" + case $KUBE_TYPE in + k3s) + git ls-remote --refs --sort="-version:refname" --tags "https://github.com/k3s-io/k3s.git" | cut -d/ -f3- | grep -E "^$(cat ".versions/$K8S_MD.latest")\+k3s[0-9]$" >".versions/$K8S_MD.cached" + cp ".versions/$K8S_MD.cached" ".versions/$K8S_MD.latest" + ;; + esac cat ".versions/$K8S_MD.cached" ) [[ -s ".versions/$K8S_MD" ]] || cp ".versions/$K8S_MD.latest" ".versions/$K8S_MD" diff --git a/.github/workflows/autobuild-k3s-containerd-part3.yml b/.github/workflows/autobuild-k3s-containerd-part3.yml new file mode 100644 index 0000000..7f7d687 --- /dev/null +++ b/.github/workflows/autobuild-k3s-containerd-part3.yml @@ -0,0 +1,127 @@ +name: containerd for k3s 1.24-25 +on: + workflow_dispatch: + inputs: + sealosPatch: + description: 'sealos patch image for development.' + required: true + default: ghcr.io/labring/sealos-patch:latest + issue_comment: + types: + - created +env: + part: 3 + allBuild: true + registry: ${{ vars.D_REGISTRY_NAME }} + repo: ${{ vars.D_REGISTRY_REPOSITORY }} + sealosPatch: ${{ github.event.inputs.sealosPatch }} + criType: containerd + kubeType: k3s +jobs: + resolve-issue-sealoslatest: + if: startswith(github.event.comment.body, '/kube') || startswith(github.event.comment.body, '/containerd') || startswith(github.event.comment.body, '/single_part3') || startswith(github.event.comment.body, '/single_containerd_part3') || contains(github.event.inputs.sealosPatch, 'sealos') + runs-on: ubuntu-20.04 + outputs: + sealoslatest: ${{ steps.set-sealoslatest.outputs.sealoslatest }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set sealos LatestVersion + id: set-sealoslatest + run: | + export commentbody="${{github.event.comment.body}}" + .github/scripts/versions/versions_sealos.sh + resolve-versions-arch: + runs-on: ubuntu-20.04 + needs: + - resolve-issue-sealoslatest + env: + sealoslatest: ${{ needs.resolve-issue-sealoslatest.outputs.sealoslatest }} + outputs: + matrix: ${{ steps.set-versions.outputs.matrix }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Resolve Versions + id: set-versions + run: .github/scripts/versions/versions_arch.sh + resolve-versions: + runs-on: ubuntu-20.04 + needs: + - resolve-issue-sealoslatest + env: + sealoslatest: ${{ needs.resolve-issue-sealoslatest.outputs.sealoslatest }} + outputs: + matrix: ${{ steps.set-versions.outputs.matrix }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Resolve Versions + id: set-versions + run: .github/scripts/versions/versions.sh + build-images: + name: building + needs: + - resolve-issue-sealoslatest + - resolve-versions-arch + runs-on: ubuntu-20.04 + env: + sealoslatest: ${{ needs.resolve-issue-sealoslatest.outputs.sealoslatest }} + strategy: + matrix: ${{ fromJson(needs.resolve-versions-arch.outputs.matrix) }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Download tools and sealos + run: .github/scripts/download.sh + + - name: Auto build image + env: + username: ${{ vars.D_REGISTRY_REPOSITORY }} + password: ${{ secrets.D_REGISTRY_TOKEN }} + arch: ${{ matrix.arch }} + kubeVersion: ${{ matrix.version }} + run: .github/scripts/kubernetes.sh + + build_manifest: + needs: + - resolve-issue-sealoslatest + - resolve-versions + - build-images + name: manifest + env: + sealoslatest: ${{ needs.resolve-issue-sealoslatest.outputs.sealoslatest }} + strategy: + matrix: ${{ fromJson(needs.resolve-versions.outputs.matrix) }} + runs-on: ubuntu-20.04 + permissions: + issues: write + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Download tools and sealos + run: .github/scripts/download.sh + - name: Manifest Image + env: + username: ${{ vars.D_REGISTRY_REPOSITORY }} + password: ${{ secrets.D_REGISTRY_TOKEN }} + version: ${{ matrix.version }}-${{ env.sealoslatest }} + run: .github/scripts/manifest.sh + add-tips: + if: contains(github.event.comment.body, 'imagebuild') + needs: + - build_manifest + name: Auto add tips + runs-on: ubuntu-20.04 + permissions: + issues: write + steps: + - name: Success Commit + uses: peter-evans/create-or-update-comment@v1 + with: + issue-number: ${{ github.event.issue.number }} + body: | + � says: Hooray! The action autobuild-k8s-containerd-part3 has been completed successfully. � + + See: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} diff --git a/.github/workflows/autobuild-k3s-containerd-part4.yml b/.github/workflows/autobuild-k3s-containerd-part4.yml new file mode 100644 index 0000000..43df2c0 --- /dev/null +++ b/.github/workflows/autobuild-k3s-containerd-part4.yml @@ -0,0 +1,128 @@ +name: containerd for k3s 1.26+ +on: + workflow_dispatch: + inputs: + sealosPatch: + description: 'sealos patch image for development.' + required: true + default: ghcr.io/labring/sealos-patch:latest + issue_comment: + types: + - created +env: + part: 4 + allBuild: true + registry: ${{ vars.D_REGISTRY_NAME }} + repo: ${{ vars.D_REGISTRY_REPOSITORY }} + sealosPatch: ${{ github.event.inputs.sealosPatch }} + criType: containerd + kubeType: k3s +jobs: + resolve-issue-sealoslatest: + if: startswith(github.event.comment.body, '/kube') || startswith(github.event.comment.body, '/containerd') || startswith(github.event.comment.body, '/single_part4') || startswith(github.event.comment.body, '/single_containerd_part4') || contains(github.event.inputs.sealosPatch, 'sealos') + runs-on: ubuntu-20.04 + outputs: + sealoslatest: ${{ steps.set-sealoslatest.outputs.sealoslatest }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set sealos LatestVersion + id: set-sealoslatest + run: | + export commentbody="${{github.event.comment.body}}" + .github/scripts/versions/versions_sealos.sh + resolve-versions-arch: + runs-on: ubuntu-20.04 + needs: + - resolve-issue-sealoslatest + env: + sealoslatest: ${{ needs.resolve-issue-sealoslatest.outputs.sealoslatest }} + outputs: + matrix: ${{ steps.set-versions.outputs.matrix }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Resolve Versions + id: set-versions + run: .github/scripts/versions/versions_arch.sh + resolve-versions: + runs-on: ubuntu-20.04 + needs: + - resolve-issue-sealoslatest + env: + sealoslatest: ${{ needs.resolve-issue-sealoslatest.outputs.sealoslatest }} + outputs: + matrix: ${{ steps.set-versions.outputs.matrix }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Resolve Versions + id: set-versions + run: .github/scripts/versions/versions.sh + build-images: + name: building + needs: + - resolve-issue-sealoslatest + - resolve-versions-arch + runs-on: ubuntu-20.04 + env: + sealoslatest: ${{ needs.resolve-issue-sealoslatest.outputs.sealoslatest }} + strategy: + matrix: ${{ fromJson(needs.resolve-versions-arch.outputs.matrix) }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Download tools and sealos + run: .github/scripts/download.sh + + - name: Auto build image + env: + username: ${{ vars.D_REGISTRY_REPOSITORY }} + password: ${{ secrets.D_REGISTRY_TOKEN }} + arch: ${{ matrix.arch }} + kubeVersion: ${{ matrix.version }} + run: .github/scripts/kubernetes.sh + + build_manifest: + needs: + - resolve-issue-sealoslatest + - resolve-versions + - build-images + name: manifest + env: + sealoslatest: ${{ needs.resolve-issue-sealoslatest.outputs.sealoslatest }} + strategy: + matrix: ${{ fromJson(needs.resolve-versions.outputs.matrix) }} + runs-on: ubuntu-20.04 + permissions: + issues: write + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Download tools and sealos + run: .github/scripts/download.sh + - name: Manifest Image + env: + username: ${{ vars.D_REGISTRY_REPOSITORY }} + password: ${{ secrets.D_REGISTRY_TOKEN }} + version: ${{ matrix.version }}-${{ env.sealoslatest }} + run: .github/scripts/manifest.sh + + add-tips: + if: contains(github.event.comment.body, 'imagebuild') + needs: + - build_manifest + name: Auto add tips + runs-on: ubuntu-20.04 + permissions: + issues: write + steps: + - name: Success Commit + uses: peter-evans/create-or-update-comment@v1 + with: + issue-number: ${{ github.event.issue.number }} + body: | + 🤖 says: Hooray! The action autobuild-k8s-containerd-part4 has been completed successfully. 🎉 + + See: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} diff --git a/containerd/Kubefile b/containerd/Kubefile index a4e78ac..c913b8e 100644 --- a/containerd/Kubefile +++ b/containerd/Kubefile @@ -14,7 +14,6 @@ ENV criData=/var/lib/containerd \ registryUsername=admin \ registryPassword=passw0rd \ disableApparmor=false \ - defaultVIP=10.103.97.2 \ SEALOS_SYS_CRI_ENDPOINT=/var/run/containerd/containerd.sock \ SEALOS_SYS_IMAGE_ENDPOINT=/var/run/image-cri-shim.sock COPY . . diff --git a/cri-o/Kubefile b/cri-o/Kubefile index b0ae84e..9208ad8 100644 --- a/cri-o/Kubefile +++ b/cri-o/Kubefile @@ -13,7 +13,6 @@ ENV criData=/var/lib/crio \ registryPort=5000 \ registryUsername=admin \ registryPassword=passw0rd \ - defaultVIP=10.103.97.2 \ SEALOS_SYS_CRI_ENDPOINT=/var/run/crio/crio.sock \ SEALOS_SYS_IMAGE_ENDPOINT=/var/run/image-cri-shim.sock COPY . . diff --git a/docker/Kubefile b/docker/Kubefile index 28c148e..ba004f8 100644 --- a/docker/Kubefile +++ b/docker/Kubefile @@ -14,7 +14,6 @@ ENV criData=/var/lib/docker \ registryPort=5000 \ registryUsername=admin \ registryPassword=passw0rd \ - defaultVIP=10.103.97.2 \ SEALOS_SYS_CRI_ENDPOINT=/var/run/cri-dockerd.sock \ SEALOS_SYS_IMAGE_ENDPOINT=/var/run/image-cri-shim.sock COPY . . diff --git a/k3s/Kubefile b/k3s/Kubefile index 7a634a4..e3f719b 100644 --- a/k3s/Kubefile +++ b/k3s/Kubefile @@ -10,19 +10,14 @@ LABEL init="init.sh" \ vip="\$defaultVIP" \ "apps.sealos.io/type"=rootfs \ "apps.sealos.io/version"=v1beta1 \ - "apps.sealos.io/distribution"=k3s \ - version=v1.27.4 + "apps.sealos.io/distribution"=k3s ENV registryData=/var/lib/registry \ registryConfig=/etc/registry \ registryDomain=sealos.hub \ registryPort=5000 \ registryUsername=admin \ registryPassword=passw0rd \ - defaultVIP=10.103.97.2 \ SEALOS_SYS_CRI_ENDPOINT=/run/k3s/containerd/containerd.sock \ SEALOS_SYS_IMAGE_ENDPOINT=/var/run/image-cri-shim.sock \ - SEALOS_SYS_RUN_MODE=master \ - sandboxImage=rancher/mirrored-pause:3.6 -COPY --from=docker.io/labring/kubernetes:v1.25.13 cri/registry cri/registry -COPY --from=ghcr.io/labring/sealos-patch:latest . . + SEALOS_SYS_RUN_MODE=master COPY . . diff --git a/k3s/images/shim/k3s b/k3s/images/shim/k3s deleted file mode 100644 index 9353679..0000000 --- a/k3s/images/shim/k3s +++ /dev/null @@ -1,8 +0,0 @@ -docker.io/rancher/klipper-helm:v0.8.0-build20230510 -docker.io/rancher/klipper-lb:v0.4.4 -docker.io/rancher/local-path-provisioner:v0.0.24 -docker.io/rancher/mirrored-coredns-coredns:1.10.1 -docker.io/rancher/mirrored-library-busybox:1.34.1 -docker.io/rancher/mirrored-library-traefik:2.9.10 -docker.io/rancher/mirrored-metrics-server:v0.6.3 -docker.io/rancher/mirrored-pause:3.6