Skip to content

Commit 472931a

Browse files
committed
build-sys: Always build packages as separate stage
We were previously trying to support a direct `podman/docker build` *and* injecting externally built packages (for CI). Looking to rework for sealed images it was too hacky; let's just accept that a raw `podman build` no longer works, the canonical entry for local build is `just build` which builds both a package and a container. This way CI and local work exactly the same. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent ba768f1 commit 472931a

File tree

2 files changed

+18
-52
lines changed

2 files changed

+18
-52
lines changed

Dockerfile

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,9 @@ ARG rootfs=""
8383
RUN --mount=type=bind,from=packaging,target=/run/packaging /run/packaging/configure-rootfs "${variant}" "${rootfs}"
8484
COPY --from=packaging /usr-extras/ /usr/
8585

86-
# Default target for source builds (just build)
87-
# Installs packages from the internal build stage
86+
# Final target: installs pre-built packages from /run/packages volume mount.
87+
# Use with: podman build --target=final -v path/to/packages:/run/packages:ro
8888
FROM final-common as final
89-
RUN --mount=type=bind,from=packaging,target=/run/packaging \
90-
--mount=type=bind,from=build,target=/build-output \
91-
--network=none \
92-
/run/packaging/install-rpm-and-setup /build-output/out
93-
RUN bootc container lint --fatal-warnings
94-
95-
# Alternative target for pre-built packages (CI workflow)
96-
# Use with: podman build --target=final-from-packages -v path/to/packages:/run/packages:ro
97-
FROM final-common as final-from-packages
9889
RUN --mount=type=bind,from=packaging,target=/run/packaging \
9990
--network=none \
10091
/run/packaging/install-rpm-and-setup /run/packages

Justfile

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,25 @@ _git-build-vars:
7070
# Note commonly you might want to override the base image via e.g.
7171
# `just build --build-arg=base=quay.io/fedora/fedora-bootc:42`
7272
#
73-
# The Dockerfile builds RPMs internally in its 'build' stage, so we don't need
74-
# to call 'package' first. This avoids cache invalidation from external files.
75-
build: _keygen
76-
#!/bin/bash
77-
set -xeuo pipefail
78-
eval $(just _git-build-vars)
79-
podman build {{base_buildargs}} --target=final \
80-
--build-arg=SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \
81-
--build-arg=pkgversion=${VERSION} \
82-
-t {{base_img}}-bin {{buildargs}} .
83-
./hack/build-sealed {{variant}} {{base_img}}-bin {{base_img}} {{sealed_buildargs}}
73+
# This first builds RPMs via the `package` target, then injects them
74+
# into the container image.
75+
build: package _keygen
76+
@just _build-from-package target/packages
8477

8578
# Generate Secure Boot keys (only for our own CI/testing)
8679
_keygen:
8780
./hack/generate-secureboot-keys
8881

82+
# Internal helper: build container image from packages at PATH
83+
_build-from-package PATH:
84+
#!/bin/bash
85+
set -xeuo pipefail
86+
# Resolve to absolute path for podman volume mount
87+
# Use :z for SELinux relabeling
88+
pkg_path=$(realpath "{{PATH}}")
89+
podman build --target=final -v "${pkg_path}":/run/packages:ro,z -t {{base_img}}-bin {{buildargs}} .
90+
./hack/build-sealed {{variant}} {{base_img}}-bin {{base_img}} {{sealed_buildargs}}
91+
8992
# Build a sealed image from current sources.
9093
build-sealed:
9194
@just --justfile {{justfile()}} variant=composefs-sealeduki-sdboot build
@@ -108,34 +111,6 @@ package: _packagecontainer
108111
chmod a+r target/packages/*.rpm
109112
podman rmi localhost/bootc-pkg
110113

111-
# Copy pre-existing packages from PATH into target/packages/
112-
# Note: This is mainly for CI artifact extraction; build-from-package
113-
# now uses volume mounts directly instead of copying to target/packages/.
114-
copy-packages-from PATH:
115-
#!/bin/bash
116-
set -xeuo pipefail
117-
if ! compgen -G "{{PATH}}/*.rpm" > /dev/null; then
118-
echo "Error: No packages found in {{PATH}}" >&2
119-
exit 1
120-
fi
121-
mkdir -p target/packages
122-
rm -vf target/packages/*.rpm
123-
cp -v {{PATH}}/*.rpm target/packages/
124-
chmod a+rx target target/packages
125-
chmod a+r target/packages/*.rpm
126-
127-
# Build the container image using pre-existing packages from PATH
128-
# Uses the 'final-from-packages' target with a volume mount to inject packages,
129-
# avoiding Docker context cache invalidation issues.
130-
build-from-package PATH: _keygen
131-
#!/bin/bash
132-
set -xeuo pipefail
133-
# Resolve to absolute path for podman volume mount
134-
# Use :z for SELinux relabeling
135-
pkg_path=$(realpath "{{PATH}}")
136-
podman build {{base_buildargs}} --target=final-from-packages -v "${pkg_path}":/run/packages:ro,z -t {{base_img}}-bin {{buildargs}} .
137-
./hack/build-sealed {{variant}} {{base_img}}-bin {{base_img}} {{sealed_buildargs}}
138-
139114
# Pull images used by hack/lbi
140115
_pull-lbi-images:
141116
podman pull -q --retry 5 --retry-delay 5s {{lbi_images}}
@@ -146,8 +121,8 @@ build-integration-test-image: build _pull-lbi-images
146121
./hack/build-sealed {{variant}} {{integration_img}}-bin {{integration_img}} {{sealed_buildargs}}
147122

148123
# Build integration test image using pre-existing packages from PATH
149-
build-integration-test-image-from-package PATH: _pull-lbi-images
150-
@just build-from-package {{PATH}}
124+
build-integration-test-image-from-package PATH: _keygen _pull-lbi-images
125+
@just _build-from-package {{PATH}}
151126
cd hack && podman build {{base_buildargs}} -t {{integration_img}}-bin -f Containerfile .
152127
./hack/build-sealed {{variant}} {{integration_img}}-bin {{integration_img}} {{sealed_buildargs}}
153128

0 commit comments

Comments
 (0)