First commit :) #3
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
| # GitHub Actions Workflow for building and publishing Docker images | |
| # to GitHub Container Registry (ghcr.io) | |
| # | |
| # Triggers: | |
| # - Push to main/master branch -> :latest tag | |
| # - Push of version tag (v*.*.*) -> version tag (e.g., :v1.0.0) | |
| # - Pull requests -> build only (no push) | |
| name: Docker Build & Publish | |
| on: | |
| push: | |
| branches: | |
| - master | |
| tags: | |
| - 'v*.*.*' | |
| pull_request: | |
| branches: | |
| - master | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container 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 metadata (tags, labels) | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| # Set :latest tag for default branch | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| # Set version tag for version tags (v1.0.0 -> 1.0.0) | |
| type=semver,pattern={{version}} | |
| # Set major.minor tag (v1.0.0 -> 1.0) | |
| type=semver,pattern={{major}}.{{minor}} | |
| # Set SHA tag for traceability | |
| type=sha,prefix= | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |