|
| 1 | +name: Docker |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["master"] |
| 6 | + # Publish semver tags as releases. |
| 7 | + tags: ["v*.*.*"] |
| 8 | + |
| 9 | +env: |
| 10 | + REGISTRY: ghcr.io |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + packages: write |
| 19 | + id-token: write |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + # Set up BuildKit Docker container builder to be able to build |
| 26 | + # multi-platform images and export cache |
| 27 | + # https://github.com/docker/setup-buildx-action |
| 28 | + - name: Set up Docker Buildx |
| 29 | + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 |
| 30 | + |
| 31 | + # Login against a Docker registry except on PR |
| 32 | + # https://github.com/docker/login-action |
| 33 | + - name: Log into registry ${{ env.REGISTRY }} |
| 34 | + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 |
| 35 | + with: |
| 36 | + registry: ${{ env.REGISTRY }} |
| 37 | + username: ${{ github.actor }} |
| 38 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + |
| 40 | + # Extract metadata (tags, labels) for Docker |
| 41 | + # https://github.com/docker/metadata-action |
| 42 | + - name: Extract Docker metadata |
| 43 | + id: meta |
| 44 | + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 |
| 45 | + with: |
| 46 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 47 | + |
| 48 | + # Build and push Docker image with Buildx (don't push on PR) |
| 49 | + # https://github.com/docker/build-push-action |
| 50 | + - name: Build and push Docker image |
| 51 | + id: build-and-push |
| 52 | + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 |
| 53 | + with: |
| 54 | + context: . |
| 55 | + push: ${{ github.event_name != 'pull_request' }} |
| 56 | + tags: ${{ steps.meta.outputs.tags }} |
| 57 | + labels: ${{ steps.meta.outputs.labels }} |
| 58 | + cache-from: type=gha |
| 59 | + cache-to: type=gha,mode=max |
0 commit comments