Skip to content

Commit 6d3aeef

Browse files
committed
build: Add BOOTC_ostree_src for building with patched ostree
Add support for building the bootc test image with a custom ostree built from source. When BOOTC_ostree_src is set to a path to an ostree source tree, the build system: 1. Builds ostree RPMs inside a container matching the base image distro (via contrib/packaging/Dockerfile.ostree-override) 2. Installs ostree-devel into the buildroot so bootc links against the patched libostree 3. Installs ostree + ostree-libs into the final image The override ostree is built as version 2026.1 by default (configurable via BOOTC_ostree_version) to ensure it is always newer than the stock package. This is important for runtime version checks like ostree::check_version(). The same pattern can be reused for other dependency overrides (e.g. composefs) in the future. Usage: BOOTC_ostree_src=/path/to/ostree just build BOOTC_ostree_src=/path/to/ostree just test-tmt loader-entries-source Assisted-by: OpenCode (Claude Opus 4.6) Signed-off-by: Joseph Marrero Corchado <jmarrero@redhat.com>
1 parent d8785c6 commit 6d3aeef

File tree

3 files changed

+172
-3
lines changed

3 files changed

+172
-3
lines changed

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ ARG initramfs=1
2727
RUN --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp \
2828
--mount=type=bind,from=packaging,src=/,target=/run/packaging \
2929
/run/packaging/install-buildroot
30+
# Install ostree override RPMs into the buildroot if provided via BOOTC_ostree_src.
31+
# This ensures bootc compiles and links against the patched ostree (ostree-devel,
32+
# ostree-libs, ostree). When the directory is empty, nothing is installed.
33+
RUN --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp \
34+
--mount=type=bind,from=ostree-packages,src=/,target=/run/ostree-packages <<EORUN
35+
set -xeuo pipefail
36+
if ls /run/ostree-packages/*.rpm 2>/dev/null; then
37+
echo "Installing ostree override into buildroot"
38+
rpm -Uvh --oldpackage /run/ostree-packages/*.rpm
39+
fi
40+
EORUN
3041
# Now copy the rest of the source
3142
COPY --from=src /src /src
3243
WORKDIR /src
@@ -162,6 +173,16 @@ ARG rootfs=""
162173
RUN --network=none --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp \
163174
--mount=type=bind,from=packaging,src=/,target=/run/packaging \
164175
/run/packaging/configure-rootfs "${variant}" "${rootfs}"
176+
# Install ostree override RPMs into the final image if provided via BOOTC_ostree_src.
177+
# Only ostree and ostree-libs are installed here (not ostree-devel).
178+
RUN --network=none --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp \
179+
--mount=type=bind,from=ostree-packages,src=/,target=/run/ostree-packages <<EORUN
180+
set -xeuo pipefail
181+
if ls /run/ostree-packages/ostree-2*.rpm /run/ostree-packages/ostree-libs-*.rpm 2>/dev/null; then
182+
echo "Installing ostree override RPMs into final image"
183+
rpm -Uvh --oldpackage /run/ostree-packages/ostree-2*.rpm /run/ostree-packages/ostree-libs-*.rpm
184+
fi
185+
EORUN
165186
# Override with our built package
166187
RUN --network=none --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp \
167188
--mount=type=bind,from=packaging,src=/,target=/run/packaging \

Justfile

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ buildroot_base := env("BOOTC_buildroot_base", "quay.io/centos/centos:stream10")
3838
extra_src := env("BOOTC_extra_src", "")
3939
# Set to "1" to disable auto-detection of local Rust dependencies
4040
no_auto_local_deps := env("BOOTC_no_auto_local_deps", "")
41+
# Optional: path to an ostree source tree to build and inject into the image.
42+
# When set, ostree is built from source inside a container matching the base
43+
# image distro, and the resulting RPMs override the stock ostree packages in
44+
# both the buildroot (so bootc links against the patched libostree) and the
45+
# final image. This pattern can be reused for other dependency overrides.
46+
# Example: BOOTC_ostree_src=/path/to/ostree just build
47+
ostree_src := env("BOOTC_ostree_src", "")
48+
# Version to assign to the override ostree RPMs. This should be set to the
49+
# next unreleased ostree version so the override is always newer than stock.
50+
ostree_version := env("BOOTC_ostree_version", "2026.1")
4151

4252
# Internal variables
4353
nocache := env("BOOTC_nocache", "")
@@ -64,13 +74,14 @@ buildargs := base_buildargs \
6474

6575
# Build container image from current sources (default target)
6676
[group('core')]
67-
build: package _keygen && _pull-lbi-images
77+
build: _build-ostree-rpms package _keygen && _pull-lbi-images
6878
#!/bin/bash
6979
set -xeuo pipefail
7080
test -d target/packages
7181
pkg_path=$(realpath target/packages)
82+
ostree_pkg_path=$(realpath target/ostree-packages)
7283
eval $(just _git-build-vars)
73-
podman build {{_nocache_arg}} --build-arg=image_version=${VERSION} --build-context "packages=${pkg_path}" -t {{base_img}} {{buildargs}} .
84+
podman build {{_nocache_arg}} --build-arg=image_version=${VERSION} --build-context "packages=${pkg_path}" --build-context "ostree-packages=${ostree_pkg_path}" -t {{base_img}} {{buildargs}} .
7485

7586
# Show available build variants and current configuration
7687
[group('core')]
@@ -321,7 +332,9 @@ package:
321332
if [[ -z "{{no_auto_local_deps}}" ]]; then
322333
local_deps_args=$(cargo xtask local-rust-deps)
323334
fi
324-
podman build {{base_buildargs}} --build-arg=SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} --build-arg=pkgversion=${VERSION} -t localhost/bootc-pkg --target=build $local_deps_args .
335+
mkdir -p target/ostree-packages
336+
ostree_pkg_path=$(realpath target/ostree-packages)
337+
podman build {{base_buildargs}} --build-arg=SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} --build-arg=pkgversion=${VERSION} --build-context "ostree-packages=${ostree_pkg_path}" -t localhost/bootc-pkg --target=build $local_deps_args .
325338
mkdir -p "${packages}"
326339
rm -vf "${packages}"/*.rpm
327340
podman run --rm localhost/bootc-pkg tar -C /out/ -cf - . | tar -C "${packages}"/ -xvf -
@@ -359,6 +372,28 @@ _git-build-vars:
359372
echo "SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH}"
360373
echo "VERSION=${VERSION}"
361374

375+
# Build ostree RPMs from source if BOOTC_ostree_src is set.
376+
# The RPMs are built inside a container matching the base image distro.
377+
# When BOOTC_ostree_src is not set, this creates an empty directory (no-op).
378+
_build-ostree-rpms:
379+
#!/bin/bash
380+
set -xeuo pipefail
381+
mkdir -p target/ostree-packages
382+
if [ -z "{{ostree_src}}" ]; then exit 0; fi
383+
echo "Building ostree {{ostree_version}} from source: {{ostree_src}}"
384+
rm -f target/ostree-packages/*.rpm
385+
podman build \
386+
--build-context ostree-src={{ostree_src}} \
387+
--build-arg=base={{base}} \
388+
--build-arg=ostree_version={{ostree_version}} \
389+
-t localhost/ostree-build \
390+
-f contrib/packaging/Dockerfile.ostree-override .
391+
cid=$(podman create localhost/ostree-build)
392+
podman cp "${cid}:/" target/ostree-packages/
393+
podman rm "${cid}"
394+
echo "ostree override RPMs:"
395+
ls -la target/ostree-packages/
396+
362397
_keygen:
363398
./hack/generate-secureboot-keys
364399

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Build ostree RPMs from source, matching the base image distro.
2+
#
3+
# This Dockerfile is used by the BOOTC_ostree_src mechanism in the Justfile
4+
# to build a patched ostree and inject it into the bootc test image. It builds
5+
# ostree RPMs inside a container matching the base image so the resulting RPMs
6+
# are compatible with the target distro.
7+
#
8+
# The ostree source is provided via the `ostree-src` build context.
9+
# The version is overridden to ensure the built RPMs are always newer than
10+
# the stock packages.
11+
#
12+
# Usage (via Justfile):
13+
# BOOTC_ostree_src=/path/to/ostree just build
14+
#
15+
# Direct usage:
16+
# podman build --build-context ostree-src=/path/to/ostree \
17+
# --build-arg=base=quay.io/centos-bootc/centos-bootc:stream10 \
18+
# --build-arg=ostree_version=2026.1 \
19+
# -f contrib/packaging/Dockerfile.ostree-override .
20+
21+
ARG base=quay.io/centos-bootc/centos-bootc:stream10
22+
23+
FROM $base as ostree-build
24+
# Install ostree build dependencies
25+
RUN <<EORUN
26+
set -xeuo pipefail
27+
. /usr/lib/os-release
28+
case "${ID}${ID_LIKE:-}" in
29+
*centos*|*rhel*)
30+
dnf config-manager --set-enabled crb
31+
;;
32+
esac
33+
dnf -y builddep ostree
34+
dnf -y install git rpm-build autoconf automake libtool make xz
35+
EORUN
36+
37+
# Copy ostree source from build context
38+
COPY --from=ostree-src / /ostree-src
39+
WORKDIR /ostree-src
40+
41+
# Build ostree RPMs with the specified version
42+
ARG ostree_version=2026.1
43+
RUN <<EORUN
44+
set -xeuo pipefail
45+
git config --global --add safe.directory /ostree-src
46+
47+
# Initialize submodules if needed
48+
if ! test -f libglnx/README.md || ! test -f bsdiff/README.md; then
49+
git submodule update --init
50+
fi
51+
52+
# Clean up any stale build artifacts from the source tree
53+
rm -rf ostree-distgit *.tar.xz *.src.rpm x86_64/ ostree.spec
54+
55+
# Create source tarball with the target version as the directory prefix.
56+
# We can't use ci/make-git-snapshot.sh because it hardcodes the directory
57+
# name from git-describe, which won't match our overridden version.
58+
GITREV=$(git rev-parse HEAD)
59+
PKG_VER="libostree-${ostree_version}"
60+
git archive --format=tar --prefix="${PKG_VER}/" "${GITREV}" > "${PKG_VER}.tar.tmp"
61+
git submodule status | while read line; do
62+
rev=$(echo ${line} | cut -f 1 -d ' ')
63+
path=$(echo ${line} | cut -f 2 -d ' ')
64+
(cd "${path}"; git archive --format=tar --prefix="${PKG_VER}/${path}/" "${rev}") > submodule.tar
65+
tar -A -f "${PKG_VER}.tar.tmp" submodule.tar
66+
rm submodule.tar
67+
done
68+
mv "${PKG_VER}.tar.tmp" "${PKG_VER}.tar"
69+
xz "${PKG_VER}.tar"
70+
71+
# Get spec file: use local one if present, otherwise fetch from dist-git
72+
if ! test -f ostree.spec; then
73+
rm -rf ostree-distgit
74+
. /usr/lib/os-release
75+
case "${ID}" in
76+
centos|rhel)
77+
git clone --depth=1 https://gitlab.com/redhat/centos-stream/rpms/ostree.git ostree-distgit || \
78+
git clone --depth=1 https://src.fedoraproject.org/rpms/ostree ostree-distgit
79+
;;
80+
*)
81+
git clone --depth=1 https://src.fedoraproject.org/rpms/ostree ostree-distgit
82+
;;
83+
esac
84+
cp ostree-distgit/ostree.spec .
85+
fi
86+
87+
# Set the target version and strip any distro patches
88+
sed -i -e '/^Patch/d' -e "s,^Version:.*,Version: ${ostree_version}," ostree.spec
89+
90+
# Build SRPM
91+
ci/rpmbuild-cwd -bs ostree.spec
92+
93+
# Install any missing build deps from the SRPM
94+
if test "$(id -u)" = 0; then
95+
dnf builddep -y *.src.rpm
96+
fi
97+
98+
# Build binary RPMs
99+
ci/rpmbuild-cwd --rebuild *.src.rpm
100+
101+
# Collect the RPMs we need
102+
mkdir -p /out
103+
cp x86_64/ostree-${ostree_version}*.rpm \
104+
x86_64/ostree-libs-${ostree_version}*.rpm \
105+
x86_64/ostree-devel-${ostree_version}*.rpm \
106+
/out/
107+
echo "Built ostree override RPMs:"
108+
ls -la /out/
109+
EORUN
110+
111+
# Final stage: just the RPMs
112+
FROM scratch
113+
COPY --from=ostree-build /out/ /

0 commit comments

Comments
 (0)