@@ -5,7 +5,7 @@ name: Build docker images
55on :
66 push :
77 tags : ["v*"]
8- branches : [ master, main, develop ]
8+ branches : [master, main, develop]
99 workflow_dispatch :
1010
1111permissions :
@@ -14,26 +14,24 @@ permissions:
1414 id-token : write # needed for signing the images with GitHub OIDC Token
1515jobs :
1616 build :
17- runs-on : ubuntu-22.04
17+ name : Build and push image for ${{ matrix.platform }}
18+ runs-on : ${{ matrix.runs_on }}
19+ strategy :
20+ matrix :
21+ include :
22+ - platform : linux/amd64
23+ runs_on : ubuntu-24.04
24+ suffix : linux-amd64
25+ - platform : linux/arm64
26+ runs_on : ubuntu-24.04-arm
27+ suffix : linux-arm64
1828 steps :
19- - name : Set up QEMU
20- id : qemu
21- uses : docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
22- with :
23- platforms : arm64
24-
2529 - name : Set up Docker Buildx
2630 id : buildx
27- uses : docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
28-
29- - name : Inspect builder
30- run : docker buildx inspect
31-
32- - name : Install Cosign
33- uses : sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2
31+ uses : docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
3432
3533 - name : Checkout repository
36- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3735
3836 - name : Extract version from pyproject.toml
3937 # Note: explicitly requesting bash will mean bash is invoked with `-eo pipefail`, see
@@ -43,57 +41,115 @@ jobs:
4341 echo "SYNAPSE_VERSION=$(grep "^version" pyproject.toml | sed -E 's/version\s*=\s*["]([^"]*)["]/\1/')" >> $GITHUB_ENV
4442
4543 - name : Log in to DockerHub
46- uses : docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4 .0
44+ uses : docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6 .0
4745 with :
4846 username : ${{ secrets.DOCKERHUB_USERNAME }}
4947 password : ${{ secrets.DOCKERHUB_TOKEN }}
5048
5149 - name : Log in to GHCR
52- uses : docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4 .0
50+ uses : docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6 .0
5351 with :
5452 registry : ghcr.io
5553 username : ${{ github.repository_owner }}
5654 password : ${{ secrets.GITHUB_TOKEN }}
5755
58- - name : Calculate docker image tag
59- id : set-tag
60- uses : docker/metadata- action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7 .0
56+ - name : Build and push by digest
57+ id : build
58+ uses : docker/build-push- action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18 .0
6159 with :
62- images : |
60+ push : true
61+ labels : |
62+ gitsha1=${{ github.sha }}
63+ org.opencontainers.image.version=${{ env.SYNAPSE_VERSION }}
64+ tags : |
6365 docker.io/matrixdotorg/synapse
6466 ghcr.io/element-hq/synapse
67+ file : " docker/Dockerfile"
68+ platforms : ${{ matrix.platform }}
69+ outputs : type=image,push-by-digest=true,name-canonical=true,push=true
70+
71+ - name : Export digest
72+ run : |
73+ mkdir -p ${{ runner.temp }}/digests
74+ digest="${{ steps.build.outputs.digest }}"
75+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
76+
77+ - name : Upload digest
78+ uses : actions/upload-artifact@v4
79+ with :
80+ name : digests-${{ matrix.suffix }}
81+ path : ${{ runner.temp }}/digests/*
82+ if-no-files-found : error
83+ retention-days : 1
84+
85+ merge :
86+ name : Push merged images to ${{ matrix.repository }}
87+ runs-on : ubuntu-latest
88+ strategy :
89+ matrix :
90+ repository :
91+ - docker.io/matrixdotorg/synapse
92+ - ghcr.io/element-hq/synapse
93+
94+ needs :
95+ - build
96+ steps :
97+ - name : Download digests
98+ uses : actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
99+ with :
100+ path : ${{ runner.temp }}/digests
101+ pattern : digests-*
102+ merge-multiple : true
103+
104+ - name : Log in to DockerHub
105+ uses : docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
106+ if : ${{ startsWith(matrix.repository, 'docker.io') }}
107+ with :
108+ username : ${{ secrets.DOCKERHUB_USERNAME }}
109+ password : ${{ secrets.DOCKERHUB_TOKEN }}
110+
111+ - name : Log in to GHCR
112+ uses : docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
113+ if : ${{ startsWith(matrix.repository, 'ghcr.io') }}
114+ with :
115+ registry : ghcr.io
116+ username : ${{ github.repository_owner }}
117+ password : ${{ secrets.GITHUB_TOKEN }}
118+
119+ - name : Set up Docker Buildx
120+ uses : docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
121+
122+ - name : Install Cosign
123+ uses : sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0
124+
125+ - name : Calculate docker image tag
126+ uses : docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5.8.0
127+ with :
128+ images : ${{ matrix.repository }}
65129 flavor : |
66130 latest=false
67131 tags : |
68132 type=raw,value=develop,enable=${{ github.ref == 'refs/heads/develop' }}
69133 type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
70134 type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
71135 type=pep440,pattern={{raw}}
136+ type=sha
72137
73- - name : Build and push all platforms
74- id : build-and-push
75- uses : docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0 # v6.17.0
76- with :
77- push : true
78- labels : |
79- gitsha1=${{ github.sha }}
80- org.opencontainers.image.version=${{ env.SYNAPSE_VERSION }}
81- tags : " ${{ steps.set-tag.outputs.tags }}"
82- file : " docker/Dockerfile"
83- platforms : linux/amd64,linux/arm64
84-
85- # arm64 builds OOM without the git fetch setting. c.f.
86- # https://github.com/rust-lang/cargo/issues/10583
87- build-args : |
88- CARGO_NET_GIT_FETCH_WITH_CLI=true
138+ - name : Create manifest list and push
139+ working-directory : ${{ runner.temp }}/digests
140+ env :
141+ REPOSITORY : ${{ matrix.repository }}
142+ run : |
143+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
144+ $(printf "$REPOSITORY@sha256:%s " *)
89145
90- - name : Sign the images with GitHub OIDC Token
146+ - name : Sign each manifest
91147 env :
92- DIGEST : ${{ steps.build-and-push.outputs.digest }}
93- TAGS : ${{ steps.set-tag.outputs.tags }}
148+ REPOSITORY : ${{ matrix.repository }}
94149 run : |
95- images=""
96- for tag in ${TAGS}; do
97- images+="${tag}@${DIGEST} "
150+ DIGESTS=""
151+ for TAG in $(echo "$DOCKER_METADATA_OUTPUT_JSON" | jq -r '.tags[]'); do
152+ DIGEST="$(docker buildx imagetools inspect $TAG --format '{{json .Manifest}}' | jq -r '.digest')"
153+ DIGESTS="$DIGESTS $REPOSITORY@$DIGEST"
98154 done
99- cosign sign --yes ${images}
155+ cosign sign --yes $DIGESTS
0 commit comments