build-sealos-cluster-image #853
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build-sealos-cluster-image | |
| on: | |
| # Triggered when dockerize-web, dockerize-server, or build-scripts-updated workflow completes on main branch | |
| workflow_run: | |
| workflows: ["dockerize-web", "dockerize-server", "dockerize-runtime-nodejs", "dockerize-runtime-exporter", "build-scripts-updated", "release"] | |
| types: [completed] | |
| branches: [main] | |
| # Manual trigger | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version tag for cluster image' | |
| required: false | |
| default: 'latest' | |
| permissions: | |
| packages: write | |
| contents: read | |
| env: | |
| GO_VERSION: "1.19" | |
| DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
| concurrency: | |
| group: build-sealos-cluster-image-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build_cluster_image: | |
| runs-on: ubuntu-latest | |
| # Only run if the triggering workflow succeeded (or manual trigger) | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Prepare | |
| id: prepare | |
| run: | | |
| IMAGE=laf | |
| # Use custom version for workflow_dispatch, otherwise 'latest' | |
| TAG=${{ github.event.inputs.version || 'latest' }} | |
| echo "tag=${TAG}" >> $GITHUB_ENV | |
| echo "image=${IMAGE}" >> $GITHUB_ENV | |
| echo "Building cluster image: ${IMAGE}:${TAG}" | |
| - name: Remove builtin docker | |
| run: | | |
| sudo apt-get remove -y moby-engine moby-cli moby-buildx moby-compose | |
| - name: Install sealos | |
| run: | | |
| echo "deb [trusted=yes] https://apt.fury.io/labring/ /" | sudo tee /etc/apt/sources.list.d/labring.list | |
| sudo apt update | |
| sudo apt install sealos=4.1.4 | |
| sudo sealos version | |
| - name: Install buildah | |
| run: | | |
| sudo apt remove buildah -y || true | |
| arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) | |
| echo "Downloading buildah from https://github.com/labring/cluster-image/releases/download/depend/buildah.linux.${arch}" | |
| sudo wget -qO "buildah" "https://github.com/labring/cluster-image/releases/download/depend/buildah.linux.${arch}" | |
| sudo chmod a+x buildah | |
| sudo mv buildah /usr/bin | |
| - name: Login GHCR.io | |
| run: | | |
| echo "Logging in to ghcr.io as ${{ github.repository_owner }}" | |
| sudo buildah login -u ${{ github.repository_owner }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io | |
| - name: Build cluster image | |
| env: | |
| IMAGE: ghcr.io/${{ github.repository_owner }}/${{ env.image }} | |
| VERSION: ${{ env.tag }} | |
| working-directory: build | |
| run: | | |
| echo "Building cluster image: $IMAGE:$VERSION" | |
| sudo sealos build -t $IMAGE:$VERSION-arm64 --platform linux/arm64 -f Kubefile . | |
| sudo rm -rf registry | |
| sudo sealos build -t $IMAGE:$VERSION-amd64 --platform linux/amd64 -f Kubefile . | |
| sudo sealos images | |
| - name: Push cluster image to ghcr.io | |
| env: | |
| IMAGE: ghcr.io/${{ github.repository_owner }}/${{ env.image }} | |
| VERSION: ${{ env.tag }} | |
| run: | | |
| sudo buildah images | |
| sudo buildah push $IMAGE:$VERSION-amd64 | |
| sudo buildah push $IMAGE:$VERSION-arm64 | |
| sudo buildah manifest create $IMAGE:$VERSION | |
| sudo buildah manifest add $IMAGE:$VERSION docker://$IMAGE:$VERSION-amd64 | |
| sudo buildah manifest add $IMAGE:$VERSION docker://$IMAGE:$VERSION-arm64 | |
| sudo buildah manifest push --all $IMAGE:$VERSION docker://$IMAGE:$VERSION | |
| - name: Push cluster image to docker.io | |
| if: ${{ env.DOCKERHUB_USERNAME != '' }} | |
| env: | |
| GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ env.image }} | |
| IMAGE: docker.io/${{ env.DOCKERHUB_USERNAME }}/${{ env.image }} | |
| VERSION: ${{ env.tag }} | |
| run: | | |
| sudo buildah login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} docker.io | |
| sudo buildah tag $GHCR_IMAGE:$VERSION-amd64 $IMAGE:$VERSION-amd64 | |
| sudo buildah tag $GHCR_IMAGE:$VERSION-arm64 $IMAGE:$VERSION-arm64 | |
| sudo buildah push $IMAGE:$VERSION-amd64 | |
| sudo buildah push $IMAGE:$VERSION-arm64 | |
| sudo buildah manifest create $IMAGE:$VERSION | |
| sudo buildah manifest add $IMAGE:$VERSION docker://$IMAGE:$VERSION-amd64 | |
| sudo buildah manifest add $IMAGE:$VERSION docker://$IMAGE:$VERSION-arm64 | |
| sudo buildah manifest push --all $IMAGE:$VERSION docker://$IMAGE:$VERSION | |
| - name: Renew issue and Sync Images | |
| uses: labring/[email protected] | |
| if: ${{ github.event_name != 'workflow_dispatch' }} | |
| with: | |
| version: v0.0.8-rc1 | |
| env: | |
| GH_TOKEN: "${{ secrets.GH_PAT }}" | |
| SEALOS_TYPE: "issue_renew" | |
| SEALOS_ISSUE_TITLE: "【DaylyReport】 Auto build for laf" | |
| SEALOS_ISSUE_BODYFILE: "build/README.md" | |
| SEALOS_ISSUE_LABEL: "dayly-report" | |
| SEALOS_ISSUE_TYPE: "day" | |
| SEALOS_ISSUE_REPO: "labring-actions/cluster-image" | |
| SEALOS_COMMENT_BODY: "/imagesync ghcr.io/${{ github.repository_owner }}/${{ env.image }}:${{ env.tag }}" |