-
Notifications
You must be signed in to change notification settings - Fork 9
346 lines (296 loc) · 10.8 KB
/
build.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
name: Build
on:
push:
branches: [main]
tags:
- "v*"
# Only run for pull requests if relevant files were changed
pull_request:
branches: [main]
paths:
- Dockerfile
- docker-bake.hcl
- .github/workflows/build.yaml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
IMAGE: ghcr.io/element-hq/matrix-authentication-service
IMAGE_SYN2MAS: ghcr.io/element-hq/matrix-authentication-service/syn2mas
BUILDCACHE: ghcr.io/element-hq/matrix-authentication-service/buildcache
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
jobs:
build-binaries:
name: Build binaries
runs-on: ubuntu-22.04
permissions:
contents: read
steps:
- name: Checkout the code
uses: actions/[email protected]
- name: Setup OPA
uses: open-policy-agent/[email protected]
with:
version: 0.64.1
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: |
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
- name: Setup sccache
uses: mozilla-actions/[email protected]
- name: Install zig
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.13.0
- name: Install cargo-zigbuild
run: curl -L https://github.com/rust-cross/cargo-zigbuild/releases/download/v0.19.1/cargo-zigbuild-v0.19.1.x86_64-unknown-linux-musl.tar.gz | tar -z -x -C /usr/local/bin
- name: Install frontend Node
uses: actions/[email protected]
with:
node-version: 20
- name: Install frontend Node dependencies
working-directory: ./frontend
run: npm ci
- name: Build frontend
working-directory: ./frontend
run: npm run build
- name: Build policies
working-directory: ./policies
run: make
- name: Build the binary
run: |
cargo zigbuild \
--release \
--target x86_64-unknown-linux-gnu.2.17 \
--target aarch64-unknown-linux-gnu.2.17 \
--no-default-features \
--features dist \
-p mas-cli
- name: Create one archive per architecture
run: |
for arch in x86_64 aarch64; do
# Create one directory per architecture
mkdir -p dist/${arch}/share/
# Copy the artifacts to the right place
cp policies/policy.wasm dist/${arch}/share/policy.wasm
cp frontend/dist/manifest.json dist/${arch}/share/manifest.json
cp -r frontend/dist/ dist/${arch}/share/assets
cp -r templates/ dist/${arch}/share/templates
cp -r translations/ dist/${arch}/share/translations
cp LICENSE dist/${arch}/LICENSE
chmod -R u=rwX,go=rX dist/${arch}/
# Copy the binary to the right place
cp target/${arch}-unknown-linux-gnu/release/mas-cli dist/${arch}/
chmod u=rwx,go=rx dist/${arch}/mas-cli
# Create the archive
tar -czvf mas-cli-${arch}-linux.tar.gz --owner=0 --group=0 -C dist/${arch}/ .
done
- name: Upload the artifacts
uses: actions/[email protected]
with:
name: binaries
path: |
mas-cli-aarch64-linux.tar.gz
mas-cli-x86_64-linux.tar.gz
build-image:
name: Build and push Docker image
runs-on: ubuntu-latest
outputs:
metadata: ${{ steps.output.outputs.metadata }}
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout the code
uses: actions/[email protected]
- name: Docker meta
id: meta
uses: docker/[email protected]
with:
images: "${{ env.IMAGE }}"
bake-target: docker-metadata-action
flavor: |
latest=auto
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Docker meta (debug variant)
id: meta-debug
uses: docker/[email protected]
with:
images: "${{ env.IMAGE }}"
bake-target: docker-metadata-action-debug
flavor: |
latest=auto
suffix=-debug,onlatest=true
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Docker meta (syn2mas)
id: meta-syn2mas
uses: docker/[email protected]
with:
images: "${{ env.IMAGE_SYN2MAS }}"
bake-target: docker-metadata-action-syn2mas
flavor: |
latest=auto
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Setup Cosign
uses: sigstore/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
with:
buildkitd-config-inline: |
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# For pull-requests, only read from the cache, do not try to push to the
# cache or the image itself
- name: Build
uses: docker/[email protected]
if: github.event_name == 'pull_request'
with:
files: |
docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
${{ steps.meta-debug.outputs.bake-file }}
${{ steps.meta-syn2mas.outputs.bake-file }}
set: |
base.context=https://github.com/${{ github.repository }}.git#${{ github.ref }}
syn2mas.context=https://github.com/${{ github.repository }}.git#${{ github.ref }}:tools/syn2mas/
base.cache-from=type=registry,ref=${{ env.BUILDCACHE }}:buildcache
- name: Build and push
id: bake
uses: docker/[email protected]
if: github.event_name != 'pull_request'
with:
files: |
docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
${{ steps.meta-debug.outputs.bake-file }}
${{ steps.meta-syn2mas.outputs.bake-file }}
set: |
base.context=https://github.com/${{ github.repository }}.git#${{ github.ref }}
syn2mas.context=https://github.com/${{ github.repository }}.git#${{ github.ref }}:tools/syn2mas/
base.output=type=image,push=true
base.cache-from=type=registry,ref=${{ env.BUILDCACHE }}:buildcache
base.cache-to=type=registry,ref=${{ env.BUILDCACHE }}:buildcache,mode=max
- name: Transform bake output
# This transforms the ouput to an object which looks like this:
# { reguar: { digest: "…", tags: ["…", "…"] }, debug: { digest: "…", tags: ["…"] }, … }
id: output
if: github.event_name != 'pull_request'
run: |
echo 'metadata<<EOF' >> $GITHUB_OUTPUT
echo '${{ steps.bake.outputs.metadata }}' | jq -c 'with_entries(select(.value | (type == "object" and has("containerimage.digest")))) | map_values({ digest: .["containerimage.digest"], tags: (.["image.name"] | split(",")) })' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Sign the images with GitHub Actions provided token
# Only sign on tags and on commits on main branch
if: |
github.event_name != 'pull_request'
&& (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: |-
cosign sign --yes \
"${{ env.IMAGE }}@${{ fromJSON(steps.output.outputs.metadata).regular.digest }}" \
"${{ env.IMAGE }}@${{ fromJSON(steps.output.outputs.metadata).debug.digest }}" \
"${{ env.IMAGE_SYN2MAS }}@${{ fromJSON(steps.output.outputs.metadata).syn2mas.digest }}"
syn2mas:
name: Release syn2mas on NPM
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout the code
uses: actions/[email protected]
- name: Install Node
uses: actions/[email protected]
with:
node-version-file: ./tools/syn2mas/.nvmrc
- name: Install Node dependencies
working-directory: ./tools/syn2mas
run: npm ci
- name: Publish
uses: JS-DevTools/npm-publish@v3
with:
package: ./tools/syn2mas
token: ${{ secrets.NPM_TOKEN }}
provenance: true
dry-run: ${{ !startsWith(github.ref, 'refs/tags/') }}
release:
name: Release
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs:
- build-binaries
- build-image
- syn2mas
steps:
- name: Download the artifacts from the previous job
uses: actions/download-artifact@v4
with:
name: binaries
path: artifacts
- name: Prepare a release
uses: softprops/action-gh-release@v2
with:
body: |
### Docker image
Regular image:
- Digest:
```
${{ env.IMAGE }}@${{ fromJSON(needs.build-image.outputs.metadata).regular.digest }}
```
- Tags:
```
${{ join(fromJSON(needs.build-image.outputs.metadata).regular.tags, '
') }}
```
Debug variant:
- Digest:
```
${{ env.IMAGE }}@${{ fromJSON(needs.build-image.outputs.metadata).debug.digest }}
```
- Tags:
```
${{ join(fromJSON(needs.build-image.outputs.metadata).debug.tags, '
') }}
```
`syn2mas` migration tool:
- Digest:
```
${{ env.IMAGE_SYN2MAS }}@${{ fromJSON(needs.build-image.outputs.metadata).syn2mas.digest }}
```
- Tags:
```
${{ join(fromJSON(needs.build-image.outputs.metadata).syn2mas.tags, '
') }}
```
files: |
artifacts/mas-cli-aarch64-linux.tar.gz
artifacts/mas-cli-x86_64-linux.tar.gz
draft: true