From 6de35e0fc2605287b1f3cfc44b1cea9fb050e2ba Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 8 Feb 2025 13:39:59 -0500 Subject: [PATCH] Rework build system further - Move everything related to base/ into that directory, including Containerfile - Introduce `bootc-base-image-rebuild-self` that can be used to resynthesize the base image, and it has docs. - Rework the standard image to put its build instructions in usr/share/doc/bootc-image-standard to serve as a reference Signed-off-by: Colin Walters --- .gitlab-ci.yml | 4 +- Containerfile | 46 +++------- Containerfile.base => base/Containerfile | 30 +++---- base/Makefile | 2 + base/bootc-base-image-rebuild-self | 17 ++++ base/bootc-base-image-rebuild-self.md | 83 +++++++++++++++++++ .../bootc-image-standard/packages-aarch64.txt | 0 .../packages-excluded.txt | 0 .../bootc-image-standard/packages-ppc64le.txt | 0 .../packages-recommended-minimal.txt | 0 .../bootc-image-standard/packages-x86_64.txt | 0 .../doc/bootc-image-standard/packages.txt | 0 .../doc/bootc-image-standard/stage-clean | 5 ++ .../doc/bootc-image-standard/stage-install | 29 +++++++ 14 files changed, 165 insertions(+), 51 deletions(-) rename Containerfile.base => base/Containerfile (53%) create mode 100644 base/Makefile create mode 100755 base/bootc-base-image-rebuild-self create mode 100644 base/bootc-base-image-rebuild-self.md rename packages-aarch64.txt => usr/share/doc/bootc-image-standard/packages-aarch64.txt (100%) rename packages-excluded.txt => usr/share/doc/bootc-image-standard/packages-excluded.txt (100%) rename packages-ppc64le.txt => usr/share/doc/bootc-image-standard/packages-ppc64le.txt (100%) rename packages-recommended-minimal.txt => usr/share/doc/bootc-image-standard/packages-recommended-minimal.txt (100%) rename packages-x86_64.txt => usr/share/doc/bootc-image-standard/packages-x86_64.txt (100%) rename packages.txt => usr/share/doc/bootc-image-standard/packages.txt (100%) create mode 100755 usr/share/doc/bootc-image-standard/stage-clean create mode 100755 usr/share/doc/bootc-image-standard/stage-install diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 52bb706..db5c0e3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,8 +16,10 @@ build: set -xeuo pipefail curl -L --fail -o /etc/yum.repos.d/coreos-continuous.repo https://copr.fedorainfracloud.org/coprs/g/CoreOS/continuous/repo/fedora-42/group_CoreOS-continuous-fedora-42.repo dnf -y install rpm-ostree - buildah build "${hostbuildopts[@]}" -f Containerfile.base --no-cache --security-opt=label=disable --cap-add=all --device /dev/fuse -t ${IMAGE_PREFIX}-base:tmp . + cd base + buildah build "${hostbuildopts[@]}" -f Containerfile --no-cache --security-opt=label=disable --cap-add=all --device /dev/fuse -t ${IMAGE_PREFIX}-base:tmp . # Rechunk rpm-ostree experimental compose build-chunked-oci --bootc --format-version=1 \ --from=${IMAGE_PREFIX}-base:tmp --output containers-storage:${IMAGE_PREFIX}-base + cd .. buildah build "${hostbuildopts[@]}" -f Containerfile --no-cache --from ${IMAGE_PREFIX}-base -t ${IMAGE_PREFIX}-standard:tmp . diff --git a/Containerfile b/Containerfile index 49bd956..0341637 100644 --- a/Containerfile +++ b/Containerfile @@ -1,42 +1,18 @@ -# This generates the default base image. +# This generates the "standard" base image, deriving from the minimal base. # This is a local reference by default because we haven't shipped this image yet. FROM localhost/fedora-bootc:base -# Drop our package sets into /usr/share/doc, so that other things can parse it -COPY packages*.txt /usr/share/doc/fedora-bootc/ -# Overlay our defaults +# Copy in our configuration and build scripts. Most of the heavy lifting +# is in `stage-install` which we emit into /usr/share/doc so it can be +# used as a reference in other images. COPY usr/ /usr/ RUN < +RUN ... +``` + +As of recently, it is possible to e.g. swap the kernel +and other fundamental components as part of default derivation. + +## Understanding the base image content + +Most, but not all content from the base image comes from RPMs. +There is some additional non-RPM content, as well as postprocessing +that operates on the filesystem root. At the current +time the implementation of the base image build uses `rpm-ostree`, +but this is considered an implementation detail subject to change. + +## Rebuilding from externally controlled content + +Some use cases want even more control - for example, +as an organization deploying a bootc system, I may want to ensure +the base image version carries a set of packages at +exactly specific versions (perhaps defined by a lockfile, +or an rpm-md repository). There are many tools which +manage snapshots of yum (rpm-md) repositories. + +The `/usr/libexec/bootc-base-image-rebuild-self` which is +included in the base image is designed to enable this +level of control. + +## Using bootc-base-image-rebuild-self + +This tool takes just two arguments: + +- A "repository configuration root" which should have an `/etc/yum.repos.d` + that defines the input RPM content. +- A path to the target root filesystem which will be generated + +### Implementation + +The current implementation uses `rpm-ostree` on a manifest (treefile) +embedded in the container image itself. The set of packages installed +is currently not configurable; however it is quite minimal and can +easily be customized further as we will see below. + +The build tooling is designed to support "cross builds"; the +repository root could e.g. be CentOS Stream 10, while the +builder root is Fedora or RHEL, etc. In other words, one given +base image can be used as a "builder" to produce another +using different RPMs. + +### Example: Generate a new image using CentOS Stream 10 content from RHEL + +FROM quay.io/centos/centos:stream10 as repos + +FROM registry.redhat.io/rhel10/rhel-bootc:10 as builder +RUN --mount=type=bind,from=repos,src=/,dst=/repos,rw /usr/libexec/bootc-base-image-rebuild-self /repos /target-rootfs + +# This container image uses the "artifact pattern"; it has some +# basic configuration we expect to apply to multiple container images. +FROM quay.io/exampleos/baseconfig@sha256:.... as baseconfig + +FROM scratch +COPY --from=builder /target-rootfs/ / +# Now we make other arbitrary changes. Copy our systemd units and +# other tweaks from the baseconfig container image. +COPY --from=baseconfig /usr/ /usr/ +RUN <