Build & Publish 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
| name: Build & Publish Docker Image | |
| # ───────────────────────────────────────────────────────────── | |
| # Trigger: on version tags (v2.4.1, v2.5.0, etc.) | |
| # ───────────────────────────────────────────────────────────── | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [main, master] | |
| env: | |
| REGISTRY_GHCR: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| # ── Build only (PR / non-tag push) ───────────────────────── | |
| build-check: | |
| name: Docker Build Check | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build (no push) | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: false | |
| load: true | |
| tags: ${{ env.IMAGE_NAME }}:build-test | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Verify image exists | |
| run: docker image inspect ${{ env.IMAGE_NAME }}:build-test | |
| # ── Build + Push to GHCR (tagged release) ────────────────── | |
| release: | |
| name: Build & Push Release Image | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| needs: [] | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY_GHCR }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (GHCR) | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY_GHCR }}/${{ github.repository }} | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Build and Push to GHCR | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64,linux/arm64 | |
| - name: Verify GHCR image | |
| run: | | |
| TAG=$(echo ${{ steps.meta.outputs.tags }} | cut -d' ' -f1) | |
| echo "Checking $TAG" | |
| docker buildx imagetools inspect $TAG |