diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 613036f..c676719 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -3,10 +3,10 @@ name: Docker on: push: branches: ["master"] - # Publish semver tags as releases. - tags: ["v*.*.*"] pull_request: branches: ["master"] + release: + types: [published] env: REGISTRY: ghcr.io @@ -14,6 +14,50 @@ env: jobs: build: + # Build only for pushes/PRs, never for release + if: github.event_name != 'release' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Set up QEMU for multi-arch builds + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract Docker metadata (non-release) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + + - name: Build Docker image (no push) + id: build + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: false + load: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + release: + # Only run when a GitHub Release is published + if: github.event_name == 'release' runs-on: ubuntu-latest permissions: contents: read @@ -25,7 +69,6 @@ jobs: uses: actions/checkout@v4 - name: Install cosign - if: github.event_name != 'pull_request' uses: sigstore/cosign-installer@v3.5.0 with: cosign-release: "v2.2.4" @@ -38,24 +81,22 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract Docker metadata + - name: Extract Docker metadata (release) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=ref,event=branch - type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - type=raw,value=latest,enable={{is_default_branch}} + type=semver,pattern={{major}} + type=raw,value=latest - name: Build and push Docker image id: build-and-push @@ -63,14 +104,13 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} + push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max - name: Sign the published Docker image - if: ${{ github.event_name != 'pull_request' }} env: TAGS: ${{ steps.meta.outputs.tags }} DIGEST: ${{ steps.build-and-push.outputs.digest }}