🏗️ Build or Update Gentoo Docker Image #11
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
| # SPDX-FileCopyrightText: Copyright 2025 Florian Albrechtskirchinger <[email protected]> | |
| # | |
| # SPDX-License-Identifier: MIT | |
| name: 🏗️ Build or Update Gentoo Docker Image | |
| on: | |
| schedule: | |
| - cron: '33 3 * * 1' | |
| workflow_dispatch: | |
| inputs: | |
| force_rebuild: | |
| description: 'Force a rebuild from gentoo/stage3 instead of updating :latest' | |
| required: false | |
| type: boolean | |
| default: false | |
| jobs: | |
| prepare-build: | |
| name: Prepare Build | |
| runs-on: ubuntu-latest | |
| outputs: | |
| build_type: ${{ steps.check_image.outputs.build_type }} | |
| date_tag: ${{ steps.meta.outputs.version }} | |
| steps: | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Date Tag | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: type=raw,value={{date 'YYYYMMDD-HHmmss'}} | |
| - name: Check for existing image | |
| id: check_image | |
| run: | | |
| # Force rebuild once every quarter | |
| month=$(date +%-m) | |
| quarter=$(( (($month - 1) / 3) + 1 )) | |
| day=$(date +%-d) | |
| if (( day <= 7 && ((month - 1) % 3 == 0) )); then | |
| echo "It's the first run of Q$quarter; forcing rebuild." | |
| echo "build_type=initial" >> $GITHUB_OUTPUT | |
| exit | |
| fi | |
| if [[ "${{ github.event.inputs.force_rebuild }}" == "true" ]]; then | |
| echo "Force rebuild requested." | |
| echo "build_type=initial" >> $GITHUB_OUTPUT | |
| elif docker manifest inspect ghcr.io/${{ github.repository }}:latest >/dev/null 2>&1; then | |
| echo "Image exists. Performing an update." | |
| echo "build_type=update" >> $GITHUB_OUTPUT | |
| else | |
| echo "Image does not exist. Performing initial build." | |
| echo "build_type=initial" >> $GITHUB_OUTPUT | |
| fi | |
| run-initial-build: | |
| name: Run Initial Build | |
| needs: prepare-build | |
| if: needs.prepare-build.outputs.build_type == 'initial' | |
| uses: ./.github/workflows/gentoo-image-base.yml | |
| with: | |
| date_tag: ${{ needs.prepare-build.outputs.date_tag }} | |
| permissions: | |
| packages: write | |
| contents: read | |
| secrets: inherit | |
| run-update-build: | |
| name: Run Update Build | |
| needs: prepare-build | |
| if: needs.prepare-build.outputs.build_type == 'update' | |
| uses: ./.github/workflows/gentoo-image-update.yml | |
| with: | |
| date_tag: ${{ needs.prepare-build.outputs.date_tag }} | |
| permissions: | |
| packages: write | |
| contents: read | |
| secrets: inherit | |
| cleanup-ghcr: | |
| name: Clean up old image tags | |
| needs: [run-initial-build, run-update-build] | |
| if: always() | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: read | |
| steps: | |
| - name: Delete old container versions | |
| uses: actions/delete-package-versions@v5 | |
| with: | |
| package-name: ${{ github.event.repository.name }} | |
| package-type: 'container' | |
| min-versions-to-keep: 3 | |
| delete-tags: '*-step' |