Initial commit #1
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 Docker image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - "v*.*.*" | |
| pull_request: | |
| branches: | |
| - main | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| # Optional repository variable: | |
| # CADDY_IMAGE=ghcr.io/ludero-git/caddy:2.10.2 | |
| # | |
| # Falls back to caddy:latest when the variable is not configured. | |
| CADDY_IMAGE: ${{ vars.CADDY_IMAGE || 'caddy:latest' }} | |
| jobs: | |
| docker: | |
| name: Build Docker image | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v7 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Log in to GHCR | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| # main branch -> latest | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| # Every build -> sha-a1b2c3d | |
| type=sha,prefix=sha- | |
| # v1.2.3 -> 1.2.3 | |
| type=semver,pattern={{version}} | |
| # v1.2.3 -> 1.2 | |
| type=semver,pattern={{major}}.{{minor}} | |
| # v1.2.3 -> 1 | |
| type=semver,pattern={{major}} | |
| - name: Build and push Docker image | |
| id: build | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| # PRs are built for validation but are not pushed. | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| # Pass the configurable Caddy image to Dockerfile. | |
| build-args: | | |
| CADDY_IMAGE=${{ env.CADDY_IMAGE }} | |
| # Make sure e.g. caddy:latest is refreshed. | |
| pull: true | |
| # GitHub Actions BuildKit cache. | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |