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

adds support for building hook kernel #3471

Merged
merged 2 commits into from
Aug 28, 2024
Merged

Conversation

jaxesn
Copy link
Member

@jaxesn jaxesn commented Jul 12, 2024

Issue #, if available:

Description of changes:

This adds support for building the hook os kernel to our build tooling. Currently linuxkit pulls the kernel built from upstream via https://github.com/tinkerbell/hook/tree/main/kernel. This ensures we can build and update the kernel when necessary as well as giving us the ability to include additional/different drives in our default builds based on what we see with customers.

The main difference between "our" build and upstreams will be that we will use AL23 whereas upstream uses debian. The new git_tag for hook is 0.9.0. This new version has made significant changes to the kernel build dockerfile. The builds-kernel-from-al2.patch patches patches just the first layer in the docker file from debian to al23. There are 3 files, keys.asc and the two kernel config files, which are copied from the upstream clone before building the kernel image.

A way to add additional kernel options has also been added and is documented in the readme. For now, I am adding the cisco drivers based on customer feedback we have recieved.

In addition to the hook upgrade, we are introducing the ability to embedded the need action container images into the local docker cache so that these images do not need pulled at runtime. Most of the new patches come from @jacobweinstock's work upstream and will go away when hook is released with this change. We use this new upstream process to docker pull/save/load to create a hook-embedded image which containers the /var/lib/docker folder with the action images + tink-worker.

A new batch-build.yml is introduced so that we can build the amd image on an amd host and the arm image on an arm host. AL2, nor Al23, provide cross compilation like upstream gets from debian. This is a pretty standard we have followed for other complex builds that require arch specific binary or image builds.

The kernel-config target is added as a helper for customers who need to add or change the kernel config for their specific hardware, similar to upstrea which we currently reference in our docs

The kernel version is set to the latest 5.10.x version we are using from upstream. Automation will be added to keep this version updated.

TODO:

  • add new private ecr repos for newly introduced images hook-runc hook-containerd hook-ip hook-mdev hook-dind hook-embedded
  • change codebuild job to be batch
  • update release019 and release020 branches to have batch build spec for this project similar to Add buildspec file for tink project #3568
  • Automate kernel patch version upgrades

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@eks-distro-bot
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@eks-distro-bot eks-distro-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 12, 2024
@jaxesn jaxesn force-pushed the jgw/hook-kernel branch 2 times, most recently from bc622e3 to 28140d1 Compare July 15, 2024 20:44
@eks-distro-bot eks-distro-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 15, 2024
@jaxesn jaxesn force-pushed the jgw/hook-kernel branch from 28140d1 to e21b840 Compare July 15, 2024 20:47
@eks-distro-bot eks-distro-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 15, 2024
- apt -o "Dpkg::Use-Pty=0" -y install curl xz-utils gnupg2 flex bison libssl-dev libelf-dev bc libncurses-dev kmod \
- crossbuild-essential-amd64 crossbuild-essential-arm64 && \
- apt -o "Dpkg::Use-Pty=0" -y clean
+ARG BASE_IMAGE
Copy link
Member Author

Choose a reason for hiding this comment

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

here is what the final Dockerfile looks like:

ARG BASE_IMAGE
FROM ${BASE_IMAGE} as kernel-source-unpacked-amd64

ARG DEFCONFIG
ENV KERNEL_ARCH=x86_64
ENV INPUT_DEFCONFIG=${DEFCONFIG}-${KERNEL_ARCH}
ENV KERNEL_OUTPUT_IMAGE=arch/${KERNEL_ARCH}/boot/bzImage

ARG BASE_IMAGE
FROM ${BASE_IMAGE} as kernel-source-unpacked-arm64

ARG DEFCONFIG
ENV KERNEL_ARCH=aarch64
ENV INPUT_DEFCONFIG=${DEFCONFIG}-${KERNEL_ARCH}
ENV KERNEL_OUTPUT_IMAGE=arch/${KERNEL_ARCH}/boot/bzImage

ARG TARGETARCH
FROM kernel-source-unpacked-${TARGETARCH} as kernel-source-unpacked

RUN set -x && yum -y update && \
        yum -y install bc bison elfutils-libelf-devel flex gcc gzip kmod make ncurses-devel openssl-devel perl tar xz && \
        yum clean all && \
        rm -rf /var/cache/yum

ARG KERNEL_MAJOR_V
ARG KERNEL_VERSION
ARG KERNEL_SOURCE=https://www.kernel.org/pub/linux/kernel/${KERNEL_MAJOR_V}/linux-${KERNEL_VERSION}.tar.xz
ARG KERNEL_SHA256_SUMS=https://www.kernel.org/pub/linux/kernel/${KERNEL_MAJOR_V}/sha256sums.asc
ARG KERNEL_PGP2_SIGN=https://www.kernel.org/pub/linux/kernel/${KERNEL_MAJOR_V}/linux-${KERNEL_VERSION}.tar.sign

# PGP keys: 589DA6B1 (greg@kroah.com) & 6092693E (autosigner@kernel.org) & 00411886 (torvalds@linux-foundation.org)
COPY /keys.asc /keys.asc

# Download and verify kernel
RUN set -x &&  \
    curl -fsSLO ${KERNEL_SHA256_SUMS} && \
    gpg2 -q --import keys.asc && \
    gpg2 --verify sha256sums.asc && \
    KERNEL_SHA256=$(grep linux-${KERNEL_VERSION}.tar.xz sha256sums.asc | cut -d ' ' -f 1) && \
    [ -f linux-${KERNEL_VERSION}.tar.xz ] || curl -fsSLO ${KERNEL_SOURCE} && \
    echo "${KERNEL_SHA256}  linux-${KERNEL_VERSION}.tar.xz" | sha256sum -c - && \
    xz -T 0 -d linux-${KERNEL_VERSION}.tar.xz && \
    curl -fsSLO ${KERNEL_PGP2_SIGN} && \
    gpg2 --verify linux-${KERNEL_VERSION}.tar.sign linux-${KERNEL_VERSION}.tar && \
    cat linux-${KERNEL_VERSION}.tar | tar --absolute-names -x && mv /linux-${KERNEL_VERSION} /linux


FROM kernel-source-unpacked as kernel-with-config

ARG INPUT_DEFCONFIG
ARG KERNEL_ARCH
ARG KERNEL_CROSS_COMPILE

ENV KERNEL_ARCH=${KERNEL_ARCH}
ENV ARCH=${KERNEL_ARCH}
ENV CROSS_COMPILE=${KERNEL_CROSS_COMPILE}
ENV KCFLAGS="-fdiagnostics-color=always -fno-pie"
ENV KBUILD_BUILD_USER="hook"
ENV KBUILD_BUILD_HOST="tinkerbell"

# Copy just the defconfig needed for this build
WORKDIR /linux
COPY /configs/${INPUT_DEFCONFIG} /linux/.config

# Kernel config; copy the correct defconfig as .config, and run olddefconfig
RUN set -x && make "ARCH=${KERNEL_ARCH}" olddefconfig

# Use this stage to run kernel configuration tasks like menuconfig / savedefconfig etc with:
#   docker buildx build --load --progress=plain --build-arg KERNEL_VERSION=5.10.212 --build-arg KERNEL_SERIES=5.10.y -t hook-kernel:builder --target kernel-configurator .
#   docker run -it -v "$(pwd)":/out-config hook-kernel:builder
# Otherwise, since this stage is not referenced anywhere during normal build, it is completely skipped
FROM kernel-with-config as kernel-configurator
VOLUME /host


FROM kernel-with-config AS kernel-build

ARG KERNEL_OUTPUT_IMAGE

RUN mkdir /out

RUN sed -i 's/#define COMMAND_LINE_SIZE 2048/#define COMMAND_LINE_SIZE 4096/' arch/x86/include/asm/setup.h

# Kernel build. ENVs in previous stages are inherited; thus ARCH, CROSS_COMPILE, KCFLAGS, KBUILD_BUILD_USER, KBUILD_BUILD_HOST are available
RUN set -x && \
    echo "Cross compiler: ${CROSS_COMPILE}" && \
    make -j"$(getconf _NPROCESSORS_ONLN)" && \
    cp ${KERNEL_OUTPUT_IMAGE} /out/kernel && \
    cp System.map /out


# Modules, from lib/modules go into kernel.tar (will be extracted in root filesystem by linuxkit)
RUN set -x && \
    make -s -j"$(getconf _NPROCESSORS_ONLN)" INSTALL_MOD_PATH=/tmp/kernel-modules modules_install && \
    ( DVER=$(basename $(find /tmp/kernel-modules/lib/modules/ -mindepth 1 -maxdepth 1)) && \
      cd /tmp/kernel-modules/lib/modules/$DVER && \
      rm -f build source ) && \
    ( cd /tmp/kernel-modules && tar cf /out/kernel.tar . )

# For arches that have DTB's, eg arm64; they go separately into dtbs.tar; for arches that don't (x86), an empty dtbs.tar is created
RUN set -x && \
    mkdir -p /tmp/kernel-dtb && \
    case "$KERNEL_ARCH" in \
    arm64) \
        make -s -j"$(getconf _NPROCESSORS_ONLN)" INSTALL_DTBS_PATH=/tmp/kernel-dtb dtbs_install; \
        ;; \
    esac && \
     ( cd /tmp/kernel-dtb && tar czvf /out/dtbs.tar.gz . )

FROM scratch
ENTRYPOINT []
CMD []
WORKDIR /
COPY --from=kernel-build /out/* /

@jaxesn jaxesn force-pushed the jgw/hook-kernel branch from e21b840 to c279899 Compare July 15, 2024 21:06
@jaxesn jaxesn marked this pull request as ready for review July 15, 2024 21:06
@jaxesn
Copy link
Member Author

jaxesn commented Jul 15, 2024

/hold

@eks-distro-bot eks-distro-bot added do-not-merge/hold size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 15, 2024
@jaxesn jaxesn force-pushed the jgw/hook-kernel branch 5 times, most recently from 4d37f0b to 38c83fc Compare July 16, 2024 20:27
@jaxesn
Copy link
Member Author

jaxesn commented Jul 16, 2024

/test hook-tooling-presubmit-arm64

@aws aws deleted a comment from eks-distro-bot Jul 16, 2024
@jaxesn jaxesn force-pushed the jgw/hook-kernel branch from 8f8bf39 to b6c6797 Compare July 22, 2024 20:57
@jaxesn jaxesn force-pushed the jgw/hook-kernel branch 3 times, most recently from d03ccf4 to 5469c79 Compare August 15, 2024 17:05
@eks-distro-bot eks-distro-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 23, 2024
@jaxesn jaxesn force-pushed the jgw/hook-kernel branch 4 times, most recently from b84286d to 4ad4663 Compare August 28, 2024 14:54
@jaxesn jaxesn changed the title WIP: adds support for building hook kernel adds support for building hook kernel Aug 28, 2024
@eks-distro-bot eks-distro-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed do-not-merge/work-in-progress size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 28, 2024
@jacobweinstock
Copy link
Member

/approve

@abhay-krishna
Copy link
Member

/lgtm
/approve

@jaxesn
Copy link
Member Author

jaxesn commented Aug 28, 2024

/unhold

@eks-distro-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abhay-krishna, jacobweinstock

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [abhay-krishna,jacobweinstock]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@eks-distro-bot eks-distro-bot merged commit a141784 into aws:main Aug 28, 2024
89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants