From e39e3185b91355c8f3377112fc19f4a32d88814b Mon Sep 17 00:00:00 2001 From: shenlan Date: Sat, 13 Sep 2025 15:12:01 +0800 Subject: [PATCH] feat: resolve latest sealos version --- .../build-sealos-offline-installer.yml | 104 --------- .../offline-package-sealos-installer.yaml | 200 ++++++++++++++++++ scripts/resolve_sealos_versions.sh | 32 +++ 3 files changed, 232 insertions(+), 104 deletions(-) delete mode 100644 .github/workflows/build-sealos-offline-installer.yml create mode 100644 .github/workflows/offline-package-sealos-installer.yaml create mode 100755 scripts/resolve_sealos_versions.sh diff --git a/.github/workflows/build-sealos-offline-installer.yml b/.github/workflows/build-sealos-offline-installer.yml deleted file mode 100644 index c8b3231..0000000 --- a/.github/workflows/build-sealos-offline-installer.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: Build Sealos Offline Installer - -on: - push: - paths: - - 'scripts/create-sealos-offline-package.sh' - - 'scripts/sealos-install.sh' - - 'scripts/cilium-values.yaml' - - '.github/workflows/build-sealos-offline-installer.yml' - workflow_dispatch: - -jobs: - build-sealos-installer: - strategy: - matrix: - arch: [amd64, arm64] - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Run Offline Package Builder - run: | - chmod +x scripts/create-sealos-offline-package.sh - ARCH=${{ matrix.arch }} ./scripts/create-sealos-offline-package.sh - - - name: Upload Artifact - uses: actions/upload-artifact@v4 - with: - name: sealos-offline-package-${{ matrix.arch }} - path: sealos-offline-package-${{ matrix.arch }}.tar.gz - - test-sealos-installer: - needs: build-sealos-installer - strategy: - matrix: - arch: [amd64] - runs-on: ubuntu-latest - - steps: - - name: Download Artifact - uses: actions/download-artifact@v4 - with: - name: sealos-offline-package-${{ matrix.arch }} - path: ./test-dir - - - name: Extract Package - run: | - cd test-dir - tar -xzvf sealos-offline-package-${{ matrix.arch }}.tar.gz - - - name: Verify Package Contents - run: | - test -f test-dir/sealos-offline-package/sealos-install.sh - test -f test-dir/sealos-offline-package/cilium-values.yaml - - publish-release: - needs: test-sealos-installer - runs-on: ubuntu-latest - env: - tag_name: offline-sealos-${{ github.run_number }} - - steps: - - uses: actions/checkout@v4 - - - name: Create GitHub Release - id: create_release - uses: actions/create-release@v1 - with: - tag_name: ${{ env.tag_name }} - release_name: Daily Build ${{ env.tag_name }} - draft: false - prerelease: false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Download amd64 Artifact - uses: actions/download-artifact@v4 - with: - name: sealos-offline-package-amd64 - path: release-artifacts - - - name: Download arm64 Artifact - uses: actions/download-artifact@v4 - with: - name: sealos-offline-package-arm64 - path: release-artifacts - - - name: Upload to GitHub Release - uses: softprops/action-gh-release@v1 - with: - tag_name: ${{ env.tag_name }} - files: | - release-artifacts/sealos-offline-package-amd64.tar.gz - release-artifacts/sealos-offline-package-arm64.tar.gz - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/offline-package-sealos-installer.yaml b/.github/workflows/offline-package-sealos-installer.yaml new file mode 100644 index 0000000..aa6d16b --- /dev/null +++ b/.github/workflows/offline-package-sealos-installer.yaml @@ -0,0 +1,200 @@ +name: Build Offline Sealos Installer + +on: + push: + paths: + - 'scripts/create-sealos-offline-package.sh' + - 'scripts/sealos-install.sh' + - 'scripts/cilium-values.yaml' + - 'scripts/resolve_sealos_versions.sh' + - '.github/workflows/offline-package-sealos-installer.yaml' + workflow_dispatch: + inputs: + tag: + description: "Release tag to use/sync (e.g., v5.0.3). Leave empty to use offline-sealos-" + required: false + type: string + sealos_version: + description: "Override Sealos version (e.g., 5.0.3). Leave empty to auto-resolve" + required: false + type: string + +permissions: + contents: write + +concurrency: + group: build-offline-sealos + cancel-in-progress: false + +jobs: + build-offline-installer: + strategy: + matrix: + arch: [amd64, arm64] + runs-on: ubuntu-latest + outputs: + sealos_version: ${{ steps.resolve.outputs.sealos_version }} + artifact-name: ${{ steps.upload-artifact.outputs.artifact-name }} + steps: + - uses: actions/checkout@v4 + + - name: Install deps (curl, jq) + run: | + set -euo pipefail + sudo apt-get update -y + sudo apt-get install -y curl jq + + - name: Resolve latest Sealos version + id: resolve + env: + OVERRIDE_SEALOS_VERSION: ${{ github.event.inputs.sealos_version }} + run: | + set -euo pipefail + bash scripts/resolve_sealos_versions.sh + + - name: Run Offline Package Builder + env: + SEALOS_VERSION: ${{ steps.resolve.outputs.sealos_version }} + run: | + set -euo pipefail + chmod +x scripts/create-sealos-offline-package.sh + ARCH=${{ matrix.arch }} ./scripts/create-sealos-offline-package.sh + + - name: Upload Artifact + id: upload-artifact + uses: actions/upload-artifact@v4 + with: + name: sealos-offline-package-${{ matrix.arch }} + path: sealos-offline-package-${{ matrix.arch }}.tar.gz + + test-offline-installer: + needs: build-offline-installer + strategy: + matrix: + arch: [amd64] + runs-on: ubuntu-latest + steps: + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: sealos-offline-package-${{ matrix.arch }} + path: ./test-dir + + - name: Extract Package + run: | + set -euo pipefail + cd test-dir + tar -xzvf sealos-offline-package-${{ matrix.arch }}.tar.gz + + - name: Verify Package Contents + run: | + set -euo pipefail + test -f test-dir/sealos-offline-package/sealos-install.sh + test -f test-dir/sealos-offline-package/cilium-values.yaml + + publish-release: + needs: test-offline-installer + runs-on: ubuntu-latest + env: + TAG_NAME: ${{ github.event.inputs.tag != '' && github.event.inputs.tag || format('offline-sealos-{0}', github.run_number) }} + RSYNC_SSH_KEY: ${{ secrets.RSYNC_SSH_KEY }} + RSYNC_SSH_USER: ${{ secrets.RSYNC_SSH_USER }} + VPS_HOST: ${{ secrets.VPS_HOST }} + REMOTE_ROOT: /data/update-server/sealos + steps: + - uses: actions/checkout@v4 + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + with: + tag_name: ${{ env.TAG_NAME }} + release_name: Build ${{ env.TAG_NAME }} + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Download amd64 artifact + uses: actions/download-artifact@v4 + with: + name: sealos-offline-package-amd64 + path: release-artifacts + + - name: Download arm64 artifact + uses: actions/download-artifact@v4 + with: + name: sealos-offline-package-arm64 + path: release-artifacts + + - name: Upload offline installers to GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ env.TAG_NAME }} + files: | + release-artifacts/sealos-offline-package-amd64.tar.gz + release-artifacts/sealos-offline-package-arm64.tar.gz + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Ensure deps (rsync, ssh) + run: | + set -euo pipefail + sudo apt-get update -y + sudo apt-get install -y rsync openssh-client + + - name: Init SSH + run: | + set -euo pipefail + mkdir -p ~/.ssh + echo "$RSYNC_SSH_KEY" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts + + - name: Rsync release assets to remote + run: | + set -euo pipefail + REMOTE_DIR="${REMOTE_ROOT}/${TAG_NAME}" + ssh -i ~/.ssh/id_rsa "${RSYNC_SSH_USER}@${VPS_HOST}" "mkdir -p '${REMOTE_DIR}'" + echo "Rsync -> ${VPS_HOST}:${REMOTE_DIR}/" + rsync -av -e "ssh -i ~/.ssh/id_rsa" \ + release-artifacts/sealos-offline-package-amd64.tar.gz \ + release-artifacts/sealos-offline-package-arm64.tar.gz \ + "${RSYNC_SSH_USER}@${VPS_HOST}:${REMOTE_DIR}/" + + retention: + name: Remote retention (keep latest 3) + needs: publish-release + runs-on: ubuntu-latest + env: + RSYNC_SSH_KEY: ${{ secrets.RSYNC_SSH_KEY }} + RSYNC_SSH_USER: ${{ secrets.RSYNC_SSH_USER }} + VPS_HOST: ${{ secrets.VPS_HOST }} + REMOTE_ROOT: /data/update-server/sealos + steps: + - name: Init SSH + run: | + set -euo pipefail + mkdir -p ~/.ssh + echo "$RSYNC_SSH_KEY" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts + + - name: Prune old versions on remote (keep 3) + run: | + set -euo pipefail + ssh -i ~/.ssh/id_rsa "${RSYNC_SSH_USER}@${VPS_HOST}" bash -lc ' + set -euo pipefail + cd "'"${REMOTE_ROOT}"'" || exit 0 + keep=3 + mapfile -t all < <(ls -1 | grep -E "^(offline-sealos-|v[0-9]+\.)" | sort -V -r || true) + if [ "${#all[@]}" -le "$keep" ]; then + echo "Nothing to prune. Count=${#all[@]}" + exit 0 + fi + to_delete=("${all[@]:keep}") + echo "Pruning old versions: ${to_delete[*]}" + for d in "${to_delete[@]}"; do + rm -rf -- "$d" + done + ' diff --git a/scripts/resolve_sealos_versions.sh b/scripts/resolve_sealos_versions.sh new file mode 100755 index 0000000..e0c5250 --- /dev/null +++ b/scripts/resolve_sealos_versions.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# scripts/resolve_sealos_versions.sh +# 输出:写入 $GITHUB_OUTPUT -> sealos_version +# 环境变量: +# OVERRIDE_SEALOS_VERSION 可选,手工指定 Sealos 版本(如 5.0.3) + +set -euo pipefail + +OVERRIDE_SEALOS_VERSION="${OVERRIDE_SEALOS_VERSION:-}" + +resolve_version() { + if [[ -n "${OVERRIDE_SEALOS_VERSION}" ]]; then + echo "${OVERRIDE_SEALOS_VERSION}" + return + fi + + latest="$(curl -fsSL https://api.github.com/repos/labring/sealos/releases/latest | jq -r '.tag_name')" + latest="${latest#v}" + + if [[ -z "${latest}" ]]; then + echo "Failed to resolve latest Sealos version" >&2 + exit 1 + fi + echo "${latest}" +} + +SEALOS_VERSION="$(resolve_version)" +{ + echo "sealos_version=${SEALOS_VERSION}" +} >> "${GITHUB_OUTPUT}" + +echo "Resolved => Sealos ${SEALOS_VERSION}"