@@ -32,10 +32,6 @@ WORKDIR /src
3232# First we download all of our Rust dependencies
3333RUN --mount=type=cache,target=/src/target --mount=type=cache,target=/var/roothome cargo fetch
3434
35- FROM buildroot as sdboot-content
36- # Writes to /out
37- RUN /src/contrib/packaging/configure-systemdboot download
38-
3935# We always do a "from scratch" build
4036# https://docs.fedoraproject.org/en-US/bootc/building-from-scratch/
4137# because this fixes https://github.com/containers/composefs-rs/issues/132
@@ -65,6 +61,11 @@ ENV container=oci
6561STOPSIGNAL SIGRTMIN+3
6662CMD ["/sbin/init" ]
6763
64+ # This layer contains things which aren't in the default image and may
65+ # be used for sealing images in particular.
66+ FROM base as tools
67+ RUN --mount=type=bind,from=packaging,target=/run/packaging /run/packaging/initialize-sealing-tools
68+
6869# -------------
6970# external dependency cutoff point:
7071# NOTE: Every RUN instruction past this point should use `--network=none`; we want to ensure
@@ -81,14 +82,35 @@ ENV SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH}
8182# Build RPM directly from source, using cached target directory
8283RUN --network=none --mount=type=cache,target=/src/target --mount=type=cache,target=/var/roothome RPM_VERSION="${pkgversion}" /src/contrib/packaging/build-rpm
8384
84- FROM buildroot as sdboot-signed
85+ # This image signs systemd-boot using our key, and writes the resulting binary into /out
86+ FROM tools as sdboot-signed
8587# The secureboot key and cert are passed via Justfile
8688# We write the signed binary into /out
89+ # Note: /out already contains systemd-boot-unsigned RPM from initialize-sealing-tools
8790RUN --network=none \
88- --mount=type=bind,from=sdboot-content,target=/run/sdboot-package \
8991 --mount=type=secret,id=secureboot_key \
90- --mount=type=secret,id=secureboot_cert \
91- /src/contrib/packaging/configure-systemdboot sign
92+ --mount=type=secret,id=secureboot_cert <<EORUN
93+ set -xeuo pipefail
94+
95+ # Extract the unsigned systemd-boot binary from the downloaded RPM
96+ cd /tmp
97+ rpm2cpio /out/*.rpm | cpio -idmv
98+ # Find the extracted unsigned binary
99+ sdboot_unsigned=$(ls ./usr/lib/systemd/boot/efi/systemd-boot*.efi)
100+ sdboot_bn=$(basename ${sdboot_unsigned})
101+ # Sign with sbsign using db certificate and key
102+ sbsign --key /run/secrets/secureboot_key \
103+ --cert /run/secrets/secureboot_cert \
104+ --output /out/${sdboot_bn} \
105+ ${sdboot_unsigned}
106+ ls -al /out/${sdboot_bn}
107+ EORUN
108+
109+ # ----
110+ # Unit and integration tests
111+ # The section here (up until the last `FROM` line which acts as the default target)
112+ # is non-default images for unit and source code validation.
113+ # ----
92114
93115# This "build" includes our unit tests
94116FROM build as units
@@ -101,20 +123,61 @@ RUN --network=none --mount=type=cache,target=/src/target --mount=type=cache,targ
101123FROM buildroot as validate
102124RUN --network=none --mount=type=cache,target=/src/target --mount=type=cache,target=/var/roothome make validate
103125
104- # Common base for final images: configures variant, rootfs, and injects extra content
105- FROM base as final-common
126+ # ----
127+ # Stages for the final image
128+ # ----
129+
130+ # Perform all filesystem transformations except generating the sealed UKI (if configured)
131+ FROM base as base-penultimate
106132ARG variant
133+ # Switch to a signed systemd-boot, if configured
107134RUN --network=none --mount=type=bind,from=packaging,target=/run/packaging \
108- --mount=type=bind,from=sdboot-content,target=/run/sdboot-content \
109- --mount=type=bind,from=sdboot-signed,target=/run/sdboot-signed \
110- /run/packaging/configure-variant "${variant}"
135+ --mount=type=bind,from=sdboot-signed,target=/run/sdboot-signed <<EORUN
136+ set -xeuo pipefail
137+ if test "${variant}" = "composefs-sealeduki-sdboot" ; then
138+ /run/packaging/switch-to-sdboot /run/sdboot-signed
139+ fi
140+ EORUN
141+ # Configure the rootfs
111142ARG rootfs=""
112- RUN --network=none --mount=type=bind,from=packaging,target=/run/packaging /run/packaging/configure-rootfs "${variant}" "${rootfs}"
113- COPY --from=packaging /usr-extras/ /usr/
114-
115- # Final target: installs pre-built packages from /run/packages volume mount.
116- # Use with: podman build --target=final -v path/to/packages:/run/packages:ro
117- FROM final-common as final
118143RUN --network=none --mount=type=bind,from=packaging,target=/run/packaging \
144+ /run/packaging/configure-rootfs "${variant}" "${rootfs}"
145+ # Override with our built package
146+ RUN --network=none \
147+ --mount=type=bind,from=packaging,target=/run/packaging \
119148 /run/packaging/install-rpm-and-setup /run/packages
149+ # Inject some other configuration
150+ COPY --from=packaging /usr-extras/ /usr/
151+
152+ # Generate the sealed UKI in a separate stage
153+ # This computes the composefs digest from base-penultimate and creates a signed UKI
154+ # We need our newly-built bootc for the compute-composefs-digest command
155+ FROM tools as sealed-uki
156+ ARG variant
157+ # Install our bootc package (only needed for the compute-composefs-digest command)
158+ RUN --network=none rpm -Uvh --oldpackage /run/packages/bootc-*.rpm
159+ RUN --network=none \
160+ --mount=type=secret,id=secureboot_key \
161+ --mount=type=secret,id=secureboot_cert \
162+ --mount=type=bind,from=packaging,target=/run/packaging \
163+ --mount=type=bind,from=base-penultimate,target=/run/target <<EORUN
164+ set -xeuo pipefail
165+ if test "${variant}" = "composefs-sealeduki-sdboot" ; then
166+ /run/packaging/seal-uki /run/target /out /run/secrets
167+ fi
168+ EORUN
169+
170+ # And now the final image
171+ FROM base-penultimate
172+ ARG variant
173+ # Copy the sealed UKI and finalize the image (remove raw kernel, create symlinks)
174+ RUN --network=none \
175+ --mount=type=bind,from=packaging,target=/run/packaging \
176+ --mount=type=bind,from=sealed-uki,target=/run/sealed-uki <<EORUN
177+ set -xeuo pipefail
178+ if test "${variant}" = "composefs-sealeduki-sdboot" ; then
179+ /run/packaging/finalize-uki /run/sealed-uki/out
180+ fi
181+ EORUN
182+ # And finally, test our linting
120183RUN --network=none bootc container lint --fatal-warnings
0 commit comments