# Builder image for the Alloy installer ISO.
#
# Derived FROM the Alloy image rather than from stock Fedora, so the live
# initramfs is built against exactly the kernel and modules that ship. A
# builder on its own base would produce an initramfs for a different kernel
# and fail at boot with no obvious cause.
#
# The extra packages live here instead of in the image itself because none
# of them belong on an installed machine: dracut-live drives a squashfs
# root, and xorriso only ever assembles ISOs.
ARG BASE=localhost/alloy:local
FROM ${BASE}

# dnf is only usable here because this stage is thrown away; the shipped
# image disables the third-party repos it layered from at build time, so
# nothing below reaches for them.
#
# The GRUB packages are the one architecture-specific part: Fedora names them
# for the EFI target, and the x64 pair does not exist on an aarch64 host. The
# builder is always native (it is derived FROM the Alloy image, so it carries
# that image's kernel), so `uname -m` is the right question to ask.
RUN case "$(uname -m)" in \
      x86_64)  GRUB_EFI="grub2-efi-x64 grub2-efi-x64-modules" ;; \
      aarch64) GRUB_EFI="grub2-efi-aa64 grub2-efi-aa64-modules" ;; \
      *) echo "no GRUB packages known for $(uname -m)" >&2; exit 1 ;; \
    esac \
 && dnf install -y \
      dracut-live \
      xorriso \
      squashfs-tools \
      $GRUB_EFI \
      grub2-tools \
      grub2-tools-extra \
      dosfstools \
      mtools \
      rsync \
 && dnf clean all

# Give dracut somewhere for /root to point.
#
# dracut preserves /root whenever it is a symlink, unconditionally and from
# its own main script rather than from any module or config file:
#
#     dracut.sh:1949   [ -L /root ]
#     dracut.sh:1950   inst_symlink /root
#
# In the bootc layout /root is a symlink to var/roothome, /var is populated
# at install time rather than in a container image, and so dracut-install
# resolved the link to /var/roothome, found nothing, and printed
# "ERROR: installing '/root'" followed by a FAILED line, on every single
# build. It was harmless — the initramfs was complete and the live boot
# worked — which is exactly the problem: a build whose normal output
# contains dracut[E] and ERROR teaches whoever reads it to skim past both,
# and the next real failure arrives in a log already full of them.
#
# One empty directory ends it. The cost is an empty /root in the live
# initramfs, which is where a root home belongs anyway. Fixed here in the
# builder rather than in the shipped image, because it is the builder's own
# filesystem dracut walks and the installed system already gets its
# /var/roothome from bootc.
RUN mkdir -p /var/roothome

COPY build/make-iso.sh /usr/local/bin/make-iso
RUN chmod +x /usr/local/bin/make-iso

ENTRYPOINT ["/usr/local/bin/make-iso"]
