@@ -10,50 +10,37 @@ ARG base=quay.io/centos-bootc/centos-bootc:stream10
1010FROM scratch as src
1111COPY . /src
1212
13+ # And this image only captures contrib/packaging separately
14+ # to ensure we have more precise cache hits.
15+ FROM scratch as packaging
16+ COPY contrib/packaging /
17+
1318FROM $base as base
14- # We could inject other content here
19+ # Mark this as a test image (moved from --label build flag to fix layer caching)
20+ LABEL bootc.testimage="1"
1521
1622# This image installs build deps, pulls in our source code, and installs updated
1723# bootc binaries in /out. The intention is that the target rootfs is extracted from /out
1824# back into a final stage (without the build deps etc) below.
19- FROM base as build
25+ FROM base as buildroot
2026# Flip this off to disable initramfs code
2127ARG initramfs=1
22- # This installs our package dependencies, and we want to cache it independently of the rest.
23- # Basically we don't want changing a .rs file to blow out the cache of packages. So we only
24- # copy files necessary
25- COPY contrib/packaging /tmp/packaging
26- RUN <<EORUN
27- set -xeuo pipefail
28- . /usr/lib/os-release
29- case $ID in
30- centos|rhel) dnf config-manager --set-enabled crb;;
31- fedora) dnf -y install dnf-utils 'dnf5-command(builddep)' ;;
32- esac
33- # Handle version skew, xref https://gitlab.com/redhat/centos-stream/containers/bootc/-/issues/1174
34- dnf -y distro-sync ostree{,-libs} systemd
35- # Install base build requirements
36- dnf -y builddep /tmp/packaging/bootc.spec
37- # And extra packages
38- grep -Ev -e '^#' /tmp/packaging/fedora-extra.txt | xargs dnf -y install
39- rm /tmp/packaging -rf
40- EORUN
28+ # Version for RPM build (optional, computed from git in Justfile)
29+ ARG pkgversion=
30+ # This installs our buildroot, and we want to cache it independently of the rest.
31+ # Basically we don't want changing a .rs file to blow out the cache of packages.
32+ RUN --mount=type=bind,from=packaging,target=/run/packaging /run/packaging/install-buildroot
4133# Now copy the rest of the source
4234COPY --from=src /src /src
4335WORKDIR /src
4436# See https://www.reddit.com/r/rust/comments/126xeyx/exploring_the_problem_of_faster_cargo_docker/
4537# We aren't using the full recommendations there, just the simple bits.
4638# First we download all of our Rust dependencies
4739RUN --mount=type=cache,target=/src/target --mount=type=cache,target=/var/roothome cargo fetch
48- # Then on general principle all the stuff from the Makefile runs with no network
49- RUN --mount=type=cache,target=/src/target --mount=type=cache,target=/var/roothome --network=none <<EORUN
50- set -xeuo pipefail
51- make
52- make install-all DESTDIR=/out
53- if test "${initramfs:-}" = 1; then
54- make install-initramfs-dracut DESTDIR=/out
55- fi
56- EORUN
40+
41+ FROM buildroot as build
42+ # Build RPM directly from source, using cached target directory
43+ RUN --mount=type=cache,target=/src/target --mount=type=cache,target=/var/roothome --network=none RPM_VERSION=${pkgversion} /src/contrib/packaging/build-rpm
5744
5845# This "build" includes our unit tests
5946FROM build as units
@@ -70,76 +57,14 @@ RUN --mount=type=cache,target=/src/target --mount=type=cache,target=/var/roothom
7057FROM base
7158# See the Justfile for possible variants
7259ARG variant
73- RUN <<EORUN
74- set -xeuo pipefail
75- case "${variant}" in
76- *-sdboot)
77- dnf -y install systemd-boot-unsigned
78- # And uninstall bootupd
79- rpm -e bootupd
80- rm /usr/lib/bootupd/updates -rf
81- dnf clean all
82- rm -rf /var/cache /var/lib/{dnf,rhsm} /var/log/*
83- ;;
84- esac
85- EORUN
60+ RUN --mount=type=bind,from=packaging,target=/run/packaging /run/packaging/configure-variant "${variant}"
8661# Support overriding the rootfs at build time conveniently
8762ARG rootfs=
88- RUN <<EORUN
89- set -xeuo pipefail
90- # Do we have an explicit build-time override? Then write it.
91- if test -n "$rootfs" ; then
92- cat > /usr/lib/bootc/install/80-rootfs-override.toml <<EOF
93- [install.filesystem.root]
94- type = "$rootfs"
95- EOF
96- else
97- # Query the default rootfs
98- base_rootfs=$(bootc install print-configuration | jq -r '.filesystem.root.type // ""' )
99- # No filesystem override set. If we're doing composefs, we need a FS that
100- # supports fsverity. If btrfs is available we'll pick that, otherwise ext4.
101- fs=
102- case "${variant}" in
103- composefs*)
104- btrfs=$(grep -qEe '^CONFIG_BTRFS_FS' /usr/lib/modules/*/config && echo btrfs || true)
105- fs=${btrfs:-ext4}
106- ;;
107- *)
108- # No explicit filesystem set and we're not using composefs. Default to xfs
109- # with the rationale that we're trying to get filesystem coverage across
110- # all the cases in general.
111- if test -z "${base_rootfs}" ; then
112- fs=xfs
113- fi
114- ;;
115- esac
116- if test -n "$fs" ; then
117- cat > /usr/lib/bootc/install/80-ext4-composefs.toml <<EOF
118- [install.filesystem.root]
119- type = "${fs}"
120- EOF
121- fi
122- fi
123-
124- # Ensure we've flushed out prior state (i.e. files no longer shipped from the old version);
125- # and yes, we may need to go to building an RPM in this Dockerfile by default.
126- (set +x; rpm -ql bootc | while read line; do if test -f $line; then rm -v $line; fi; done)
127- EORUN
128- # Create a layer that is our new binaries
129- COPY --from=build /out/ /
130- # We have code in the initramfs so we always need to regenerate it
131- RUN --network=none <<EORUN
132- set -xeuo pipefail
133- if test -x /usr/lib/bootc/initramfs-setup; then
134- kver=$(cd /usr/lib/modules && echo *);
135- env DRACUT_NO_XATTR=1 dracut -vf /usr/lib/modules/$kver/initramfs.img $kver
136- fi
137- # Only in this containerfile, inject a file which signifies
138- # this comes from this development image. This can be used in
139- # tests to know we're doing upstream CI.
140- touch /usr/lib/.bootc-dev-stamp
141- # And test our own linting
142- # # Workaround for https://github.com/bootc-dev/bootc/issues/1546
143- rm -rf /root/buildinfo
144- bootc container lint --fatal-warnings
145- EORUN
63+ RUN --mount=type=bind,from=packaging,target=/run/packaging /run/packaging/configure-rootfs "${variant}" "${rootfs}"
64+ # Install the RPM built in the build stage
65+ # This replaces the manual file deletion hack and COPY, ensuring proper package management
66+ # Use rpm -Uvh with --oldpackage to allow replacing with dev version
67+ COPY --from=build /out/*.rpm /tmp/
68+ RUN --mount=type=bind,from=packaging,target=/run/packaging --network=none /run/packaging/install-rpm-and-setup /tmp
69+ # Finally, testour own linting
70+ RUN bootc container lint --fatal-warnings
0 commit comments