From 422bfa0c9507a8932eb2e5274222d035a597e025 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Thu, 27 Jul 2023 11:29:13 +0200 Subject: [PATCH 1/2] Restore cross-arch build of arm images By playing with the buildarch and having separated luet repo files we can install the proper artifacts for each arch AND also teh arm64 artifacts for arm images under x86 Signed-off-by: Itxaka --- tools-image/Dockerfile | 29 +++++++++++++++++----- tools-image/arm/boards/odroid_c2.sh | 14 +++-------- tools-image/build-arm-image.sh | 4 +-- tools-image/luet-amd64.yaml | 15 +++++++++++ tools-image/{luet.yaml => luet-arm64.yaml} | 11 +------- tools-image/prepare_arm_images.sh | 4 +-- 6 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 tools-image/luet-amd64.yaml rename tools-image/{luet.yaml => luet-arm64.yaml} (57%) diff --git a/tools-image/Dockerfile b/tools-image/Dockerfile index 3c2e562..b62f63c 100644 --- a/tools-image/Dockerfile +++ b/tools-image/Dockerfile @@ -20,14 +20,19 @@ RUN go build \ -o /usr/bin/enki FROM opensuse/leap:$LEAP_VERSION as default -COPY --from=luet /usr/bin/luet /usr/bin/luet -ENV LUET_NOLOCK=true -ENV TMPDIR=/tmp -COPY luet.yaml /etc/luet/luet.yaml - RUN zypper ref && zypper dup -y ## ISO+ Arm image + Netboot + cloud images Build depedencies RUN zypper ref && zypper in -y bc qemu-tools jq cdrtools docker git curl gptfdisk kpartx sudo xfsprogs parted util-linux-systemd e2fsprogs curl util-linux udev rsync grub2 dosfstools grub2-x86_64-efi squashfs mtools xorriso lvm2 zstd +COPY --from=luet /usr/bin/luet /usr/bin/luet +ENV LUET_NOLOCK=true +ENV TMPDIR=/tmp +ARG BUILDARCH +# copy both arches +COPY luet-arm64.yaml /tmp/luet-arm64.yaml +COPY luet-amd64.yaml /tmp/luet-amd64.yaml +# Set the default luet config to the current build arch +RUN mkdir -p /etc/luet/ +RUN cp /tmp/luet-${BUILDARCH}.yaml /etc/luet/luet.yaml ## Live CD artifacts RUN luet install -y livecd/grub2 --system-target /grub2 @@ -39,11 +44,23 @@ RUN luet install -y firmware/u-boot-rpi64 firmware/raspberrypi-firmware firmware ## PineBook64 Pro RUN luet install -y arm-vendor-blob/u-boot-rockchip --system-target /pinebookpro/u-boot - ## RAW images +## Odroid fw +RUN luet install -y firmware/odroid-c2 --system-target /firmware/odroid-c2 + +## RAW images for current arch RUN luet install -y static/grub-efi --system-target /raw/grub RUN luet install -y static/grub-config --system-target /raw/grubconfig RUN luet install -y static/grub-artifacts --system-target /raw/grubartifacts +## RAW images for arm64 +# Luet will install this artifacts from the current arch repo, so in x86 it will +# get them from the x86 repo and we want it to do it from the arm64 repo, even on x86 +# so we use the arm64 luet config and use that to install those on x86 +# This is being used by the prepare_arm_images.sh and build-arch-image.sh scripts +RUN luet install --config /tmp/luet-arm64.yaml -y static/grub-efi --system-target /arm/raw/grub +RUN luet install --config /tmp/luet-arm64.yaml -y static/grub-config --system-target /arm/raw/grubconfig +RUN luet install --config /tmp/luet-arm64.yaml -y static/grub-artifacts --system-target /arm/raw/grubartifacts + # remove luet tmp files. Side effect of setting the system-target is that it treats it as a root fs # so temporal files are stored in each dir RUN rm -Rf /grub2/var/tmp diff --git a/tools-image/arm/boards/odroid_c2.sh b/tools-image/arm/boards/odroid_c2.sh index 0c626ba..c83c020 100755 --- a/tools-image/arm/boards/odroid_c2.sh +++ b/tools-image/arm/boards/odroid_c2.sh @@ -7,15 +7,7 @@ if [ -z "$image" ]; then exit 1 fi -if [ ! -e "$WORKDIR/luet.yaml" ]; then - ls -liah $WORKDIR - echo "No valid config file" - cat "$WORKDIR/luet.yaml" - exit 1 -fi - -sudo luet install --config $WORKDIR/luet.yaml -y --system-target $WORKDIR firmware/odroid-c2 # conv=notrunc ? -dd if=$WORKDIR/bl1.bin.hardkernel of=$image conv=fsync bs=1 count=442 -dd if=$WORKDIR/bl1.bin.hardkernel of=$image conv=fsync bs=512 skip=1 seek=1 -dd if=$WORKDIR/u-boot.odroidc2 of=$image conv=fsync bs=512 seek=97 \ No newline at end of file +dd if=/firmware/odroid-c2/bl1.bin.hardkernel of=$image conv=fsync bs=1 count=442 +dd if=/firmware/odroid-c2/bl1.bin.hardkernel of=$image conv=fsync bs=512 skip=1 seek=1 +dd if=/firmware/odroid-c2/u-boot.odroidc2 of=$image conv=fsync bs=512 seek=97 \ No newline at end of file diff --git a/tools-image/build-arm-image.sh b/tools-image/build-arm-image.sh index b59893b..3689540 100755 --- a/tools-image/build-arm-image.sh +++ b/tools-image/build-arm-image.sh @@ -321,9 +321,9 @@ cp -rfv ${STATEDIR}/cOS/active.img ${RECOVERY}/cOS/recovery.img tune2fs -L ${SYSTEM_LABEL} ${RECOVERY}/cOS/recovery.img # Install real grub config to recovery -cp -rfv /raw/grubconfig/* $RECOVERY +cp -rfv /arm/raw/grubconfig/* $RECOVERY mkdir -p $RECOVERY/grub2/fonts -cp -rfv /raw/grubartifacts/* $RECOVERY/grub2 +cp -rfv /arm/raw/grubartifacts/* $RECOVERY/grub2 mv $RECOVERY/grub2/*pf2 $RECOVERY/grub2/fonts sync diff --git a/tools-image/luet-amd64.yaml b/tools-image/luet-amd64.yaml new file mode 100644 index 0000000..5f4ccf6 --- /dev/null +++ b/tools-image/luet-amd64.yaml @@ -0,0 +1,15 @@ +general: + debug: false + spinner_charset: 9 +logging: + enable_emoji: false +repositories: + - name: "kairos" + description: "kairos repository" + type: "docker" + cached: true + enable: true + priority: 2 + urls: + - "quay.io/kairos/packages" + reference: 20230718103103-repository.yaml \ No newline at end of file diff --git a/tools-image/luet.yaml b/tools-image/luet-arm64.yaml similarity index 57% rename from tools-image/luet.yaml rename to tools-image/luet-arm64.yaml index 45ef076..8bb1222 100644 --- a/tools-image/luet.yaml +++ b/tools-image/luet-arm64.yaml @@ -4,20 +4,11 @@ general: logging: enable_emoji: false repositories: - - name: "kairos" - description: "kairos repository" - type: "docker" - arch: amd64 - cached: true - priority: 2 - urls: - - "quay.io/kairos/packages" - reference: 20230718103103-repository.yaml - name: "kairos-arm64" description: "kairos repository arm64" type: "docker" - arch: arm64 cached: true + enable: true priority: 2 urls: - "quay.io/kairos/packages-arm64" diff --git a/tools-image/prepare_arm_images.sh b/tools-image/prepare_arm_images.sh index 6002f6f..e33db47 100755 --- a/tools-image/prepare_arm_images.sh +++ b/tools-image/prepare_arm_images.sh @@ -93,9 +93,9 @@ cp -rfv ${STATEDIR}/cOS/active.img ${RECOVERY}/cOS/recovery.img tune2fs -L ${SYSTEM_LABEL} ${RECOVERY}/cOS/recovery.img # Install real grub config to recovery -cp -rfv /raw/grubconfig/* $RECOVERY +cp -rfv /arm/raw/grubconfig/* $RECOVERY mkdir -p $RECOVERY/grub2/fonts -cp -rfv /raw/grubartifacts/* $RECOVERY/grub2 +cp -rfv /arm/raw/grubartifacts/* $RECOVERY/grub2 mv $RECOVERY/grub2/*pf2 $RECOVERY/grub2/fonts dd if=/dev/zero of=recovery_partition.img bs=1M count=$recovery_size From 758e97a77548af38ee194e9b6a7bc0e2ba9faf46 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Thu, 27 Jul 2023 11:44:27 +0200 Subject: [PATCH 2/2] Fix tests for cleanstack Is no longer provided by enki but by the sdk, so tests do not need to be here anymore Signed-off-by: Itxaka --- tools-image/enki/pkg/utils/utils_test.go | 74 ------------------------ tools-image/luet-amd64.yaml | 2 +- 2 files changed, 1 insertion(+), 75 deletions(-) diff --git a/tools-image/enki/pkg/utils/utils_test.go b/tools-image/enki/pkg/utils/utils_test.go index fa19baf..6aa84c5 100644 --- a/tools-image/enki/pkg/utils/utils_test.go +++ b/tools-image/enki/pkg/utils/utils_test.go @@ -291,78 +291,4 @@ var _ = Describe("Utils", Label("utils"), func() { Expect(err).To(HaveOccurred()) }) }) - Describe("CleanStack", Label("CleanStack"), func() { - var cleaner *utils.CleanStack - BeforeEach(func() { - cleaner = utils.NewCleanStack() - }) - It("Adds a callback to the stack and pops it", func() { - var flag bool - callback := func() error { - flag = true - return nil - } - Expect(cleaner.Pop()).To(BeNil()) - cleaner.Push(callback) - poppedJob := cleaner.Pop() - Expect(poppedJob).NotTo(BeNil()) - poppedJob() - Expect(flag).To(BeTrue()) - }) - It("On Cleanup runs callback stack in reverse order", func() { - result := "" - callback1 := func() error { - result = result + "one " - return nil - } - callback2 := func() error { - result = result + "two " - return nil - } - callback3 := func() error { - result = result + "three " - return nil - } - cleaner.Push(callback1) - cleaner.Push(callback2) - cleaner.Push(callback3) - cleaner.Cleanup(nil) - Expect(result).To(Equal("three two one ")) - }) - It("On Cleanup keeps former error and all callbacks are executed", func() { - err := errors.New("Former error") - count := 0 - callback := func() error { - count++ - if count == 2 { - return errors.New("Cleanup Error") - } - return nil - } - cleaner.Push(callback) - cleaner.Push(callback) - cleaner.Push(callback) - err = cleaner.Cleanup(err) - Expect(count).To(Equal(3)) - Expect(err.Error()).To(ContainSubstring("Former error")) - }) - It("On Cleanup error reports first error and all callbacks are executed", func() { - var err error - count := 0 - callback := func() error { - count++ - if count >= 2 { - return errors.New(fmt.Sprintf("Cleanup error %d", count)) - } - return nil - } - cleaner.Push(callback) - cleaner.Push(callback) - cleaner.Push(callback) - err = cleaner.Cleanup(err) - Expect(count).To(Equal(3)) - Expect(err.Error()).To(ContainSubstring("Cleanup error 2")) - Expect(err.Error()).To(ContainSubstring("Cleanup error 3")) - }) - }) }) diff --git a/tools-image/luet-amd64.yaml b/tools-image/luet-amd64.yaml index 5f4ccf6..e2aeb4a 100644 --- a/tools-image/luet-amd64.yaml +++ b/tools-image/luet-amd64.yaml @@ -12,4 +12,4 @@ repositories: priority: 2 urls: - "quay.io/kairos/packages" - reference: 20230718103103-repository.yaml \ No newline at end of file + reference: 20230718103103-repository.yaml