Auto-update, Build & Release #416
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: Auto-update, Build & Release | |
| on: | |
| schedule: | |
| - cron: '0 6 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| update-build-release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: true | |
| # ─── 1. Fetch the latest k3s tag matching *-amd64 ─────────────────── | |
| - name: Get latest k3s tag | |
| id: k3s | |
| run: | | |
| latest=$(curl -s \ | |
| "https://registry.hub.docker.com/v2/repositories/rancher/k3s/tags?page_size=100" \ | |
| | jq -r '.results[].name' \ | |
| | grep -E 'amd64$' \ | |
| | grep -v 'rc' \ | |
| | sort -V \ | |
| | tail -n1) | |
| echo "latest=$latest" >> $GITHUB_OUTPUT | |
| # ─── 2. Fetch the latest CUDA tag matching *-base-ubuntu24.04 ─────── | |
| - name: Get latest CUDA tag | |
| id: cuda | |
| run: | | |
| latest=$(curl -s \ | |
| "https://registry.hub.docker.com/v2/repositories/nvidia/cuda/tags?page_size=100" \ | |
| | jq -r '.results[].name' \ | |
| | grep -E 'base-ubuntu24\.04$' \ | |
| | sort -V \ | |
| | tail -n1) | |
| echo "latest=$latest" >> $GITHUB_OUTPUT | |
| # ─── 3. Fetch the latest NVIDIA device plugin version ─────────────── | |
| - name: Get latest NVIDIA device plugin version | |
| id: nvidia_plugin | |
| run: | | |
| latest=$(curl -s \ | |
| "https://api.github.com/repos/NVIDIA/k8s-device-plugin/releases/latest" \ | |
| | jq -r '.tag_name') | |
| echo "latest=$latest" >> $GITHUB_OUTPUT | |
| - name: Read current ARGs | |
| id: current | |
| run: | | |
| ct=$(grep '^ARG CUDA_TAG' Dockerfile | cut -d= -f2 | tr -d '"') | |
| kt=$(grep '^ARG K3S_TAG' Dockerfile | cut -d= -f2 | tr -d '"') | |
| echo "cuda=$ct" >> $GITHUB_OUTPUT | |
| echo "k3s=$kt" >> $GITHUB_OUTPUT | |
| - name: Determine if update is needed | |
| id: need | |
| run: | | |
| if [[ "${{ steps.cuda.outputs.latest }}" != "${{ steps.current.outputs.cuda }}" ]] || \ | |
| [[ "${{ steps.k3s.outputs.latest }}" != "${{ steps.current.outputs.k3s }}" ]]; then | |
| echo "update=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "update=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Abort if nothing to do | |
| if: steps.need.outputs.update == 'false' | |
| run: exit 0 | |
| - name: Bump Dockerfile ARGs | |
| if: steps.need.outputs.update == 'true' | |
| run: | | |
| sed -i \ | |
| -e "s|^ARG CUDA_TAG=.*|ARG CUDA_TAG=\"${{ steps.cuda.outputs.latest }}\"|" \ | |
| -e "s|^ARG K3S_TAG=.*|ARG K3S_TAG=\"${{ steps.k3s.outputs.latest }}\"|" \ | |
| Dockerfile | |
| - name: Update README | |
| if: steps.need.outputs.update == 'true' | |
| run: | | |
| today=$(date -u +'%Y-%m-%d') | |
| entry="| $today | ${{ steps.cuda.outputs.latest }} | ${{ steps.k3s.outputs.latest }} |" | |
| awk -v e="$entry" \ | |
| -v k3s="${{ steps.k3s.outputs.latest }}" \ | |
| -v cuda="${{ steps.cuda.outputs.latest }}" \ | |
| -v nvidia_plugin="${{ steps.nvidia_plugin.outputs.latest }}" ' | |
| /^\|----------/ { print; print e; next } | |
| /^\| `K3S_TAG`/ { sub(/`v[0-9][^`]*-amd64`/, "`" k3s "`"); print; next } | |
| /^\| `CUDA_TAG`/ { sub(/`[0-9][^`]*-base-ubuntu[0-9.]*`/, "`" cuda "`"); print; next } | |
| /kubectl apply -f https:\/\/raw\.githubusercontent\.com\/NVIDIA\/k8s-device-plugin\// { | |
| sub(/v[0-9]+\.[0-9]+\.[0-9]+/, nvidia_plugin); print; next | |
| } | |
| { print } | |
| ' README.md > README.md.new && mv README.md.new README.md | |
| - name: Commit & push version bump | |
| if: steps.need.outputs.update == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Dockerfile README.md | |
| git commit -m "chore: bump CUDA→${{ steps.cuda.outputs.latest }} & K3s→${{ steps.k3s.outputs.latest }}" | |
| git push origin HEAD:main | |
| - name: Prepare build tags | |
| if: steps.need.outputs.update == 'true' | |
| run: | | |
| echo "CUDA_TAG=${{ steps.cuda.outputs.latest }}" >> $GITHUB_ENV | |
| echo "K3S_TAG=${{ steps.k3s.outputs.latest }}" >> $GITHUB_ENV | |
| - name: Set up QEMU | |
| if: steps.need.outputs.update == 'true' | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| if: steps.need.outputs.update == 'true' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| if: steps.need.outputs.update == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| if: steps.need.outputs.update == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push image to DockerHub and GHCR | |
| if: steps.need.outputs.update == 'true' | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64 | |
| tags: | | |
| cryptoandcoffee/k3d-gpu:${{ env.CUDA_TAG }}-${{ env.K3S_TAG }} | |
| cryptoandcoffee/k3d-gpu:latest | |
| ghcr.io/${{ github.repository_owner }}/k3d-gpu:${{ env.CUDA_TAG }}-${{ env.K3S_TAG }} | |
| ghcr.io/${{ github.repository_owner }}/k3d-gpu:latest | |
| - name: Create GitHub Release | |
| if: steps.need.outputs.update == 'true' | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.cuda.outputs.latest }}-${{ steps.k3s.outputs.latest }} | |
| release_name: k3d-gpu-${{ steps.cuda.outputs.latest }}-${{ steps.k3s.outputs.latest }} | |
| body: | | |
| ## 🚀 New k3d-gpu Release | |
| **Docker Hub** | |
| - `cryptoandcoffee/k3d-gpu:${{ steps.cuda.outputs.latest }}-${{ steps.k3s.outputs.latest }}` | |
| - `cryptoandcoffee/k3d-gpu:latest` | |
| **GitHub Container Registry (GHCR)** | |
| - `ghcr.io/${{ github.repository_owner }}/k3d-gpu:${{ steps.cuda.outputs.latest }}-${{ steps.k3s.outputs.latest }}` | |
| - `ghcr.io/${{ github.repository_owner }}/k3d-gpu:latest` | |