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

Rely less on earthly and more on pure docker instructions #1939

Closed
wants to merge 1 commit into from
Closed
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
80 changes: 23 additions & 57 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ base-image:
ARG FLAVOR
ARG VARIANT
ARG KAIROS_VERSION
ARG BUILD_INITRD="true"
ARG TARGETARCH
# HWE is used to determine if the HWE kernel should be installed on Ubuntu LTS.
# The default value is empty, which means the HWE kernel WILL be installed
Expand Down Expand Up @@ -338,8 +337,7 @@ base-image:
# Includes overlay/files
# We only support non-fips for now, they are built separatedly and pushed for other to consume, not used in our workflows
COPY (+framework/framework --FLAVOR=generic) /
# Avoid to accidentally push keys generated by package managers
RUN rm -rf /etc/ssh/ssh_host_*


# Set proper os-release file with all the info
IF [ "$KAIROS_VERSION" = "" ]
Expand All @@ -354,9 +352,6 @@ base-image:

DO +OSRELEASE --HOME_URL=https://github.com/kairos-io/kairos --BUG_REPORT_URL=https://github.com/kairos-io/kairos/issues --GITHUB_REPO=kairos-io/kairos --VARIANT=${VARIANT} --FLAVOR=${FLAVOR} --OS_ID=${OS_ID} --OS_LABEL=${OS_LABEL} --OS_NAME=${OS_NAME} --OS_REPO=${OS_REPO} --OS_VERSION=${OS_VERSION}

# Fully remove machine-id, it will be generated on first boot
RUN rm -rf /etc/machine-id

# TEST KAIROS-AGENT FROM BRANCH
ARG KAIROS_AGENT_DEV
ARG KAIROS_AGENT_DEV_BRANCH=main
Expand Down Expand Up @@ -407,63 +402,34 @@ base-image:
--OS_VERSION=${OS_VERSION}
END

# Avoid to accidentally push keys generated by package managers
RUN rm -rf /etc/ssh/ssh_host_*
# Fully remove machine-id, it will be generated on first boot
RUN rm -rf /etc/machine-id

IF [[ "$FLAVOR" =~ ^ubuntu* ]]
# compress firmware
RUN find /usr/lib/firmware -type f -execdir zstd --rm -9 {} \+
# compress modules
RUN find /usr/lib/modules -type f -name "*.ko" -execdir zstd --rm -9 {} \+
END

IF [ "$BUILD_INITRD" = "true" ]
IF [ "$FLAVOR" = "debian" ]
RUN rm -rf /boot/initrd.img-*
END


RUN --no-cache kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}"

IF [ -f "/usr/bin/dracut" ]
# Regenerate initrd if necessary
RUN --no-cache kernel=$(ls /lib/modules | head -n1) && dracut -f "/boot/initrd-${kernel}" "${kernel}" && ln -sf "initrd-${kernel}" /boot/initrd
END

IF [ -f "/sbin/mkinitfs" ]
# Proper config files with immucore and custom initrd should already be in there installed by framework
RUN --no-cache kernel=$(ls /lib/modules | head -n1) && mkinitfs -o /boot/initrd $kernel
END
END

# Set /boot/vmlinuz pointing to our kernel so kairos-agent can use it
# https://github.com/kairos-io/kairos-agent/blob/0288fb111bc568a1bfca59cb09f39302220475b6/pkg/elemental/elemental.go#L548 q
IF [ "$FLAVOR" = "fedora" ] || [ "$FLAVOR" = "rockylinux" ] || [ "$FLAVOR" = "almalinux" ]
RUN rm -rf /boot/initramfs-*
END

IF [ ! -e "/boot/vmlinuz" ]
IF [ -e "/boot/vmlinuz-lts" ]
# Alpine provides the kernel under this name
RUN ln -sf /boot/vmlinuz-lts /boot/vmlinuz
END
IF [ -e "/boot/vmlinuz-rpi4" ]
# Alpine-rpi provides the kernel under this name
RUN ln -sf /boot/vmlinuz-rpi4 /boot/vmlinuz
END
# If it's an ARM flavor, we want a symlink here from zImage/Image
# Check that its not a symlink already or grub will fail!
IF [ -e "/boot/Image" ] && [ ! -L "/boot/Image" ]
RUN ln -sf Image /boot/vmlinuz
ELSE IF [ -e "/boot/zImage" ]
IF [ ! -L "/boot/zImage" ]
RUN ln -sf zImage /boot/vmlinuz
ELSE
RUN kernel=$(ls /boot/zImage-* | head -n1) && if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi
END
ELSE
# Debian has vmlinuz-VERSION
RUN kernel=$(ls /boot/vmlinuz-* | head -n1) && if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi
RUN kernel=$(ls /boot/Image-* | head -n1) && if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi
END
END
# Delete not needed initramfs files
RUN rm -rf /boot/initrd.img-* || true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always do and not fail if its not there, we dont care

RUN rm -rf /boot/initramfs-* || true
RUN --no-cache kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}"
# Recreate initrd and link it to /boot/initrd
RUN --no-cache if [ -f "/usr/bin/dracut" ]; then kernel=$(ls /lib/modules | head -n1) && dracut -f "/boot/initrd-${kernel}" "${kernel}" && ln -sf "initrd-${kernel}" /boot/initrd;fi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check in time for initrd builder

RUN --no-cache if [ -f "/sbin/mkinitfs" ]; then kernel=$(ls /lib/modules | head -n1) && mkinitfs -o /boot/initrd $kernel; fi

# Create a symlink to the kernel to /boot/vmlinuz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do all the linking here if the sources exists

RUN --no-cache if [ -e "/boot/vmlinuz-lts" ]; then ln -sf /boot/vmlinuz-lts /boot/vmlinuz; fi
RUN --no-cache if [ -e "/boot/vmlinuz-rpi4" ]; then ln -sf /boot/vmlinuz-rpi4 /boot/vmlinuz; fi
RUN --no-cache if [ -e " /boot/Image" ]; then ln -sf /boot/Image /boot/vmlinuz; fi
RUN --no-cache if [ -e "/boot/zImage" ]; then ln -sf /boot/zImage /boot/vmlinuz; fi
RUN --no-cache kernel=$(ls /boot/zImage-* 2> /dev/null | head -n1) && if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi
RUN --no-cache kernel=$(ls /boot/vmlinuz-* 2> /dev/null | head -n1) && if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi
RUN --no-cache kernel=$(ls /boot/Image-* 2> /dev/null | head -n1) && if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi
Comment on lines +426 to +432
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually we will have to move these to the dockerfiles and it would be good to remember which line is there for which flavor. Maybe keep that information around as comments? We can always look back in this commit but I'm afraid more changes in the future might make it hard to discover.

It should be too long until we move them though, so maybe it's fine as it is. I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it? Or should we do ALL the lines and then fail if there is no link created?

I mean, I worked them so they wont run unless it finds the file so they are mostly non-op and only one triggers.

This means we can add all of them to all the dockerfiles and they will work everywhere. Would be nicer if it was some script or whatever, but as pure docker goes, this should be valid for all the flavors in existance and should not fail anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can wrap these to a script you are right. But were does this script belong? Maybe it should be in the framework image. If we don't want it in the final images, we can just delete it in the dockerfiles after running it.


RUN rm -rf /tmp/*

Expand All @@ -484,7 +450,7 @@ image-rootfs:
SAVE ARTIFACT --keep-own /. rootfs

uki-artifacts:
FROM +base-image --BUILD_INITRD=false
FROM +base-image
RUN /usr/bin/immucore version
RUN ln -s /usr/bin/immucore /init
RUN mkdir -p /oem # be able to mount oem under here if found
Expand Down
Loading