|
| 1 | +name: Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: ['v*'] |
| 7 | + pull_request: |
| 8 | + branches: [main] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +env: |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }}/synapse-website |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build & push image |
| 18 | + runs-on: ubuntu-latest |
| 19 | + # Skip on PRs from forks (no GHCR write access) and on this repo's PRs |
| 20 | + # where we still want to verify the build succeeds without pushing. |
| 21 | + if: github.event_name != 'pull_request' |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + packages: write |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Set up Docker Buildx |
| 30 | + uses: docker/setup-buildx-action@v3 |
| 31 | + |
| 32 | + - name: Log in to GHCR |
| 33 | + uses: docker/login-action@v3 |
| 34 | + with: |
| 35 | + registry: ghcr.io |
| 36 | + username: ${{ github.actor }} |
| 37 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + |
| 39 | + - name: Extract metadata |
| 40 | + id: meta |
| 41 | + uses: docker/metadata-action@v5 |
| 42 | + with: |
| 43 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 44 | + tags: | |
| 45 | + type=ref,event=branch |
| 46 | + type=ref,event=pr |
| 47 | + type=semver,pattern={{version}} |
| 48 | + type=semver,pattern={{major}}.{{minor}} |
| 49 | + type=sha,format=short |
| 50 | + type=raw,value=latest,enable={{is_default_branch}} |
| 51 | + bake-target: synapse-website |
| 52 | + flavor: | |
| 53 | + latest=auto |
| 54 | +
|
| 55 | + - name: Build (and push) |
| 56 | + uses: docker/bake-action@v5 |
| 57 | + with: |
| 58 | + source: website |
| 59 | + files: | |
| 60 | + website/docker-bake.hcl |
| 61 | + ${{ steps.meta.outputs.bake-file }} |
| 62 | + targets: synapse-website |
| 63 | + push: true |
| 64 | + tags: ${{ steps.meta.outputs.tags }} |
| 65 | + labels: ${{ steps.meta.outputs.labels }} |
| 66 | + cache-from: type=gha |
| 67 | + cache-to: type=gha,mode=max |
| 68 | + |
| 69 | + build-pr: |
| 70 | + name: Build (PR only) |
| 71 | + runs-on: ubuntu-latest |
| 72 | + if: github.event_name == 'pull_request' |
| 73 | + permissions: |
| 74 | + contents: read |
| 75 | + steps: |
| 76 | + - name: Checkout |
| 77 | + uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - name: Set up Docker Buildx |
| 80 | + uses: docker/setup-buildx-action@v3 |
| 81 | + |
| 82 | + - name: Build |
| 83 | + uses: docker/bake-action@v5 |
| 84 | + with: |
| 85 | + source: website |
| 86 | + files: | |
| 87 | + website/docker-bake.hcl |
| 88 | + targets: synapse-website |
| 89 | + push: false |
| 90 | + cache-from: type=gha |
0 commit comments