|
| 1 | +# Based on https://github.com/matrix-org/dendrite/blob/master/.github/workflows/docker-hub.yml |
| 2 | + |
| 3 | +name: "Docker" |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + paths-ignore: |
| 8 | + - changelog.d/**' |
| 9 | + pull_request: |
| 10 | + branches: [ main ] |
| 11 | + paths-ignore: |
| 12 | + - changelog.d/**' |
| 13 | + release: |
| 14 | + types: [published] |
| 15 | + |
| 16 | + merge_group: |
| 17 | + |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +env: |
| 24 | + DOCKER_NAMESPACE: halfshot |
| 25 | + PLATFORMS: linux/amd64 |
| 26 | + PLATFORMS_PUSH: linux/amd64,linux/arm64 |
| 27 | + # Only push if this is main, otherwise we just want to build |
| 28 | + BUILD_FOR_ALL_PLATFORMS: ${{ github.ref == 'refs/heads/main' }} |
| 29 | + |
| 30 | +jobs: |
| 31 | + docker-latest: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + |
| 34 | + permissions: |
| 35 | + contents: read |
| 36 | + packages: write |
| 37 | + attestations: write |
| 38 | + id-token: write |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@v4 |
| 43 | + - name: Set up QEMU |
| 44 | + uses: docker/setup-qemu-action@v3 |
| 45 | + - name: Set up Docker Buildx |
| 46 | + uses: docker/setup-buildx-action@v3 |
| 47 | + - name: Log in to Docker Hub |
| 48 | + uses: docker/login-action@v3 |
| 49 | + with: |
| 50 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 51 | + password: ${{ secrets.DOCKER_HUB_TOKEN }} |
| 52 | + - name: Log in to the GitHub Container registry |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + registry: ghcr.io |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Extract metadata (tags, labels) for Docker |
| 60 | + id: meta |
| 61 | + uses: docker/metadata-action@v5 |
| 62 | + with: |
| 63 | + tags: | |
| 64 | + type=semver,pattern={{version}} |
| 65 | + type=ref,event=branch |
| 66 | + type=ref,event=pr |
| 67 | + type=raw,value=latest,enable={{is_default_branch}} |
| 68 | + images: | |
| 69 | + ${{ env.DOCKER_NAMESPACE }}/matrix-hookshot |
| 70 | + ghcr.io/matrix-org/matrix-hookshot |
| 71 | + |
| 72 | + - name: Build and push Docker images |
| 73 | + id: push |
| 74 | + uses: docker/build-push-action@v6 |
| 75 | + with: |
| 76 | + context: . |
| 77 | + # arm64 builds OOM without the git fetch setting. c.f. |
| 78 | + # https://github.com/rust-lang/cargo/issues/10583 |
| 79 | + build-args: | |
| 80 | + CARGO_NET_GIT_FETCH_WITH_CLI=true |
| 81 | + platforms: ${{ (env.BUILD_FOR_ALL_PLATFORMS == 'true' && env.PLATFORMS_PUSH) || env.PLATFORMS }} |
| 82 | + push: true |
| 83 | + tags: ${{ steps.meta.outputs.tags }} |
| 84 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments