diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index a8f25b8..020e184 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -44,27 +44,31 @@ jobs: with: dry_run: true build_docker: - runs-on: ubuntu-latest + name: build_docker (${{ matrix.arch }}) + # Build each arch on its native runner. QEMU-emulated arm64 SIGILLs on + # Deno/V8 during `prisma generate`, so emulation is avoided entirely. + # Validation only (no push), so forks and same-repo PRs behave identically. + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + runner: ubuntu-latest + arch: amd64 + - platform: linux/arm64 + runner: ubuntu-24.04-arm + arch: arm64 + runs-on: ${{ matrix.runner }} permissions: contents: read - packages: write steps: - uses: actions/checkout@v7 - # Fork PRs get a read-only GITHUB_TOKEN and no secrets, so only same-repo - # PRs can log in and push. Forks just build (validates the Dockerfile). - - uses: docker/login-action@v4 - if: github.event.pull_request.head.repo.full_name == github.repository - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.github_token }} - - uses: docker/setup-qemu-action@v4 - uses: docker/setup-buildx-action@v4 - - name: build and push + - name: build uses: docker/build-push-action@v7 with: - tags: ghcr.io/cbackas/tvbot:pr-${{github.event.pull_request.number}} - platforms: linux/amd64,linux/arm64 - cache-from: type=gha - cache-to: ${{ github.event.pull_request.head.repo.full_name == github.repository && 'type=gha,mode=max' || '' }} - push: ${{ github.event.pull_request.head.repo.full_name == github.repository }} + platforms: ${{ matrix.platform }} + cache-from: type=gha,scope=pr-${{ matrix.arch }} + # Fork PRs can't write the Actions cache; only export it for same-repo PRs. + cache-to: ${{ github.event.pull_request.head.repo.full_name == github.repository && format('type=gha,mode=max,scope=pr-{0}', matrix.arch) || '' }} + push: false diff --git a/.github/workflows/tags.yml b/.github/workflows/tags.yml index df4f150..074dc3b 100644 --- a/.github/workflows/tags.yml +++ b/.github/workflows/tags.yml @@ -5,8 +5,21 @@ on: tags: - '*.*.*' jobs: - build_and_push: - runs-on: ubuntu-latest + build: + name: build (${{ matrix.arch }}) + # Build each arch on its native runner (no QEMU) and push by digest. + # The merge job stitches the per-arch digests into one multi-arch manifest. + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + runner: ubuntu-latest + arch: amd64 + - platform: linux/arm64 + runner: ubuntu-24.04-arm + arch: arm64 + runs-on: ${{ matrix.runner }} permissions: contents: read packages: write @@ -15,27 +28,69 @@ jobs: - uses: docker/metadata-action@v6 id: meta with: - images: | - ghcr.io/cbackas/tvbot + images: ghcr.io/cbackas/tvbot - uses: docker/login-action@v4 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.github_token }} - - uses: docker/setup-qemu-action@v4 - uses: docker/setup-buildx-action@v4 - - name: build and push + - name: Build and push by digest + id: build uses: docker/build-push-action@v7 with: - tags: ${{ steps.meta.outputs.tags }} + platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64,linux/arm64 - cache-from: type=gha - cache-to: type=gha,mode=max - push: true + cache-from: type=gha,scope=${{ matrix.arch }} + cache-to: type=gha,mode=max,scope=${{ matrix.arch }} + outputs: type=image,name=ghcr.io/cbackas/tvbot,push-by-digest=true,name-canonical=true,push=true + - name: Export digest + run: | + mkdir -p "${{ runner.temp }}/digests" + digest="${{ steps.build.outputs.digest }}" + touch "${{ runner.temp }}/digests/${digest#sha256:}" + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ matrix.arch }} + path: ${{ runner.temp }}/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: build + permissions: + contents: read + packages: write + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: ${{ runner.temp }}/digests + pattern: digests-* + merge-multiple: true + - uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.github_token }} + - uses: docker/setup-buildx-action@v4 + - uses: docker/metadata-action@v6 + id: meta + with: + images: ghcr.io/cbackas/tvbot + - name: Create manifest list and push + working-directory: ${{ runner.temp }}/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf 'ghcr.io/cbackas/tvbot@sha256:%s ' *) + - name: Inspect image + run: | + docker buildx imagetools inspect ghcr.io/cbackas/tvbot:${{ steps.meta.outputs.version }} deploy: - needs: build_and_push + needs: merge permissions: contents: read uses: ./.github/workflows/fly-deploy.yml