Mirror of https://forge.levinkeller.de/levin/dorfarchiv.git
06c4ddf6b7fe1f632d16009afcaa58f59faa87e2
113 lines · 3.2 KB
| 1 | name: Build & Deploy |
| 2 | |
| 3 | # Variant B: Multi-Arch-Image auf NATIVEN Runnern bauen (amd64 + arm64), |
| 4 | # per-arch pushen, mit `docker buildx imagetools create` zu einem Manifest |
| 5 | # zusammenführen — niemals QEMU. Danach den Image-Tag im Production-Overlay |
| 6 | # bumpen und nach main committen ([skip ci]-Loop-Guard). Flux deployt. |
| 7 | |
| 8 | on: |
| 9 | push: |
| 10 | branches: [main] |
| 11 | paths-ignore: |
| 12 | - "deploy/**" |
| 13 | - "**/*.md" |
| 14 | workflow_dispatch: |
| 15 | |
| 16 | concurrency: |
| 17 | group: deploy-${{ github.ref }} |
| 18 | cancel-in-progress: false |
| 19 | |
| 20 | env: |
| 21 | IMAGE: ghcr.io/dorfpflege-roessing/dorfarchiv |
| 22 | |
| 23 | jobs: |
| 24 | # 1) Pro Architektur ein natives Image bauen und als per-arch Tag pushen. |
| 25 | build: |
| 26 | strategy: |
| 27 | fail-fast: true |
| 28 | matrix: |
| 29 | include: |
| 30 | - arch: amd64 |
| 31 | runner: ubuntu-latest |
| 32 | - arch: arm64 |
| 33 | runner: ubuntu-24.04-arm |
| 34 | runs-on: ${{ matrix.runner }} |
| 35 | permissions: |
| 36 | contents: read |
| 37 | packages: write |
| 38 | steps: |
| 39 | - uses: actions/checkout@v4 |
| 40 | |
| 41 | - name: Set up Docker Buildx |
| 42 | uses: docker/setup-buildx-action@v3 |
| 43 | |
| 44 | - name: Log in to GHCR |
| 45 | uses: docker/login-action@v3 |
| 46 | with: |
| 47 | registry: ghcr.io |
| 48 | username: ${{ github.actor }} |
| 49 | password: ${{ secrets.GITHUB_TOKEN }} |
| 50 | |
| 51 | - name: Build & push (${{ matrix.arch }}) |
| 52 | uses: docker/build-push-action@v6 |
| 53 | with: |
| 54 | context: . |
| 55 | platforms: linux/${{ matrix.arch }} |
| 56 | push: true |
| 57 | provenance: false |
| 58 | tags: ${{ env.IMAGE }}:${{ github.sha }}-${{ matrix.arch }} |
| 59 | cache-from: type=gha,scope=${{ matrix.arch }} |
| 60 | cache-to: type=gha,scope=${{ matrix.arch }},mode=max |
| 61 | |
| 62 | # 2) Per-arch Tags zu einem Multi-Arch-Manifest zusammenführen (kein QEMU). |
| 63 | merge: |
| 64 | needs: build |
| 65 | runs-on: ubuntu-latest |
| 66 | permissions: |
| 67 | contents: read |
| 68 | packages: write |
| 69 | steps: |
| 70 | - name: Log in to GHCR |
| 71 | uses: docker/login-action@v3 |
| 72 | with: |
| 73 | registry: ghcr.io |
| 74 | username: ${{ github.actor }} |
| 75 | password: ${{ secrets.GITHUB_TOKEN }} |
| 76 | |
| 77 | - name: Create multi-arch manifest |
| 78 | run: | |
| 79 | docker buildx imagetools create \ |
| 80 | --tag "${IMAGE}:${{ github.sha }}" \ |
| 81 | --tag "${IMAGE}:latest" \ |
| 82 | "${IMAGE}:${{ github.sha }}-amd64" \ |
| 83 | "${IMAGE}:${{ github.sha }}-arm64" |
| 84 | |
| 85 | # 3) Image-Tag im Production-Overlay bumpen und nach main committen. |
| 86 | bump: |
| 87 | needs: merge |
| 88 | runs-on: ubuntu-latest |
| 89 | permissions: |
| 90 | contents: write |
| 91 | steps: |
| 92 | - uses: actions/checkout@v4 |
| 93 | with: |
| 94 | ref: main |
| 95 | |
| 96 | - name: Install kustomize |
| 97 | uses: imranismail/setup-kustomize@v2 |
| 98 | |
| 99 | - name: Bump image tag in production overlay |
| 100 | working-directory: deploy/overlays/production |
| 101 | run: kustomize edit set image "${IMAGE}=${IMAGE}:${{ github.sha }}" |
| 102 | |
| 103 | - name: Commit & push bump |
| 104 | run: | |
| 105 | git config user.name "github-actions[bot]" |
| 106 | git config user.email "github-actions[bot]@users.noreply.github.com" |
| 107 | if git diff --quiet; then |
| 108 | echo "Kein Image-Bump nötig." |
| 109 | exit 0 |
| 110 | fi |
| 111 | git add deploy/overlays/production/kustomization.yaml |
| 112 | git commit -m "ci: deploy dorfarchiv ${{ github.sha }} [skip ci]" |
| 113 | git push |