Auto-update, Build & Release #82
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@v3 | |
| 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 "::set-output name=latest::$latest" | |
| # ─── 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 "::set-output name=latest::$latest" | |
| - 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 "::set-output name=cuda::$ct" | |
| echo "::set-output name=k3s::$kt" | |
| - 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 "::set-output name=update::true" | |
| else | |
| echo "::set-output name=update::false" | |
| 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: Append to README Release History | |
| 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" ' | |
| /^## Release History/ { print; getline; print; print e; 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@v2 | |
| - name: Set up Docker Buildx | |
| if: steps.need.outputs.update == 'true' | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to DockerHub | |
| if: steps.need.outputs.update == 'true' | |
| uses: docker/login-action@v2 | |
| 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@v2 | |
| 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@v4 | |
| 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: actions/create-release@v1 | |
| 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` | |