-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJustfile
More file actions
583 lines (504 loc) · 22.8 KB
/
Justfile
File metadata and controls
583 lines (504 loc) · 22.8 KB
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
set unstable := true
mod? titanoboa
# Constants
repo_image_name := lowercase("m2os")
repo_name := lowercase("m2Giles")
IMAGE_REGISTRY := "ghcr.io" / repo_name
FQ_IMAGE_NAME := IMAGE_REGISTRY / repo_image_name
# Images
[private]
images := '(
# Stable Images
[aurora]=' + aurora + '
[aurora-nvidia]=' + aurora_nvidia + '
[bazzite]=' + bazzite + '
[bazzite-deck]=' + bazzite_deck + '
[bluefin]=' + bluefin + '
[bluefin-nvidia]=' + bluefin_nvidia + '
[cosmic]="cosmic"
[cosmic-nvidia]="cosmic-nvidia-open"
[ucore]=' + ucore + '
[ucore-nvidia]=' + ucore_nvidia + '
# Beta Images
[aurora-beta]=' + aurora_beta + '
[aurora-nvidia-beta]=' + aurora_nvidia_beta + '
[bazzite-beta]=' + bazzite_beta + '
[bazzite-deck-beta]=' + bazzite_deck_beta + '
[bluefin-beta]=' + bluefin_beta + '
[bluefin-nvidia-beta]=' + bluefin_nvidia_beta + '
[cosmic-beta]="cosmic"
[cosmic-nvidia-beta]="cosmic-nvidia-open"
[ucore-beta]=' + ucore_beta + '
[ucore-nvidia-beta]=' + ucore_nvidia_beta + '
)'
# Build Containers
[private]
chunkah := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)\"" $1', image-file, "chunkah")
[private]
qemu := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "qemu")
# Base Containers
[private]
brew := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "brew")
[private]
common := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "common")
[private]
aurora := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "aurora")
[private]
aurora_nvidia := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "aurora-nvidia")
[private]
bazzite := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "bazzite")
[private]
bazzite_deck := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "bazzite-deck")
[private]
bluefin := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "bluefin")
[private]
bluefin_nvidia := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "bluefin-nvidia")
[private]
ucore := "ghcr.io/ublue-os/ucore:stable-zfs@sha256:ec2bfae0a8aa84add04ee802a8b116995dc8ce609b193540655203e4abcf3937"
[private]
ucore_nvidia := "ghcr.io/ublue-os/ucore:stable-nvidia-zfs@sha256:ecda298f835a15eddd203a574428ab1358c3bf103532eb607f0f15c3006aa83b"
[private]
aurora_beta := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "aurora-beta")
[private]
aurora_nvidia_beta := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "aurora-nvidia-beta")
[private]
bazzite_beta := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "bazzite-beta")
[private]
bazzite_deck_beta := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "bazzite-deck-beta")
[private]
bluefin_beta := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "bluefin-beta")
[private]
bluefin_nvidia_beta := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "bluefin-nvidia-beta")
[private]
ucore_beta := "ghcr.io/ublue-os/ucore:testing-zfs@sha256:71f47c5cac34ae48714026ea1a8197730ce6bd172cf1d1c394cdb1e5626c96b2"
[private]
ucore_nvidia_beta := "ghcr.io/ublue-os/ucore:testing-nvidia-zfs@sha256:ded20788bbd11957552c950c53733fe15726c46e397306edad2533fea75dc149"
[private]
akmods_stable := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "akmods-stable")
[private]
akmods_testing := shell('yq -r ".images[] | select(.name == \"$2\") | \"\\(.image):\\(.tag)@\\(.digest)\"" $1', image-file, "akmods-testing")
[private]
default:
@{{ just }} --list
# Check Just Syntax
[group('Just')]
check:
{{ just }} --unstable --fmt --check
# Fix Just Syntax
[group('Just')]
fix:
{{ just }} --unstable --fmt
# Cleanup
[group('Utility')]
clean:
find {{ repo_image_name }}_* -maxdepth 0 -exec rm -rf {} \; 2>/dev/null || true
rm -f output*.env changelog*.md version.txt previous.manifest.json
rm -f ./*.sbom.*
# Build
[group('Image')]
build image="bluefin": (build-image image) (secureboot "localhost" / repo_image_name + ":" + image) (rechunk image)
# Build Image
[group('Image')]
build-image image="bluefin":
#!/usr/bin/bash
{{ ci_grouping }}
{{ verify-container }}
echo "################################################################################"
echo "image := {{ image }}"
echo "PODMAN := {{ PODMAN }}"
echo "CI := {{ CI }}"
echo "################################################################################"
declare -A images={{ images }}
check=${images[{{ image }}]-}
if [[ -z "$check" ]]; then
exit 1
fi
BUILD_ARGS=({{ if CI != '' { '--cpp-flag=-DGHCI' } else { '' } }})
mkdir -p {{ GIT_ROOT / BUILD_DIR }}
BUILDTMP="$(mktemp -d -p {{ GIT_ROOT / BUILD_DIR }})"
trap 'rm -rf $BUILDTMP' EXIT SIGINT
set -eoux pipefail
case "{{ image }}" in
"aurora"*|"bluefin"*) BUILD_ARGS+=("--cpp-flag=-DDESKTOP") ;;
"bazzite"*) BUILD_ARGS+=("--cpp-flag=-DBAZZITE") ;;
"cosmic"*)
{{ if image =~ 'beta' { 'bluefin=${images[bluefin-beta]}' } else { 'bluefin="${images[bluefin]}"' } }}
verify-container "${bluefin#*-os/}"
fedora_version="$(skopeo inspect docker://"${bluefin/:*@/@}" | jq -r '.Labels["ostree.linux"]' | grep -oP 'fc\K[0-9]+')"
check="$(yq -r ".images[] | select(.name == \"base-${fedora_version}\")" {{ image-file }} | yq -r "\"\(.image):\(.tag)@\(.digest)\"")"
BUILD_ARGS+=("--cpp-flag=-DCOSMIC")
verify-container "{{ replace_regex(brew, "^.+/", "") }}"
verify-container "{{ replace_regex(common, "^.+/", "") }}" "ghcr.io/projectbluefin" "https://raw.githubusercontent.com/projectbluefin/common/refs/heads/main/cosign.pub"
BUILD_ARGS+=("--cpp-flag=-DBREW={{ brew }}" "--cpp-flag=-DCOMMON={{ common }}")
;;
"ucore"*) BUILD_ARGS+=("--cpp-flag=-DSERVER") ;;
esac
# Check Base Container
verify-container "${check#*-os/}"
# AKMODS
{{ if image =~ 'beta' { 'akmods_version=testing' } else if image =~ 'aurora|bluefin|cosmic' { 'akmods_version=stable' } else { '' } }}
# TODO: should instead take advantage of the kernel version tags on the akmods images to avoid skew between nvidia/zfs and akmods.
# akmods
{{ if image =~ 'aurora|bluefin|cosmic' { 'akmods="$(yq -r ".images[] | select(.name == \"akmods-${akmods_version}\")" ' + image-file + ' | yq -r "\"\(.image):\(.tag)@\(.digest)\"")"' } else { '' } }}
{{ if image =~ 'aurora|bluefin|cosmic' { 'verify-container "${akmods#*-os/}"; BUILD_ARGS+=("--cpp-flag=-DAKMODS=$akmods")' } else { '' } }}
# zfs
{{ if image =~ 'cosmic|(aurora.*|bluefin.*)-beta' { 'akmods_zfs="$(yq -r ".images[] | select(.name == \"akmods-zfs-${akmods_version}\")" ' + image-file + ' | yq -r "\"\(.image):\(.tag)@\(.digest)\"")"' } else { '' } }}
{{ if image =~ 'cosmic|(aurora.*|bluefin.*)-beta' { 'verify-container "${akmods_zfs#*-os/}"; BUILD_ARGS+=("--cpp-flag=-DZFS=$akmods_zfs")' } else { '' } }}
# nvidia
{{ if image =~ 'cosmic-nv.*|(aurora-nv.*|bluefin-nv.*)-beta' { 'akmods_nvidia="$(yq -r ".images[] | select(.name == \"akmods-nvidia-open-${akmods_version}\")" ' + image-file + ' | yq -r "\"\(.image):\(.tag)@\(.digest)\"")"' } else { '' } }}
{{ if image =~ 'cosmic-nv.*|(aurora-nv.*|bluefin-nv.*)-beta' { 'verify-container "${akmods_nvidia#*-os/}"; BUILD_ARGS+=("--cpp-flag=-DNVIDIA=$akmods_nvidia")' } else { '' } }}
skopeo inspect docker://{{ if image =~ 'cosmic|(aurora.*|bluefin.*)-beta' { '"${akmods/:*@/@}"' } else { '"${check/:*@/@}"' } }} > "$BUILDTMP/inspect-{{ image }}.json"
# Get The Version
fedora_version="$(jq -r '.Labels["ostree.linux"]' < "$BUILDTMP/inspect-{{ image }}.json" | grep -oP 'fc\K[0-9]+')"
VERSION="{{ image }}-${fedora_version}.$(date +%Y%m%d)"
skopeo list-tags docker://{{ FQ_IMAGE_NAME }} > "$BUILDTMP"/repotags.json
if [[ $(jq "any(.Tags[]; contains(\"$VERSION\"))" < "$BUILDTMP"/repotags.json) == "true" ]]; then
POINT="1"
while jq -e "any(.Tags[]; contains(\"$VERSION.$POINT\"))" >/dev/null < "$BUILDTMP"/repotags.json
do
(( POINT++ ))
done
fi
if [[ -n "${POINT:-}" ]]; then
VERSION="${VERSION}.$POINT"
fi
# Pull the images
{{ PODMAN }} pull "$check"
{{ if image =~ 'cosmic|aurora|bluefin' { PODMAN + ' pull "$akmods"' } else { '' } }}
{{ if image =~ 'cosmic|(aurora.*|bluefin.*)-beta' { PODMAN + ' pull "$akmods_zfs"' } else { '' } }}
{{ if image =~ 'cosmic-nv.*|(aurora-nv.*|bluefin-nv.*)-beta' { PODMAN + ' pull "$akmods_nvidia"' } else { '' } }}
{{ if image =~ 'cosmic' { PODMAN + ' pull ' + common } else { '' } }}
{{ if image =~ 'cosmic' { PODMAN + ' pull ' + brew } else { '' } }}
# Labels
BUILD_ARGS+=(
"--inherit-labels=false"
"--label" "org.opencontainers.image.description={{ repo_image_name }} is my OCI image built from ublue projects. It mainly extends them for my uses."
"--label" "org.opencontainers.image.source=https://github.com/{{ repo_name }}/{{ repo_image_name }}"
"--label" "org.opencontainers.image.title={{ repo_image_name }}"
"--label" "org.opencontainers.image.version=$VERSION"
"--label" "ostree.kernel_flavor={{ if image =~ 'bazzite' { 'bazzite' } else if image =~ 'beta' { 'coreos-testing' } else { 'coreos-stable' } }}"
"--label" "ostree.linux=$(jq -r '.Labels["ostree.linux"]' < "$BUILDTMP"/inspect-{{ image }}.json)"
"--label" "containers.bootc=1"
"--label" "ostree.bootable=true"
)
#Build Args
BUILD_ARGS+=(
"--build-arg" "IMAGE={{ image }}"
"--build-arg" "BASE_IMAGE=${check%%:*}"
"--build-arg" "TAG_VERSION=${check#*:}"
"--build-arg" "VERSION=$VERSION"
)
{{ if env("GITHUB_TOKEN", "") != "" { 'echo "Adding GitHub Token as build secret..."; BUILD_ARGS+=("--secret" "id=GITHUB_TOKEN,env=GITHUB_TOKEN")' } else { '' } }}
# Additional Args
BUILD_ARGS+=(
"--security-opt" "label=disable"
"--file" "Containerfile.in"
"--tag" "{{ repo_image_name + ":" + image }}"
)
{{ PODMAN }} build "${BUILD_ARGS[@]}" {{ GIT_ROOT }}
{{ if CI != '' { PODMAN + ' rmi -f "${check%@*}"' } else { '' } }}
# Rechunk Image
[group('Image')]
rechunk image="bluefin":
#!/usr/bin/bash
{{ shell('mkdir -p $1', GIT_ROOT / BUILD_DIR) }}
{{ ci_grouping }}
echo "################################################################################"
echo "image := {{ image }}"
echo "PODMAN := {{ PODMAN }}"
echo "CI := {{ CI }}"
echo "whoami := {{ shell("whoami") }}"
echo "################################################################################"
set -eou pipefail
{{ if CI != '' { 'set -x' } else { '' } }}
IMG="localhost/{{ repo_image_name + ":" + image }}"
{{ PODMAN }} image exists "$IMG" || { echo "Image $IMG not found. Please build the image first." >&2; exit 1; }
TMPDIR="$(mktemp -d -p {{ GIT_ROOT / BUILD_DIR }})"
trap 'rm -rf "$TMPDIR"' EXIT SIGINT
{{ PODMAN }} inspect "$IMG" > "$TMPDIR/inspect.json"
{{ PODMAN }} run --rm \
--security-opt label=disable \
--mount=type=bind,source="$TMPDIR/inspect.json",target=/tmp/inspect.json,ro \
--mount=type=image,source="$IMG",target=/chunkah \
{{ chunkah }} build \
{{ if CI != '' { '-v' } else { '' } }} \
--prune /sysroot/ \
--max-layers=448 \
--config /tmp/inspect.json \
> {{ repo_image_name + "_" + image + ".tar" }}
{{ PODMAN }} images
{{ if CI != '' { PODMAN + ' system reset --force' } else { PODMAN + ' rmi -f $IMG' } }}
{{ skopeo }} copy oci-archive:{{ repo_image_name + "_" + image + ".tar" }} containers-storage:{{ FQ_IMAGE_NAME + ":" + image }}
{{ PODMAN }} images
# Build ISO
[group('ISO')]
build-iso image="bluefin":
{{ shell("mkdir -p $1/output", GIT_ROOT / BUILD_DIR) }}
{{ SUDOIF }} \
HOOK_pre_initramfs="{{ if image =~ 'bazzite' { GIT_ROOT / 'iso_files/preinitramfs.sh' } else { '' } }}" \
HOOK_post_rootfs="{{ GIT_ROOT / 'iso_files/configure_iso.sh' }}" \
CI="{{ CI }}" \
{{ just }} titanoboa::build \
{{ FQ_IMAGE_NAME + ":" + image }} \
"1" \
{{ if image =~ "aurora" { GIT_ROOT / "iso_files/kde-flatpaks.txt" } else { GIT_ROOT / "iso_files/gnome-flatpaks.txt" } }} \
"squashfs" \
"NONE" \
{{ FQ_IMAGE_NAME + ":" + image }} \
"1"
{{ SUDOIF }} chown "$(id -u):$(id -g)" output.iso
sha256sum output.iso | tee {{ GIT_ROOT / BUILD_DIR / "output" / repo_image_name + "-" + image + ".iso-CHECKSUM" }}
mv output.iso {{ GIT_ROOT / BUILD_DIR / "output" / repo_image_name + "-" + image + ".iso" }}
{{ SUDOIF }} {{ just }} titanoboa::clean
# Run ISO
[group('ISO')]
run-iso image="bluefin":
{{ if path_exists(GIT_ROOT / BUILD_DIR / "output" / repo_image_name + "-" + image + ".iso") == "true" { '' } else { just + " build-iso " + image } }}
{{ just }} titanoboa::container-run-vm {{ GIT_ROOT / BUILD_DIR / "output" / repo_image_name + "-" + image + ".iso" }}
# Verify Container with Cosign
[group('Utility')]
verify-container container registry="ghcr.io/ublue-os" key="":
if ! cosign verify --key "{{ if key == '' { 'https://raw.githubusercontent.com/ublue-os/main/main/cosign.pub' } else { key } }}" "{{ if registry != '' { registry / container } else { container } }}" >/dev/null; then \
echo "NOTICE: Verification failed. Please ensure your public key is correct." && exit 1 \
; fi
# Secureboot Check
[group('Image')]
secureboot image="bluefin":
#!/usr/bin/bash
{{ ci_grouping }}
set -eoux pipefail
# Get the vmlinuz to check
kernel_release=$({{ PODMAN }} inspect "{{ image }}" | jq -r '.[].Config.Labels["ostree.linux"]')
TMP=$({{ PODMAN }} create "{{ image }}" bash)
TMPDIR="$(mktemp -d -p .)"
trap 'rm -rf $TMPDIR' EXIT
{{ PODMAN }} cp "$TMP":/usr/lib/modules/"${kernel_release}"/vmlinuz "$TMPDIR/vmlinuz"
{{ PODMAN }} rm "$TMP"
# Get the Public Certificates
curl --retry 3 -Lo "$TMPDIR"/kernel-sign.der https://github.com/ublue-os/kernel-cache/raw/main/certs/public_key.der
curl --retry 3 -Lo "$TMPDIR"/akmods.der https://github.com/ublue-os/kernel-cache/raw/main/certs/public_key_2.der
openssl x509 -in "$TMPDIR"/kernel-sign.der -out "$TMPDIR"/kernel-sign.crt
openssl x509 -in "$TMPDIR"/akmods.der -out "$TMPDIR"/akmods.crt
# Make sure we have sbverify
CMD="$(command -v sbverify)" || true
if [[ -z "${CMD:-}" ]]; then
temp_name="sbverify-${RANDOM}"
{{ PODMAN }} run -dt \
--entrypoint /bin/sh \
--security-opt label=disable \
--workdir {{ GIT_ROOT }} \
--volume "{{ GIT_ROOT }}/$TMPDIR/:{{ GIT_ROOT }}/$TMPDIR" \
--name ${temp_name} \
alpine:edge
{{ PODMAN }} exec "${temp_name}" apk add sbsigntool
CMD="{{ PODMAN }} exec ${temp_name} /usr/bin/sbverify"
fi
# Confirm that Signatures Are Good
$CMD --list "$TMPDIR/vmlinuz"
returncode=0
if ! $CMD --cert "$TMPDIR/kernel-sign.crt" "$TMPDIR/vmlinuz" ||
! $CMD --cert "$TMPDIR/akmods.crt" "$TMPDIR/vmlinuz"; then
echo "Secureboot Signature Failed...."
returncode=1
fi
if [[ -n "${temp_name:-}" ]]; then
{{ PODMAN }} rm -f "${temp_name}"
fi
exit "$returncode"
# Lint Files
[group('Utility')]
lint:
# shell
/usr/bin/find . -iname "*.sh" -type f -not -path "./titanoboa/*" -exec shellcheck "{}" ';'
# yaml
yamllint -s {{ justfile_dir() }}
# just
{{ just }} check
# just recipes
{{ just }} lint-recipes
# Format Files
[group('Utility')]
format:
# shell
/usr/bin/find . -iname "*.sh" -type f -exec shfmt --write "{}" ';'
# yaml
yamlfmt {{ justfile_dir() }}
# just
{{ just }} fix
# Linter Helper
[group('Utility')]
_lint-recipe linter recipe *args:
#!/usr/bin/bash
set -eou pipefail
mkdir -p {{ BUILD_DIR }}
TMPDIR="$(mktemp -d -p {{ BUILD_DIR }})"
trap 'rm -rf "$TMPDIR"' EXIT SIGINT
{{ just }} -n {{ recipe }} {{ args }} 2>&1 | tee "$TMPDIR"/{{ recipe }} >/dev/null
linter=({{ linter }})
echo "Linting {{ style('warning') }}{{ recipe }}{{ NORMAL }} with {{ style('command') }}${linter[0]}{{ NORMAL }}"
{{ linter }} "$TMPDIR"/{{ recipe }} && rm "$TMPDIR"/{{ recipe }} || rm "$TMPDIR"/{{ recipe }}
# Linter Helper
[group('Utility')]
lint-recipes:
#!/usr/bin/bash
recipes=(
build-image
build-iso
gen-sbom
rechunk
run-iso
sbom-sign
sbom-attach
secureboot
)
for recipe in "${recipes[@]}"; do
{{ just }} _lint-recipe "shellcheck" "$recipe" bluefin
done
recipes=(
clean
lint-recipes
)
for recipe in "${recipes[@]}"; do
{{ just }} _lint-recipe "shellcheck" "$recipe"
done
# Login to GHCR
[group('CI')]
login-to-ghcr $user $token:
echo "$token" | {{ if which("podman") != "" { PODMAN + ' login ghcr.io -u "$user" --password-stdin' } else { 'docker login ghcr.io -u "$user" --password-stdin' } }}
{{ if which("podman") != "" { 'echo $token | ' + PODMAN + ' login ghcr.io -u "$user" --password-stdin --authfile ~/.docker/config.json' } else { '' } }}
# Push and Sign
[group('CI')]
push-and-sign image dryrun="true" sign="false":
#!/usr/bin/bash
set -eoux pipefail
{{ shell('mkdir -p $1', BUILD_DIR) }}
trap 'rm -f {{ BUILD_DIR }}/{digest{,1,2},inspect.json}' EXIT SIGINT
skopeo inspect oci-archive:{{ repo_image_name }}_{{ image }}.tar > "{{ BUILD_DIR }}/inspect.json"
for tag in {{ image }} $(jq -r '.Labels["org.opencontainers.image.version"]' < "{{ BUILD_DIR }}/inspect.json"); do
# Push twice do to bug with annotations not getting pushed on the first time?
{{ if dryrun == "false" { 'skopeo copy --preserve-digests --digestfile ' + BUILD_DIR + '/digest1 oci-archive:' + repo_image_name + '_' + image + '.tar docker://' + IMAGE_REGISTRY + '/' + repo_image_name + ':$tag >&2' } else { 'echo "$tag" >&2' } }}
{{ if dryrun == "false" { 'skopeo copy --preserve-digests --digestfile ' + BUILD_DIR + '/digest2 oci-archive:' + repo_image_name + '_' + image + '.tar docker://' + IMAGE_REGISTRY + '/' + repo_image_name + ':$tag >&2' } else { 'echo "$tag" >&2' } }}
done
if [[ "{{ dryrun }}" == "true" ]]; then
echo "Dry run complete. Digests not pushed."
exit 0
fi
# Compare digests are the same, if not fail as something went wrong with the push
if ! diff {{ BUILD_DIR }}/{digest1,digest2} >/dev/null; then
echo "Digests are not the same..."
exit 1
else
mv {{ BUILD_DIR }}/digest{1,}
rm {{ BUILD_DIR }}/digest2
fi
# Sign the image with Cosign if enabled
if [[ "{{ sign }}" == "true" ]]; then
cosign sign -y --key env://COSIGN_PRIVATE_KEY "{{ IMAGE_REGISTRY + "/" + repo_image_name }}@$(cat {{ BUILD_DIR }}/digest)"
fi
# Generate SBOM
[group('CI')]
gen-sbom $input $output="":
#!/usr/bin/bash
set -eoux pipefail
# Make SBOM
if [[ -z "$output" ]]; then
OUTPUT_PATH="$(mktemp -d)/sbom.json"
else
OUTPUT_PATH="$output"
fi
syft scan "{{ input }}" -o spdx-json="$OUTPUT_PATH" --select-catalogers "rpm,+sbom-cataloger"
# Output Path
echo "$OUTPUT_PATH"
# Add SBOM Signing
[group('CI')]
sbom-sign input $sbom="":
#!/usr/bin/bash
set -eoux pipefail
# set SBOM
if [[ ! -f "$sbom" ]]; then
sbom="$({{ just }} gen-sbom {{ input }})"
fi
# Sign-blob Args
SBOM_SIGN_ARGS=(
"--key" "env://COSIGN_PRIVATE_KEY"
"--output-signature" "$sbom.sig"
"$sbom"
)
# Sign SBOM
cosign sign-blob -y "${SBOM_SIGN_ARGS[@]}"
# Verify-blob Args
SBOM_VERIFY_ARGS=(
"--key" "cosign.pub"
"--signature" "$sbom.sig"
"$sbom"
)
# Verify Signature
{{ cosign }} verify-blob "${SBOM_VERIFY_ARGS[@]}"
# SBOM Attach (ORAS attach + cosign sign)
[group('CI')]
sbom-attach input $sbom="" $destination="":
#!/usr/bin/bash
set -eoux pipefail
# set SBOM
if [[ ! -f "$sbom" ]]; then
sbom="$({{ just }} gen-sbom {{ input }})"
fi
: "${destination:={{ IMAGE_REGISTRY }}}"
TMPDIR="$(mktemp -d -p .)"
trap 'rm -rf "$TMPDIR"' EXIT SIGINT
{{ skopeo }} inspect "{{ input }}" > "$TMPDIR/info.json"
digest="$({{ jq }} -r '.Digest' < "$TMPDIR/info.json")"
version="$({{ jq }} -r '.Labels["org.opencontainers.image.version"]' < "$TMPDIR/info.json")"
pushd "$(dirname "$sbom")" > /dev/null
{{ oras }} attach "$destination/{{ repo_image_name }}@${digest}" "$(basename "$sbom")" --artifact-type application/vnd.spdx+json -a "filename=$(basename "$sbom")" -a "org.opencontainers.image.version=$version"
sbom_digest="$({{ oras }} discover "$destination/{{ repo_image_name }}@${digest}" --artifact-type application/vnd.spdx+json --format json | {{ jq }} -r '.manifests[0].digest')"
{{ cosign }} sign -y --key env://COSIGN_PRIVATE_KEY "$destination/{{ repo_image_name }}@${sbom_digest}"
popd > /dev/null
# Utils
[private]
GIT_ROOT := justfile_dir()
[private]
BUILD_DIR := repo_image_name + "_build"
[private]
just := just_executable() + " -f " + justfile()
[private]
image-file := GIT_ROOT / "image-versions.yml"
[private]
yq := which("yq")
[private]
jq := which("jq")
[private]
skopeo := which("skopeo")
[private]
oras := which("oras")
[private]
cosign := which("cosign")
[private]
syft := which("syft")
# SUDO
[private]
SUDO_DISPLAY := env("DISPLAY", "") || env("WAYLAND_DISPLAY", "")
[private]
export SUDOIF := if `id -u` == "0" { "" } else if SUDO_DISPLAY != "" { which("sudo") + " --askpass" } else { which("sudo") }
# Podman By Default
[private]
export PODMAN := env("PODMAN", "") || which("podman") || require("podman-remote")
# Utilities
verify-container := '''
function verify-container() {
local container="$1"
local registry="${2:-ghcr.io/ublue-os}"
local key="${3:-https://raw.githubusercontent.com/ublue-os/main/main/cosign.pub}"
local target="$registry/$container"
if ! cosign verify --key "$key" "$target" &>/dev/null; then
echo "NOTICE: Verification failed. Please ensure your public key is correct." && exit 1
fi
}
'''
ci_grouping := '
if [[ -n "${CI:-}" ]]; then
echo "::group::' + style('warning') + '${BASH_SOURCE[0]##*/} step' + NORMAL + '"
trap "echo ::endgroup::" EXIT
fi'
[private]
CI := env('CI', '')