Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore cross-arch build of arm images #80

Merged
merged 2 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions tools-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 3 additions & 11 deletions tools-image/arm/boards/odroid_c2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
4 changes: 2 additions & 2 deletions tools-image/build-arm-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 0 additions & 74 deletions tools-image/enki/pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})
})
15 changes: 15 additions & 0 deletions tools-image/luet-amd64.yaml
Original file line number Diff line number Diff line change
@@ -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
mauromorales marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 1 addition & 10 deletions tools-image/luet.yaml → tools-image/luet-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tools-image/prepare_arm_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down