|
| 1 | +name: Docker Image Builder |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + # Run once a week on Fridays |
| 7 | + - cron: "0 0 * * FRI" |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - ".github/workflows/docker-images.yml" |
| 11 | + push: |
| 12 | + branches: |
| 13 | + - main |
| 14 | + paths: |
| 15 | + - ".github/workflows/docker-images.yml" |
| 16 | + |
| 17 | +jobs: |
| 18 | + build: |
| 19 | + runs-on: ${{ matrix.IMAGE.RUNNER }} |
| 20 | + timeout-minutes: 10 |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + packages: write |
| 24 | + id-token: write |
| 25 | + attestations: write |
| 26 | + |
| 27 | + strategy: |
| 28 | + fail-fast: false |
| 29 | + matrix: |
| 30 | + IMAGE: |
| 31 | + - { |
| 32 | + TAG_NAME: "archlinux:latest", |
| 33 | + DOCKER_PLATFORM: "linux/loong64", |
| 34 | + DOCKERFILE_PATH: ".github/docker", |
| 35 | + RUNNER: "ubuntu-latest", |
| 36 | + } |
| 37 | + |
| 38 | + name: Build Archlinux docker image |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4.2.2 |
| 41 | + with: |
| 42 | + persist-credentials: false |
| 43 | + - name: Pull existing image |
| 44 | + run: docker pull ghcr.io/${{ github.repository_owner }}/${{ matrix.IMAGE.TAG_NAME }} || true |
| 45 | + if: github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' |
| 46 | + |
| 47 | + - name: Setup environment variables |
| 48 | + shell: bash |
| 49 | + id: image-name |
| 50 | + run: | |
| 51 | + IMAGE_NAME=$(echo "${{ matrix.IMAGE.TAG_NAME }}" | cut -d ':' -f 1) |
| 52 | + echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV |
| 53 | + - name: Setup QEMU |
| 54 | + uses: docker/setup-qemu-action@v3 |
| 55 | + - name: Set up Docker Buildx |
| 56 | + uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 |
| 57 | + with: |
| 58 | + cache-binary: false |
| 59 | + - name: Login to ghcr.io |
| 60 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 |
| 61 | + with: |
| 62 | + registry: ghcr.io |
| 63 | + username: ${{ github.actor }} |
| 64 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + if: (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' |
| 66 | + - name: Build docker image |
| 67 | + uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0 # v6.17.0 |
| 68 | + id: docker-build |
| 69 | + with: |
| 70 | + context: ${{ matrix.IMAGE.DOCKERFILE_PATH }} |
| 71 | + cache-from: ghcr.io/${{ github.repository_owner }}/${{ matrix.IMAGE.TAG_NAME }} |
| 72 | + tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.IMAGE.TAG_NAME }} |
| 73 | + platforms: ${{ matrix.IMAGE.DOCKER_PLATFORM }} |
| 74 | + pull: true |
| 75 | + push: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' }} |
| 76 | + - name: Attese |
| 77 | + uses: actions/attest-build-provenance@db473fddc028af60658334401dc6fa3ffd8669fd # v2.3.0 |
| 78 | + with: |
| 79 | + subject-name: "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}" |
| 80 | + subject-digest: ${{ steps.docker-build.outputs.digest }} |
| 81 | + push-to-registry: true |
| 82 | + if: (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' |
0 commit comments