-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEarthfile
More file actions
1336 lines (1161 loc) · 60.3 KB
/
Copy pathEarthfile
File metadata and controls
1336 lines (1161 loc) · 60.3 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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
VERSION --arg-scope-and-set --shell-out-anywhere 0.6
ARG TARGETOS
ARG TARGETARCH
# Default image repositories used in the builds.
ARG SPECTRO_PUB_REPO=us-docker.pkg.dev/palette-images
ARG BUILDER_3RDPARTY_VERSION=4.8
ARG SPECTRO_THIRD_PARTY_IMAGE=us-docker.pkg.dev/palette-images/third-party/spectro-third-party:$BUILDER_3RDPARTY_VERSION
ARG ALPINE_TAG=3.20
ARG ALPINE_IMG=$SPECTRO_PUB_REPO/edge/canvos/alpine:$ALPINE_TAG
FROM $ALPINE_IMG
ARG FIPS_ENABLED=false
IF [ "$FIPS_ENABLED" = "true" ] && [ "$SPECTRO_PUB_REPO" = "us-docker.pkg.dev/palette-images" ]
LET SPECTRO_PUB_REPO=us-docker.pkg.dev/palette-images-fips
LET ALPINE_IMG=$SPECTRO_PUB_REPO/edge/canvos/alpine:$ALPINE_TAG
END
ARG SPECTRO_LUET_REPO=us-docker.pkg.dev/palette-images/edge
ARG KAIROS_BASE_IMAGE_URL=$SPECTRO_PUB_REPO/edge
# Spectro Cloud and Kairos tags.
ARG PE_VERSION=v4.9.21
ARG KAIROS_VERSION=v4.0.4
ARG K3S_FLAVOR_TAG=k3s1
ARG RKE2_FLAVOR_TAG=rke2r1
ARG BASE_IMAGE_URL=quay.io/kairos
ARG OSBUILDER_VERSION=v0.400.3
ARG OSBUILDER_IMAGE=quay.io/kairos/osbuilder-tools:$OSBUILDER_VERSION
ARG AURORABOOT_VERSION=v0.16.0
ARG AURORABOOT_IMAGE=quay.io/kairos/auroraboot:$AURORABOOT_VERSION
ARG K3S_PROVIDER_VERSION=v4.9.4
ARG KUBEADM_PROVIDER_VERSION=v4.9.8
ARG RKE2_PROVIDER_VERSION=v4.9.3
ARG NODEADM_PROVIDER_VERSION=v4.9.3
ARG CANONICAL_PROVIDER_VERSION=v4.9.3
# Variables used in the builds. Update for ADVANCED use cases only. Modify in .arg file or via CLI arguments.
ARG OS_DISTRIBUTION
ARG OS_VERSION
ARG K8S_VERSION
ARG IMAGE_REGISTRY
ARG IMAGE_REPO=$OS_DISTRIBUTION
ARG ISO_NAME=installer
ARG K8S_DISTRIBUTION
ARG CUSTOM_TAG
ARG CLUSTERCONFIG
ARG EDGE_CUSTOM_CONFIG=.edge-custom-config.yaml
ARG ARCH
ARG DISABLE_SELINUX=true
ARG CIS_HARDENING=false
# Ubuntu Pro toggle. The token itself is NEVER passed as a build arg.
# Recommended flow: use the earthly.sh wrapper. Set UBUNTU_PRO_ATTACH=true in
# .arg (or pass --UBUNTU_PRO_ATTACH=true on the CLI), then run e.g.
# ./earthly.sh +iso
# The wrapper prompts for the token without echoing it and forwards it as an
# Earthly --secret, so the value never lands in .arg, in `docker history`,
# in build-arg metadata, in the build cache, or in shell history.
# For non-interactive (CI) runs, export UBUNTU_PRO_KEY before invoking the
# script and the prompt is skipped:
# read -rs UBUNTU_PRO_KEY && export UBUNTU_PRO_KEY
# ./earthly.sh +iso
# Note: `earthly secret set ...` requires Earthly Cloud (earthly account login)
# and is not available on a stock CLI install - use the earthly.sh flow above.
ARG UBUNTU_PRO_ATTACH=false
# DRBD version for Piraeus pack
ARG DRBD_VERSION="9.2.13"
ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG NO_PROXY
ARG http_proxy=${HTTP_PROXY}
ARG https_proxy=${HTTPS_PROXY}
ARG no_proxy=${NO_PROXY}
ARG UPDATE_KERNEL=false
IF [ "$FIPS_ENABLED" = "true" ] && [ "$UPDATE_KERNEL" = "true" ]
RUN echo "ERROR: UPDATE_KERNEL and FIPS_ENABLED are mutually exclusive. Cannot set both to true." >&2 && \
exit 1
END
ARG ETCD_VERSION="v3.5.13"
# Two node variables
ARG TWO_NODE=false
ARG KINE_VERSION=0.15.0
# MAAS Variables
ARG IS_MAAS=false
ARG MAAS_IMAGE_NAME=kairos-ubuntu-maas
# UKI Variables
ARG IS_UKI=false
ARG INCLUDE_MS_SECUREBOOT_KEYS=true
ARG AUTO_ENROLL_SECUREBOOT_KEYS=false
ARG UKI_BRING_YOUR_OWN_KEYS=false
ARG CMDLINE="stylus.registration"
ARG BRANDING="Palette eXtended Kubernetes Edge"
ARG FORCE_INTERACTIVE_INSTALL=false
# EFI size check
ARG EFI_MAX_SIZE=2048
ARG EFI_IMG_SIZE=2200
# internal variables
ARG GOLANG_VERSION=1.23
ARG DEBUG=false
# Pin UKI to Kairos v3.5.9: systemd 257.x dropped the boot-assessment
# suffix from sd-boot entry IDs, breaking `bootentry` selection and
# assessment fallback on newer builds (refs: kairos-io/kairos#3831,
# kairos-io/kairos#4046). v3.5.9 ships systemd 256.x where it still works.
IF [ "$IS_UKI" = "true" ]
LET KAIROS_VERSION=v3.5.9
END
IF [ "$OS_DISTRIBUTION" = "ubuntu" ] && [ "$BASE_IMAGE" = "" ]
IF [ "$OS_VERSION" == 22 ] || [ "$OS_VERSION" == 20 ]
ARG BASE_IMAGE_TAG=kairos-$OS_DISTRIBUTION:$OS_VERSION.04-core-$ARCH-generic-$KAIROS_VERSION
ELSE
IF [ "$IS_UKI" = "true" ]
ARG BASE_IMAGE_TAG=kairos-$OS_DISTRIBUTION:$OS_VERSION-core-$ARCH-generic-$KAIROS_VERSION-uki
ELSE
ARG BASE_IMAGE_TAG=kairos-$OS_DISTRIBUTION:$OS_VERSION-core-$ARCH-generic-$KAIROS_VERSION
END
END
ARG BASE_IMAGE=$KAIROS_BASE_IMAGE_URL/$BASE_IMAGE_TAG
ELSE IF [ "$OS_DISTRIBUTION" = "opensuse-leap" ] && [ "$BASE_IMAGE" = "" ]
ARG BASE_IMAGE_TAG=kairos-opensuse:leap-$OS_VERSION-core-$ARCH-generic-$KAIROS_VERSION
ARG BASE_IMAGE=$KAIROS_BASE_IMAGE_URL/$BASE_IMAGE_TAG
ELSE IF [ "$OS_DISTRIBUTION" = "rhel" ] || [ "$OS_DISTRIBUTION" = "sles" ]
# Check for default value for rhel
ARG BASE_IMAGE
END
IF [[ "$BASE_IMAGE" =~ "nvidia-jetson-agx-orin" ]]
ARG IS_JETSON=true
END
ARG STYLUS_BASE=$SPECTRO_PUB_REPO/edge/stylus-framework-linux-$ARCH:$PE_VERSION
ARG STYLUS_PACKAGE_BASE=$SPECTRO_PUB_REPO/edge/stylus-linux-$ARCH:$PE_VERSION
IF [ "$FIPS_ENABLED" = "true" ]
ARG BIN_TYPE=vertex
ARG CLI_IMAGE=$SPECTRO_PUB_REPO/edge/palette-edge-cli-fips-${TARGETARCH}:${PE_VERSION}
ELSE
ARG BIN_TYPE=palette
ARG CLI_IMAGE=$SPECTRO_PUB_REPO/edge/palette-edge-cli-${TARGETARCH}:${PE_VERSION}
END
IF [ "$CUSTOM_TAG" != "" ]
ARG IMAGE_TAG=$PE_VERSION-$CUSTOM_TAG
ELSE
ARG IMAGE_TAG=$PE_VERSION
END
ARG IMAGE_PATH=$IMAGE_REGISTRY/$IMAGE_REPO:$K8S_DISTRIBUTION-$K8S_VERSION-$IMAGE_TAG
alpine-all:
BUILD --platform=linux/amd64 --platform=linux/arm64 +alpine
alpine:
FROM alpine:$ALPINE_TAG
RUN apk add --no-cache bash curl jq ca-certificates upx
RUN update-ca-certificates
SAVE IMAGE --push gcr.io/spectro-dev-public/canvos/alpine:$ALPINE_TAG
build-all-images:
IF $FIPS_ENABLED
BUILD +build-provider-images-fips
ELSE
BUILD +build-provider-images
END
IF [ "$ARCH" = "arm64" ]
BUILD --platform=linux/arm64 +iso-image
BUILD --platform=linux/arm64 +iso
ELSE IF [ "$ARCH" = "amd64" ]
BUILD --platform=linux/amd64 +iso-image
BUILD --platform=linux/amd64 +iso
END
build-provider-images:
FROM $ALPINE_IMG
IF [ !-n "$K8S_DISTRIBUTION"]
RUN echo "K8S_DISTRIBUTION is not set. Please set K8S_DISTRIBUTION to kubeadm, kubeadm-fips, k3s, nodeadm, rke2 or canonical." && exit 1
END
IF [ "$IS_UKI" = "true" ]
ARG TARGET=uki-provider-image
ELSE
ARG TARGET=provider-image
END
IF [ "$K8S_VERSION" = "" ]
WORKDIR /workdir
COPY k8s_version.json k8s_version.json
ENV K8S_DISTRIBUTION=$K8S_DISTRIBUTION
RUN jq -r --arg key "$K8S_DISTRIBUTION" 'if .[$key] then .[$key][] else empty end' k8s_version.json > k8s_version.txt
FOR version IN $(cat k8s_version.txt)
BUILD +$TARGET --K8S_VERSION=$version
END
ELSE
BUILD +$TARGET --K8S_VERSION=$K8S_VERSION
END
build-provider-images-fips:
BUILD +build-provider-images
BASE_ALPINE:
COMMAND
COPY --if-exists certs/ /etc/ssl/certs/
RUN update-ca-certificates
iso-image-rootfs:
FROM --platform=linux/${ARCH} +iso-image
SAVE ARTIFACT --keep-ts --keep-own /. rootfs
uki-iso:
WORKDIR /build
COPY --platform=linux/${ARCH} +build-uki-iso/ .
SAVE ARTIFACT /build/* AS LOCAL ./build/
uki-provider-image:
FROM --platform=linux/${ARCH} +ubuntu
RUN apt-get update && apt-get install -y rsync
WORKDIR /
COPY --if-exists overlay/files/etc/ /etc/
IF [ -f /etc/logrotate.d/stylus.conf ]
RUN chmod 644 /etc/logrotate.d/stylus.conf
END
COPY (+third-party/luet --binary=luet) /usr/bin/luet
COPY +kairos-agent/kairos-agent /usr/bin/kairos-agent
COPY --platform=linux/${ARCH} +trust-boot-unpack/ /trusted-boot
COPY --keep-ts --platform=linux/${ARCH} +install-k8s/output/ /k8s
COPY --if-exists "$EDGE_CUSTOM_CONFIG" /oem/.edge_custom_config.yaml
COPY --if-exists +stylus-image/etc/kairos/80_stylus.yaml /etc/kairos/80_stylus.yaml
SAVE IMAGE --push $IMAGE_PATH
trust-boot-unpack:
COPY (+third-party/luet --binary=luet) /usr/bin/luet
COPY --platform=linux/${ARCH} +build-provider-trustedboot-image/ /image
RUN FILE="file:/$(find /image -type f -name "*.tar" | head -n 1)" && \
luet util unpack $FILE /trusted-boot
SAVE ARTIFACT /trusted-boot/*
stylus-image-pack:
COPY (+third-party/luet --binary=luet) /usr/bin/luet
COPY --keep-ts --platform=linux/${ARCH} +stylus-package-image/ /stylus
RUN cd stylus && tar -czf ../stylus.tar *
RUN luet util pack $STYLUS_BASE stylus.tar stylus-image.tar
SAVE ARTIFACT --keep-ts stylus-image.tar AS LOCAL ./build/
kairos-agent:
FROM --platform=linux/${ARCH} $BASE_IMAGE
SAVE ARTIFACT /usr/bin/kairos-agent /kairos-agent
install-k8s:
FROM --platform=linux/${ARCH} $ALPINE_IMG
DO +BASE_ALPINE
COPY (+third-party/luet --binary=luet) /usr/bin/luet
IF [ "$K8S_DISTRIBUTION" = "kubeadm" ] || [ "$K8S_DISTRIBUTION" = "kubeadm-fips" ] || [ "$K8S_DISTRIBUTION" = "nodeadm" ] || [ "$K8S_DISTRIBUTION" = "canonical" ]
ARG BASE_K8S_VERSION=$K8S_VERSION
ELSE IF [ "$K8S_DISTRIBUTION" = "k3s" ]
ARG K8S_DISTRIBUTION_TAG=$K3S_FLAVOR_TAG
ARG BASE_K8S_VERSION=$K8S_VERSION-$K8S_DISTRIBUTION_TAG
ELSE IF [ "$K8S_DISTRIBUTION" = "rke2" ]
ARG K8S_DISTRIBUTION_TAG=$RKE2_FLAVOR_TAG
ARG BASE_K8S_VERSION=$K8S_VERSION-$K8S_DISTRIBUTION_TAG
END
WORKDIR /output
IF [ "$ARCH" = "arm64" ]
LET LUET_REPO=luet-repo-arm
ELSE IF [ "$ARCH" = "amd64" ]
LET LUET_REPO=luet-repo-amd
END
RUN mkdir -p /etc/luet/repos.conf.d && \
luet repo add spectro --type docker --url $SPECTRO_LUET_REPO/$LUET_REPO --priority 1 -y
COPY --if-exists spectro-luet-auth.yaml spectro-luet-auth.yaml
RUN --no-cache if [ -f spectro-luet-auth.yaml ]; then cat spectro-luet-auth.yaml >> /etc/luet/repos.conf.d/spectro.yaml; fi
RUN --no-cache luet repo update
RUN luet install -y k8s/$K8S_DISTRIBUTION@$BASE_K8S_VERSION --system-target /output && luet cleanup
RUN rm -rf /output/var/cache/*
SAVE ARTIFACT --keep-ts /output/ .
build-uki-iso:
FROM --platform=linux/${ARCH} $OSBUILDER_IMAGE
ENV ISO_NAME=${ISO_NAME}
COPY overlay/files-iso/ /overlay/
COPY --if-exists +validate-user-data/user-data /overlay/config.yaml
COPY --platform=linux/${ARCH} +stylus-image-pack/stylus-image.tar /overlay/stylus-image.tar
COPY --platform=linux/${ARCH} (+third-party/luet --binary=luet) /overlay/luet
COPY --if-exists "$EDGE_CUSTOM_CONFIG" /overlay/.edge_custom_config.yaml
# Add content files (split if > 3GB)
COPY --if-exists content-*/*.zst /overlay/opt/spectrocloud/content/
RUN if [ -n "$(ls /overlay/opt/spectrocloud/content/*.zst 2>/dev/null)" ]; then \
for file in /overlay/opt/spectrocloud/content/*.zst; do \
split --bytes=3GB --numeric-suffixes "$file" /overlay/opt/spectrocloud/content/$(basename "$file")_part; \
done; \
rm -f /overlay/opt/spectrocloud/content/*.zst; \
fi
# Add cluster config (SPC) if provided
IF [ "$CLUSTERCONFIG" != "" ]
COPY --if-exists "$CLUSTERCONFIG" /overlay/opt/spectrocloud/clusterconfig/spc.tgz
END
# Add local-ui if provided (extract it)
COPY --if-exists local-ui.tar /overlay/opt/spectrocloud/
RUN if [ -f /overlay/opt/spectrocloud/local-ui.tar ]; then \
tar -xf /overlay/opt/spectrocloud/local-ui.tar -C /overlay/opt/spectrocloud && \
rm -f /overlay/opt/spectrocloud/local-ui.tar; \
fi
WORKDIR /build
COPY --platform=linux/${ARCH} --keep-own +iso-image-rootfs/rootfs /build/image
IF [ "$ARCH" = "arm64" ]
RUN CMD="/entrypoint.sh --name $ISO_NAME build-iso --date=false --overlay-iso /overlay dir:/build/image --output /iso/ --arch $ARCH" && \
if [ "$DEBUG" = "true" ]; then CMD="$CMD --debug"; else CMD="$CMD"; fi && \
$CMD
ELSE IF [ "$ARCH" = "amd64" ]
COPY secure-boot/enrollment/ secure-boot/private-keys/ secure-boot/public-keys/ /keys
RUN ls -liah /keys
RUN mkdir /iso
IF [ "$AUTO_ENROLL_SECUREBOOT_KEYS" = "true" ]
RUN enki --config-dir /config build-uki dir:/build/image --extend-cmdline "$CMDLINE" --overlay-iso /overlay --secure-boot-enroll force -t iso -d /iso -k /keys --boot-branding "$BRANDING"
ELSE
RUN enki --config-dir /config build-uki dir:/build/image --extend-cmdline "$CMDLINE" --overlay-iso /overlay -t iso -d /iso -k /keys --boot-branding "$BRANDING"
END
END
WORKDIR /iso
RUN mv /iso/*.iso $ISO_NAME.iso
SAVE ARTIFACT /iso/*
iso:
WORKDIR /build
IF [ "$IS_UKI" = "true" ]
COPY --platform=linux/${ARCH} +build-uki-iso/ .
ELSE
COPY --keep-ts --platform=linux/${ARCH} +build-iso/ .
END
SAVE ARTIFACT /build/* AS LOCAL ./build/
validate-user-data:
FROM --platform=linux/${TARGETARCH} $CLI_IMAGE
COPY --if-exists user-data /user-data
RUN chmod +x /usr/local/bin/palette-edge-cli;
RUN if [ -f /user-data ]; then \
/usr/local/bin/palette-edge-cli validate -f /user-data; \
else \
echo "user-data file does not exist."; \
fi
SAVE ARTIFACT --if-exists /user-data
build-iso:
FROM --platform=linux/${ARCH} $OSBUILDER_IMAGE
ENV ISO_NAME=${ISO_NAME}
COPY overlay/files-iso/ /overlay/
COPY --if-exists +validate-user-data/user-data /overlay/files-iso/config.yaml
COPY --if-exists "$EDGE_CUSTOM_CONFIG" /overlay/.edge_custom_config.yaml
# Generate grub.cfg based on FORCE_INTERACTIVE_INSTALL setting (without modifying source)
RUN if [ "$FORCE_INTERACTIVE_INSTALL" = "true" ]; then \
sed 's/{{DEFAULT_ENTRY}}/2/g' /overlay/boot/grub2/grub.cfg > /overlay/boot/grub2/grub.cfg.tmp && \
mv /overlay/boot/grub2/grub.cfg.tmp /overlay/boot/grub2/grub.cfg; \
else \
sed 's/{{DEFAULT_ENTRY}}/0/g' /overlay/boot/grub2/grub.cfg > /overlay/boot/grub2/grub.cfg.tmp && \
mv /overlay/boot/grub2/grub.cfg.tmp /overlay/boot/grub2/grub.cfg; \
fi
# Append Kairos debug flags to installer kernel cmdline when DEBUG is enabled
RUN if [ "$DEBUG" = "true" ]; then \
sed -i '/rd.immucore.sysrootwait/s/$/ rd.immucore.debug console=tty0 rd.debug/' /overlay/boot/grub2/grub.cfg; \
fi
# Add content files (split if > 3GB)
COPY --if-exists content-*/*.zst /overlay/opt/spectrocloud/content/
RUN if [ -n "$(ls /overlay/opt/spectrocloud/content/*.zst 2>/dev/null)" ]; then \
for file in /overlay/opt/spectrocloud/content/*.zst; do \
split --bytes=3GB --numeric-suffixes "$file" /overlay/opt/spectrocloud/content/$(basename "$file")_part; \
done; \
rm -f /overlay/opt/spectrocloud/content/*.zst; \
fi
# Add cluster config (SPC) if provided
IF [ "$CLUSTERCONFIG" != "" ]
COPY --if-exists "$CLUSTERCONFIG" /overlay/opt/spectrocloud/clusterconfig/spc.tgz
END
WORKDIR /build
COPY --platform=linux/${ARCH} --keep-ts --keep-own +iso-image-rootfs/rootfs /build/image
# Add local-ui if provided (extract it)
COPY --if-exists local-ui.tar /build/image/opt/spectrocloud/
RUN if [ -f /build/image/opt/spectrocloud/local-ui.tar ]; then \
tar -xf /build/image/opt/spectrocloud/local-ui.tar -C /build/image/opt/spectrocloud && \
rm -f /build/image/opt/spectrocloud/local-ui.tar; \
fi
IF [ "$ARCH" = "arm64" ]
RUN CMD="/entrypoint.sh --name $ISO_NAME build-iso --date=false --overlay-iso /overlay dir:/build/image --output /iso/ --arch $ARCH" && \
if [ "$DEBUG" = "true" ]; then CMD="$CMD --debug"; else CMD="$CMD"; fi && \
$CMD
ELSE IF [ "$ARCH" = "amd64" ]
RUN CMD="/entrypoint.sh --name $ISO_NAME build-iso --date=false --overlay-iso /overlay dir:/build/image --output /iso/ --arch x86_64" && \
if [ "$DEBUG" = "true" ]; then CMD="$CMD --debug"; else CMD="$CMD"; fi && \
$CMD
END
WORKDIR /iso
RUN sha256sum $ISO_NAME.iso > $ISO_NAME.iso.sha256
SAVE ARTIFACT --keep-ts /iso/*
### UKI targets
## Generate UKI keys
# Default Expiry 15 years
## earthly +uki-genkey --MY_ORG="ACME Corp" --EXPIRATION_IN_DAYS=5475
uki-genkey:
ARG MY_ORG="ACME Corp"
ARG EXPIRATION_IN_DAYS=5475
FROM --platform=linux/${ARCH} $OSBUILDER_IMAGE
IF [ "$UKI_BRING_YOUR_OWN_KEYS" = "false" ]
RUN --no-cache mkdir -p /custom-keys
COPY --if-exists secure-boot/exported-keys/ /custom-keys
IF [ "$INCLUDE_MS_SECUREBOOT_KEYS" = "false" ]
RUN --no-cache if [[ -f /custom-keys/KEK && -f /custom-keys/db ]]; then \
echo "Generating Secure Boot keys, including exported UEFI keys..." && \
/entrypoint.sh genkey "$MY_ORG" --custom-cert-dir /custom-keys --skip-microsoft-certs-I-KNOW-WHAT-IM-DOING --expiration-in-days $EXPIRATION_IN_DAYS -o /keys; else \
echo "Generating Secure Boot keys..." && \
/entrypoint.sh genkey "$MY_ORG" --skip-microsoft-certs-I-KNOW-WHAT-IM-DOING --expiration-in-days $EXPIRATION_IN_DAYS -o /keys; fi
ELSE
RUN --no-cache if [[ -f /custom-keys/KEK && -f /custom-keys/db ]]; then \
echo "Generating Secure Boot keys, including exported UEFI keys and Microsoft keys..." && \
/entrypoint.sh genkey "$MY_ORG" --custom-cert-dir /custom-keys --expiration-in-days $EXPIRATION_IN_DAYS -o /keys; else \
echo "Generating Secure Boot keys, including Microsoft keys..." && \
/entrypoint.sh genkey "$MY_ORG" --expiration-in-days $EXPIRATION_IN_DAYS -o /keys; fi
END
RUN --no-cache mkdir -p /private-keys
RUN --no-cache mkdir -p /public-keys
RUN --no-cache cd /keys; mv *.key tpm2-pcr-private.pem /private-keys
RUN --no-cache cd /keys; mv *.pem /public-keys
ELSE
COPY +uki-byok/ /keys
END
SAVE ARTIFACT --if-exists /keys AS LOCAL ./secure-boot/enrollment
IF [ "$UKI_BRING_YOUR_OWN_KEYS" = "false" ]
SAVE ARTIFACT --if-exists /private-keys AS LOCAL ./secure-boot/private-keys
SAVE ARTIFACT --if-exists /public-keys AS LOCAL ./secure-boot/public-keys
END
download-sbctl:
FROM $ALPINE_IMG
DO +BASE_ALPINE
RUN curl -Ls https://github.com/Foxboron/sbctl/releases/download/0.13/sbctl-0.13-linux-amd64.tar.gz | tar -xvzf - && mv sbctl/sbctl /usr/bin/sbctl
SAVE ARTIFACT /usr/bin/sbctl
uki-byok:
FROM +ubuntu
RUN apt-get update && apt-get install -y efitools curl
COPY +download-sbctl/sbctl /usr/bin/sbctl
COPY --if-exists secure-boot/exported-keys/ /exported-keys
COPY secure-boot/private-keys/ secure-boot/public-keys /keys
WORKDIR /keys
RUN sbctl import-keys \
--pk-key /keys/PK.key \
--pk-cert /keys/PK.pem \
--kek-key /keys/KEK.key \
--kek-cert /keys/KEK.pem \
--db-key /keys/db.key \
--db-cert /keys/db.pem
RUN sbctl create-keys
IF [ "$INCLUDE_MS_SECUREBOOT_KEYS" = "false" ]
RUN sbctl enroll-keys --export esl --yes-this-might-brick-my-machine
ELSE
RUN sbctl enroll-keys --export esl --yes-this-might-brick-my-machine --microsoft
END
RUN mkdir -p /output
RUN cp PK.esl /output/PK.esl 2>/dev/null
RUN cp KEK.esl /output/KEK.esl 2>/dev/null
RUN cp db.esl /output/db.esl 2>/dev/null
RUN if [ -f dbx.esl ]; then cp dbx.esl /output/dbx.esl; else touch /output/dbx.esl; fi
RUN [ -f /exported-keys/KEK ] && cat /exported-keys/KEK >> /output/KEK.esl || true
RUN [ -f /exported-keys/db ] && cat /exported-keys/db >> /output/db.esl || true
RUN [ -f /exported-keys/dbx ] && cat /exported-keys/dbx >> /output/dbx.esl || true
WORKDIR /output
RUN sign-efi-sig-list -c /keys/PK.pem -k /keys/PK.key PK PK.esl PK.auth
RUN sign-efi-sig-list -c /keys/PK.pem -k /keys/PK.key KEK KEK.esl KEK.auth
RUN sign-efi-sig-list -c /keys/KEK.pem -k /keys/KEK.key db db.esl db.auth
RUN sign-efi-sig-list -c /keys/KEK.pem -k /keys/KEK.key dbx dbx.esl dbx.auth
RUN sig-list-to-certs 'PK.esl' 'PK'
RUN sig-list-to-certs 'KEK.esl' 'KEK'
RUN sig-list-to-certs 'db.esl' 'db'
RUN cp PK-0.der PK.der 2>/dev/null
RUN cp KEK-0.der KEK.der 2>/dev/null
RUN cp db-0.der db.der 2>/dev/null
SAVE ARTIFACT /output/*
secure-boot-dirs:
FROM --platform=linux/${ARCH} ubuntu:latest
RUN mkdir -p --mode=0644 /secure-boot/enrollment
RUN mkdir -p --mode=0600 /secure-boot/exported-keys
RUN mkdir -p --mode=0600 /secure-boot/private-keys
RUN mkdir -p --mode=0644 /secure-boot/public-keys
COPY --if-exists --keep-ts secure-boot/enrollment/ /secure-boot/enrollment
COPY --if-exists --keep-ts secure-boot/exported-keys/ /secure-boot/exported-keys
COPY --if-exists --keep-ts secure-boot/private-keys/ /secure-boot/private-keys
COPY --if-exists --keep-ts secure-boot/public-keys/ /secure-boot/public-keys
RUN chmod 0600 /secure-boot/exported-keys
RUN chmod 0600 /secure-boot/private-keys
RUN chmod 0644 /secure-boot/public-keys
SAVE ARTIFACT --keep-ts /secure-boot AS LOCAL ./secure-boot
# Used to create the provider images. The --K8S_VERSION will be passed in the earthly build.
provider-image:
FROM --platform=linux/${ARCH} +base-image
# added PROVIDER_K8S_VERSION to fix missing image in ghcr.io/kairos-io/provider-*
ARG IMAGE_REPO
# Generic, version-agnostic kernel-header installer. Resolves the ABI-exact
# headers for the kernel shipped in the base image, falling back to Ubuntu's
# immutable snapshot archive when the live mirror has rotated the ABI out
# (see scripts/install-kernel-headers.sh). Used by both the kubeadm and the
# UPDATE_KERNEL paths below.
COPY scripts/install-kernel-headers.sh /tmp/install-kernel-headers.sh
RUN chmod 755 /tmp/install-kernel-headers.sh
IF [ "$K8S_DISTRIBUTION" = "kubeadm" ] || [ "$K8S_DISTRIBUTION" = "kubeadm-fips" ] || [ "$K8S_DISTRIBUTION" = "nodeadm" ]
ARG BASE_K8S_VERSION=$K8S_VERSION
IF [ "$OS_DISTRIBUTION" = "ubuntu" ] && [ "$ARCH" = "amd64" ] && [ "$K8S_DISTRIBUTION" = "kubeadm" ]
RUN /tmp/install-kernel-headers.sh
END
ELSE IF [ "$K8S_DISTRIBUTION" = "k3s" ]
ARG K8S_DISTRIBUTION_TAG=$K3S_FLAVOR_TAG
ARG BASE_K8S_VERSION=$K8S_VERSION-$K8S_DISTRIBUTION_TAG
ELSE IF [ "$K8S_DISTRIBUTION" = "rke2" ]
ARG K8S_DISTRIBUTION_TAG=$RKE2_FLAVOR_TAG
ARG BASE_K8S_VERSION=$K8S_VERSION-$K8S_DISTRIBUTION_TAG
END
IF [ "$UPDATE_KERNEL" = true ]
IF [ "$OS_DISTRIBUTION" = "ubuntu" ] && [ "$ARCH" = "amd64" ]
RUN /tmp/install-kernel-headers.sh
ELSE IF [ "$OS_DISTRIBUTION" = "opensuse-leap" ] || [ "$OS_DISTRIBUTION" = "sles" ]
RUN zypper --non-interactive ref && \
kernel=$(printf '%s\n' /lib/modules/* | xargs -n1 basename | sort -V | tail -1) && \
echo "kernel module: $kernel" && \
version=$(echo $kernel | sed 's/-default$//') && \
echo "kernel version: $version" && \
if ! zypper --non-interactive install --no-recommends kernel-default-devel-$version; then \
echo "Exact kernel-default-devel-$version not found, searching for closest match..."; \
match=$(zypper se -s kernel-default-devel | awk -F'|' '/kernel-default-devel/ && $3 ~ /^ *[0-9]/ {gsub(/^ +| +$/,"",$3); if (index($3,"'"$version"'")==1) print $3}' | sort -Vr | head -n1); \
if [ -n "$match" ]; then \
echo "Trying to install kernel-default-devel-$match"; \
zypper --non-interactive install --no-recommends kernel-default-devel-$match || echo "Failed to install kernel-default-devel-$match"; \
else \
echo "No matching kernel-default-devel package found, trying generic kernel-devel"; \
zypper --non-interactive install --no-recommends kernel-devel || echo "kernel development packages not available, continuing without them"; \
fi \
fi
ELSE IF [ "$OS_DISTRIBUTION" = "rhel" ]
RUN yum clean all && yum makecache && \
# Enable additional repositories that might contain kernel-devel packages
yum-config-manager --enable ubi-8-baseos-rpms ubi-8-appstream-rpms ubi-8-codeready-builder-rpms && \
# Try to add EPEL repository for additional packages
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm || echo "EPEL repo not available" && \
yum makecache && \
kernel=$(printf '%s\n' /lib/modules/* | xargs -n1 basename | sort -V | tail -1) && echo "kernel version: $kernel" && \
if ! yum install -y kernel-devel-$kernel; then \
echo "kernel-devel-$kernel not available, trying alternative packages" && \
yum install -y kernel-devel || \
echo "Trying to install from different source..." && \
yum install -y gcc make || echo "kernel development packages not available, continuing without them"; \
fi
END
END
COPY --if-exists overlay/files/etc/ /etc/
IF [ -f /etc/logrotate.d/stylus.conf ]
RUN chmod 644 /etc/logrotate.d/stylus.conf
END
COPY --platform=linux/${ARCH} +kairos-provider-image/ /
COPY +stylus-image/etc/kairos/branding /etc/kairos/branding
COPY --if-exists +stylus-image/etc/kairos/80_stylus.yaml /etc/kairos/80_stylus.yaml
COPY +stylus-image/oem/stylus_config.yaml /etc/kairos/branding/stylus_config.yaml
COPY +stylus-image/etc/elemental/config.yaml /etc/elemental/config.yaml
COPY --if-exists "$EDGE_CUSTOM_CONFIG" /oem/.edge_custom_config.yaml
IF [ "$IS_UKI" = "true" ]
COPY +internal-slink/slink /usr/bin/slink
COPY --keep-ts +install-k8s/output/ /k8s
RUN slink --source /k8s/ --target /opt/k8s
RUN rm -f /usr/bin/slink
RUN rm -rf /k8s
RUN ln -sf /opt/spectrocloud/bin/agent-provider-stylus /usr/local/bin/agent-provider-stylus
ELSE
COPY --keep-ts +install-k8s/output/ /
END
RUN rm -f /etc/ssh/ssh_host_* /etc/ssh/moduli
COPY (+third-party/etcdctl --binary=etcdctl) /usr/bin/
RUN touch /etc/machine-id \
&& chmod 444 /etc/machine-id
IF [ "$OS_DISTRIBUTION" = "ubuntu" ] && [ "$K8S_DISTRIBUTION" = "nodeadm" ]
RUN apt-get update -y && apt-get install -y gnupg && \
/opt/nodeadmutil/bin/nodeadm install -p iam-ra $K8S_VERSION && \
/opt/nodeadmutil/bin/nodeadm install -p ssm $K8S_VERSION && \
# ssm-setup-cli fails to install amazon-ssm-agent via snap after downloading the package
# due to PID 1 not being systemd, so we do it manually
find /opt/ssm -type f -name "amazon-ssm-agent.deb" -exec sudo dpkg -i {} \; && \
apt-get remove gnupg -y && apt autoremove -y && \
# nodeadm installs these bins under /usr/local/bin, which gets wiped during kairos upgrade,
# so we install to /usr/bin and provider-nodeadm symlinks to /usr/local/bin
mv /usr/local/bin/aws-iam-authenticator /usr/bin && \
mv /usr/local/bin/aws_signing_helper /usr/bin && \
# nodeadm is hardcoded to check for snap.amazon-ssm-agent.amazon-ssm-agent.service, so we alias it
cp /lib/systemd/system/amazon-ssm-agent.service /etc/systemd/system/snap.amazon-ssm-agent.amazon-ssm-agent.service
END
IF $TWO_NODE
# Install postgresql 16
IF [ "$OS_DISTRIBUTION" = "ubuntu" ] && [ "$ARCH" = "amd64" ]
RUN apt-get update && \
echo "tzdata tzdata/Areas select Etc" | debconf-set-selections && \
echo "tzdata tzdata/Zones/Etc select UTC" | debconf-set-selections && \
DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl && \
install -d /usr/share/postgresql-common/pgdg && \
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc && \
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql-16 postgresql-contrib-16 iputils-ping
ELSE IF [ "$OS_DISTRIBUTION" = "opensuse-leap" ] && [ "$ARCH" = "amd64" ]
RUN zypper --non-interactive --quiet addrepo --refresh -p 90 http://download.opensuse.org/repositories/server:database:postgresql/openSUSE_Tumbleweed/ PostgreSQL && \
zypper --gpg-auto-import-keys ref && \
zypper install -y postgresql-16 postgresql-server-16 postgresql-contrib iputils
END
# Install kine
RUN mkdir -p /opt/spectrocloud/bin && \
curl -L https://github.com/k3s-io/kine/releases/download/v${KINE_VERSION}/kine-amd64 | install -m 755 /dev/stdin /opt/spectrocloud/bin/kine
# Ensure psql works ootb for the postgres user
RUN su postgres -c 'echo "export PERL5LIB=/usr/share/perl/5.34:/etc/perl:/usr/lib/x86_64-linux-gnu/perl5/5.34:/usr/share/perl5:/usr/lib/x86_64-linux-gnu/perl/5.34:/usr/lib/x86_64-linux-gnu/perl-base" > ~/.bash_profile'
# Ensure psql waits for the network to be online
RUN sed -i 's/After=network.target/After=network-online.target/' /lib/systemd/system/postgresql@.service
# Disable psql by default, Stylus will enable it when it needs it
RUN systemctl disable postgresql
END
# Build-time helper only; don't ship it in the final image.
RUN rm -f /tmp/install-kernel-headers.sh
SAVE IMAGE --push $IMAGE_PATH
provider-image-rootfs:
FROM --platform=linux/${ARCH} +provider-image
SAVE ARTIFACT --keep-own /. rootfs
build-provider-trustedboot-image:
FROM --platform=linux/${ARCH} $OSBUILDER_IMAGE
COPY --platform=linux/${ARCH} --keep-own +provider-image-rootfs/rootfs /build/image
COPY secure-boot/enrollment/ secure-boot/private-keys/ secure-boot/public-keys/ /keys
RUN /entrypoint.sh build-uki dir:/build/image -t container -d /output -k /keys --boot-branding "Palette eXtended Kubernetes Edge"
SAVE ARTIFACT /output/* AS LOCAL ./trusted-boot/
stylus-image:
FROM --platform=linux/${ARCH} $STYLUS_BASE
SAVE ARTIFACT --keep-ts --keep-own ./*
# SAVE ARTIFACT /etc/kairos/branding
# SAVE ARTIFACT /etc/elemental/config.yaml
# SAVE ARTIFACT /oem/stylus_config.yaml
stylus-package-image:
FROM --platform=linux/${ARCH} $STYLUS_PACKAGE_BASE
SAVE ARTIFACT --keep-ts --keep-own ./*
kairos-provider-image:
IF [ "$K8S_DISTRIBUTION" = "kubeadm" ]
ARG PROVIDER_BASE=$SPECTRO_PUB_REPO/edge/kairos-io/provider-kubeadm:$KUBEADM_PROVIDER_VERSION
ELSE IF [ "$K8S_DISTRIBUTION" = "kubeadm-fips" ]
ARG PROVIDER_BASE=$SPECTRO_PUB_REPO/edge/kairos-io/provider-kubeadm:$KUBEADM_PROVIDER_VERSION
ELSE IF [ "$K8S_DISTRIBUTION" = "k3s" ]
ARG PROVIDER_BASE=$SPECTRO_PUB_REPO/edge/kairos-io/provider-k3s:$K3S_PROVIDER_VERSION
ELSE IF [ "$K8S_DISTRIBUTION" = "rke2" ] && $FIPS_ENABLED
ARG PROVIDER_BASE=$SPECTRO_PUB_REPO/edge/kairos-io/provider-rke2:$RKE2_PROVIDER_VERSION
ELSE IF [ "$K8S_DISTRIBUTION" = "rke2" ]
ARG PROVIDER_BASE=$SPECTRO_PUB_REPO/edge/kairos-io/provider-rke2:$RKE2_PROVIDER_VERSION
ELSE IF [ "$K8S_DISTRIBUTION" = "nodeadm" ]
ARG PROVIDER_BASE=$SPECTRO_PUB_REPO/edge/kairos-io/provider-nodeadm:$NODEADM_PROVIDER_VERSION
ELSE IF [ "$K8S_DISTRIBUTION" = "canonical" ]
ARG PROVIDER_BASE=$SPECTRO_PUB_REPO/edge/kairos-io/provider-canonical:$CANONICAL_PROVIDER_VERSION
END
FROM --platform=linux/${ARCH} $PROVIDER_BASE
SAVE ARTIFACT ./*
# base build image used to create the base image for all other image types
base-image:
FROM DOCKERFILE --build-arg BASE=$BASE_IMAGE \
--build-arg OS_DISTRIBUTION=$OS_DISTRIBUTION --build-arg OS_VERSION=$OS_VERSION \
--build-arg HTTP_PROXY=$HTTP_PROXY --build-arg HTTPS_PROXY=$HTTPS_PROXY \
--build-arg NO_PROXY=$NO_PROXY --build-arg DRBD_VERSION=$DRBD_VERSION .
IF [ "$IS_JETSON" = "true" ]
COPY cloudconfigs/mount.yaml /etc/kairos/mount.yaml
END
IF [ "$IS_UKI" = "true" ]
# create empty boot directory to support services like longhorn which require /boot
COPY cloudconfigs/80_stylus_uki.yaml /etc/kairos/80_stylus_uki.yaml
END
IF [ "$IS_MAAS" = "true" ]
COPY cloudconfigs/80_stylus_maas.yaml /system/oem/80_stylus_maas.yaml
END
# OS == Ubuntu
IF [ "$OS_DISTRIBUTION" = "ubuntu" ] && [ "$ARCH" = "amd64" ]
IF [ "$UBUNTU_PRO_ATTACH" = "true" ]
# The token is mounted via Earthly's secret store as an env var
# that lives only for the duration of this RUN. It is materialized
# into an attach-config file using the shell builtin `printf`, so
# the value never appears in any process argv (/proc/<pid>/cmdline)
# or in docker build history. The env var is unset and the temp
# file removed before the RUN exits, so nothing about the token
# survives in the resulting layer. If `--secret UBUNTU_PRO_KEY`
# is not supplied, Earthly aborts before this RUN is invoked.
RUN --secret UBUNTU_PRO_KEY \
sed -i '/^[[:space:]]*$/d' /etc/os-release && \
apt-get update && apt-get install -y snapd && \
umask 077 && \
printf 'token: %s\n' "$UBUNTU_PRO_KEY" > /tmp/.pro-attach.yaml && \
unset UBUNTU_PRO_KEY && \
pro attach --attach-config /tmp/.pro-attach.yaml && \
rm -f /tmp/.pro-attach.yaml
END
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends kbd zstd vim iputils-ping bridge-utils curl tcpdump ethtool rsyslog logrotate -y
LET APT_UPGRADE_FLAGS="-y"
IF [ "$UPDATE_KERNEL" = "false" ]
RUN if dpkg -l "linux-image-generic-hwe-$OS_VERSION" > /dev/null; then apt-mark hold "linux-image-generic-hwe-$OS_VERSION" "linux-headers-generic-hwe-$OS_VERSION" "linux-generic-hwe-$OS_VERSION" ; fi && \
if dpkg -l linux-image-generic > /dev/null; then apt-mark hold linux-image-generic linux-headers-generic linux-generic; fi
ELSE
SET APT_UPGRADE_FLAGS="-y --with-new-pkgs"
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -y linux-image-generic-hwe-$OS_VERSION
END
# https://www.reddit.com/r/Ubuntu/comments/1bd46t3/i_did_an_aptget_updateupgrade_but_the_kernel/
# tldr: apt-get upgrade -y doesn't install new packages, so we need to use --with-new-pkgs
IF [ "$IS_UKI" = "false" ]
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get upgrade $APT_UPGRADE_FLAGS && \
apt-get install --no-install-recommends -y \
util-linux \ # Provides essential utilities for Linux systems, including disk management tools.
parted \ # Used for creating and managing disk partitions.
cloud-guest-utils \ # Includes utilities for cloud environments, such as resizing root partitions.
gawk \ # Required for text processing and scripting in build scripts.
fdisk \ # A partitioning tool for managing disk partitions.
gdisk \ # GPT partitioning tool, complementing fdisk for modern systems.
e2fsprogs \ # Provides tools for managing ext2/ext3/ext4 file systems.
dosfstools \ # Utilities for creating and checking FAT file systems.
rsync \ # Used for efficient file synchronization and transfer.
cryptsetup-bin \ # Provides tools for setting up encrypted disks.
udev && \ # Device manager for the Linux kernel, required for managing device nodes.
latest_kernel=$(printf '%s\n' /lib/modules/* | xargs -n1 basename | sort -V | tail -1 | awk -F '-' '{print $1"-"$2}') && \
if [ "$FIPS_ENABLED" = "true" ]; then \
# When FIPS is enabled, we need to remove any non-FIPS kernel packages (e.g., 5.15 HWE) to avoid conflicts.
# However, some kernel packages may be held (apt-mark hold), which causes `apt-get purge` to fail with:
# "E: Held packages were changed and -y was used without --allow-change-held-packages."
# To fix this, we first unhold all matching non-FIPS and non-latest kernel packages before purging them.
# This ensures a clean, FIPS-only environment without apt resolver errors.
for pkg in $(dpkg -l | awk '/^.i\s+linux-(image|headers|modules)/ {print $2}' \
| grep -v "$latest_kernel" | grep -v fips); do \
apt-mark unhold "$pkg" || true; \
done && \
apt-get purge -y $(dpkg -l | awk '/^.i\s+linux-(image|headers|modules)/ {print $2}' | grep -v "${latest_kernel}" | grep -v fips); \
else \
apt-get purge -y $(dpkg -l | awk '/^ii\s+linux-(image|headers|modules)/ {print $2}' | grep -v "${latest_kernel}"); \
fi && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*
RUN kernel=$(ls /boot/vmlinuz-* | tail -n1) && \
ln -sf "${kernel#/boot/}" /boot/vmlinuz
# Skip dracut when FIPS is enabled - the Dockerfile will include custom dracut modules.fips
IF [ "$FIPS_ENABLED" = "false" ]
RUN kernel=$(printf '%s\n' /lib/modules/* | xargs -n1 basename | sort -V | tail -1) && \
dracut -f "/boot/initrd-${kernel}" "${kernel}" && \
ln -sf "initrd-${kernel}" /boot/initrd
END
RUN kernel=$(printf '%s\n' /lib/modules/* | xargs -n1 basename | sort -V | tail -1) && \
depmod -a "${kernel}"
RUN if [ ! -f /usr/bin/grub2-editenv ]; then \
ln -s /usr/sbin/grub-editenv /usr/bin/grub2-editenv; \
fi
END
IF [ "$CIS_HARDENING" = "true" ]
COPY cis-harden/harden.sh /tmp/harden.sh
RUN /tmp/harden.sh && rm /tmp/harden.sh
END
IF [ "$UBUNTU_PRO_ATTACH" = "true" ]
# Detach the entitlement, then scrub any on-disk traces. `pro` may
# echo or log token fragments under /var/log/ubuntu-advantage* and
# leave private state under /var/lib/ubuntu-advantage/private; we
# truncate those so the resulting image carries no residue.
RUN pro detach --assume-yes && \
find /var/log -maxdepth 3 -name 'ubuntu-advantage*' -type f -exec sh -c ': > "$1"' _ {} \; 2>/dev/null || true && \
rm -rf /var/lib/ubuntu-advantage/private 2>/dev/null || true && \
rm -f /tmp/.pro-attach.yaml 2>/dev/null || true
END
# OS == Opensuse
ELSE IF [ "$OS_DISTRIBUTION" = "opensuse-leap" ] && [ "$ARCH" = "amd64" ]
# Enable or Disable Kernel Updates
IF [ "$UPDATE_KERNEL" = "false" ]
RUN zypper al kernel-de*
END
RUN zypper refresh && zypper update -y
IF [ -e "/usr/bin/dracut" ]
RUN --no-cache kernel=$(printf '%s\n' /lib/modules/* | xargs -n1 basename | sort -V | tail -1) && depmod -a "${kernel}"
RUN --no-cache kernel=$(printf '%s\n' /lib/modules/* | xargs -n1 basename | sort -V | tail -1) && dracut -f "/boot/initrd-${kernel}" "${kernel}" && ln -sf "initrd-${kernel}" /boot/initrd
END
RUN zypper install -y zstd vim iputils bridge-utils curl ethtool tcpdump && \
zypper cc && \
zypper clean
END
IF [ "$OS_DISTRIBUTION" = "opensuse-leap" ] || [ "$OS_DISTRIBUTION" = "sles" ]
RUN zypper install -y apparmor-parser apparmor-profiles rsyslog logrotate
RUN zypper cc && \
zypper clean
RUN if [ ! -e /usr/bin/apparmor_parser ]; then cp /sbin/apparmor_parser /usr/bin/apparmor_parser; fi
END
IF [ "$OS_DISTRIBUTION" = "rhel" ]
RUN yum install -y openssl rsyslog logrotate
END
DO +OS_RELEASE --OS_VERSION=$KAIROS_VERSION
DO +KAIROS_RELEASE --OS_VERSION=$OS_VERSION --OS_DISTRIBUTION=$OS_DISTRIBUTION --ARCH=$ARCH --IS_MAAS=$IS_MAAS
RUN find /var/cache -mindepth 1 -maxdepth 1 ! -name 'cracklib' -exec rm -rf {} + && \
journalctl --vacuum-size=1K && \
rm -rf /etc/machine-id && \
rm -rf /var/lib/dbus/machine-id
RUN touch /etc/machine-id && \
chmod 444 /etc/machine-id
RUN rm /tmp/* -rf
IF [ "$IS_UKI" != "true" ]
IF [ "$DISABLE_SELINUX" = "true" ]
# Ensure SElinux gets disabled
RUN if grep "security=selinux" /etc/cos/bootargs.cfg > /dev/null; then sed -i 's/security=selinux //g' /etc/cos/bootargs.cfg; fi &&\
if grep "selinux=1" /etc/cos/bootargs.cfg > /dev/null; then sed -i 's/selinux=1/selinux=0/g' /etc/cos/bootargs.cfg; fi
END
# Enable cgroup v2 (unified hierarchy) — required for Kubernetes >= 1.31 (deprecated in 1.31, hard-fail in 1.35)
RUN if ! grep -Fq "systemd.unified_cgroup_hierarchy=1" /etc/cos/bootargs.cfg; then \
sed -i 's|\(set baseCmd="[^"]*\)"|\1 systemd.unified_cgroup_hierarchy=1"|' /etc/cos/bootargs.cfg; \
fi
END
KAIROS_RELEASE:
COMMAND
ARG OS_VERSION
ARG OS_DISTRIBUTION
ARG ARCH
ARG IS_MAAS=false
# Build dynamic KAIROS_IMAGE_LABEL based on OS version, arch, and MAAS flag
# Format: {OS_VERSION}-standard-{ARCH}-generic{MAAS_SUFFIX}
# For Ubuntu, OS_VERSION is the major version (e.g., "22"), so we format it as "22.04"
IF [ "$OS_DISTRIBUTION" = "ubuntu" ]
IF [ "$OS_VERSION" = "22" ] || [ "$OS_VERSION" = "20" ]
IF [ "$IS_MAAS" = "true" ]
LET KAIROS_IMAGE_LABEL="${OS_VERSION}.04-standard-${ARCH}-generic-maas"
ELSE
LET KAIROS_IMAGE_LABEL="${OS_VERSION}.04-standard-${ARCH}-generic"
END
ELSE
IF [ "$IS_MAAS" = "true" ]
LET KAIROS_IMAGE_LABEL="${OS_VERSION}-standard-${ARCH}-generic-maas"
ELSE
LET KAIROS_IMAGE_LABEL="${OS_VERSION}-standard-${ARCH}-generic"
END
END
ELSE
IF [ "$IS_MAAS" = "true" ]
LET KAIROS_IMAGE_LABEL="${OS_VERSION}-standard-${ARCH}-generic-maas"
ELSE
LET KAIROS_IMAGE_LABEL="${OS_VERSION}-standard-${ARCH}-generic"
END
END
RUN if [ -f /etc/kairos-release ]; then \
sed -i 's/^KAIROS_NAME=.*/KAIROS_NAME="kairos-core-'"$OS_DISTRIBUTION"'-'"$OS_VERSION"'"/' /etc/kairos-release; \
sed -i '/^KAIROS_IMAGE_LABEL=/d' /etc/kairos-release; \
echo 'KAIROS_IMAGE_LABEL="'"$KAIROS_IMAGE_LABEL"'"' >> /etc/kairos-release; \
else \
echo 'KAIROS_NAME="kairos-core-'"$OS_DISTRIBUTION"'-'"$OS_VERSION"'"' >> /etc/kairos-release; \
echo 'KAIROS_IMAGE_LABEL="'"$KAIROS_IMAGE_LABEL"'"' >> /etc/kairos-release; \
fi
# Used to build the installer image. The installer ISO will be created from this.
iso-image:
FROM --platform=linux/${ARCH} +base-image
ARG IS_CLOUD_IMAGE=false
ARG IMAGE_REGISTRY
IF [ "$IS_UKI" = "false" ]
COPY --keep-ts --platform=linux/${ARCH} +stylus-image/ /
ELSE
COPY --keep-ts --platform=linux/${ARCH} +stylus-image/ /
RUN find /opt/spectrocloud/bin/. ! -name 'agent-provider-stylus' -type f -exec rm -f {} +
RUN rm -f /usr/bin/luet
END
COPY overlay/files/ /
IF [ "$IS_CLOUD_IMAGE" = "true" ]
COPY cloud-images/workaround/grubmenu.cfg /etc/kairos/branding/grubmenu.cfg
COPY cloud-images/workaround/custom-post-reset.yaml /system/oem/custom-post-reset.yaml
RUN mkdir -p /opt/spectrocloud/scripts
COPY cloudconfigs/cloud-content.sh /opt/spectrocloud/scripts/cloud-content.sh
RUN chmod 755 /opt/spectrocloud/scripts/cloud-content.sh
COPY cloudconfigs/cloud-extend-persistent.sh /opt/spectrocloud/scripts/cloud-extend-persistent.sh
RUN chmod 755 /opt/spectrocloud/scripts/cloud-extend-persistent.sh
# Add local-ui if provided (extract it directly to the image)
# Note: local-ui is handled directly in the iso-image build, not via content partition
COPY --if-exists local-ui.tar /opt/spectrocloud/
RUN if [ -f /opt/spectrocloud/local-ui.tar ]; then \
tar -xf /opt/spectrocloud/local-ui.tar -C /opt/spectrocloud && \
rm -f /opt/spectrocloud/local-ui.tar; \
fi
END
IF [ -f /etc/logrotate.d/stylus.conf ]
RUN chmod 644 /etc/logrotate.d/stylus.conf
END
# For MAAS builds, install maas-content.sh script and handle local-ui
IF [ "$IS_MAAS" = "true" ]
RUN mkdir -p /opt/spectrocloud/scripts
COPY cloudconfigs/maas-content.sh /opt/spectrocloud/scripts/maas-content.sh
RUN chmod 755 /opt/spectrocloud/scripts/maas-content.sh
# Add local-ui if provided (extract it directly to the image)
COPY --if-exists local-ui.tar /opt/spectrocloud/
RUN if [ -f /opt/spectrocloud/local-ui.tar ]; then \
tar -xf /opt/spectrocloud/local-ui.tar -C /opt/spectrocloud && \
rm -f /opt/spectrocloud/local-ui.tar; \
fi
END
RUN rm -f /etc/ssh/ssh_host_* /etc/ssh/moduli
RUN touch /etc/machine-id \
&& chmod 444 /etc/machine-id
# Only push image if not building for MAAS (MAAS uses local image via --load)
IF [ "$IS_MAAS" = "false" ]
SAVE IMAGE palette-installer-image:$IMAGE_TAG
ELSE
SAVE IMAGE index.docker.io/library/palette-installer-image:latest
END
cloud-image:
ARG IS_CLOUD_IMAGE=true