Skip to content

Commit ba53ea3

Browse files
committed
feat(container): add finalize-rootfs subcommand for building base images
Add bootc container finalize-rootfs and bootc container post-chroot-cleanup subcommands that transform a dnf --installroot rootfs into a bootc-compatible layout without requiring rpm-ostree. Transforms: toplevel symlinks, /var->tmpfiles.d, rpmdb relocation, config injection (prepare-root.conf, dracut.conf.d, kernel install.conf). Validated end-to-end: Fedora 42 image boots to login in 41s, bootc status works, reboot succeeds, 12/12 lint checks pass. Signed-off-by: Andrew Dunn <andrew@dunn.dev>
1 parent 5cbb111 commit ba53ea3

3 files changed

Lines changed: 626 additions & 0 deletions

File tree

crates/lib/src/cli.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,35 @@ pub(crate) enum ContainerOpts {
463463
/// Path to the container filesystem root
464464
target: Utf8PathBuf,
465465
},
466+
/// Transform a dnf --installroot rootfs into a bootc-compatible layout.
467+
///
468+
/// Applies the filesystem transforms needed to make a plain rootfs
469+
/// deployable by bootc: toplevel symlinks, /var->tmpfiles.d conversion,
470+
/// rpmdb relocation, config injection (prepare-root.conf, dracut.conf.d,
471+
/// kernel install.conf, etc.).
472+
///
473+
/// After running this, run dracut and systemctl preset-all in a chroot,
474+
/// then use post-chroot-cleanup to finalize.
475+
FinalizeRootfs {
476+
/// Path to the rootfs directory (from dnf --installroot)
477+
rootfs: Utf8PathBuf,
478+
479+
/// Check mode: report what would change without modifying
480+
#[clap(long)]
481+
check: bool,
482+
},
483+
/// Clean up artifacts left by chroot operations after finalize-rootfs.
484+
///
485+
/// Run this AFTER dracut, systemctl preset-all, and bootupd metadata
486+
/// generation, and BEFORE building the OCI image.
487+
PostChrootCleanup {
488+
/// Path to the rootfs directory
489+
rootfs: Utf8PathBuf,
490+
491+
/// Check mode: report what would change without modifying
492+
#[clap(long)]
493+
check: bool,
494+
},
466495
}
467496

468497
#[derive(Debug, Clone, ValueEnum, PartialEq, Eq)]
@@ -1712,6 +1741,12 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
17121741
)
17131742
.await
17141743
}
1744+
ContainerOpts::FinalizeRootfs { rootfs, check } => {
1745+
crate::finalize_rootfs::finalize_rootfs(&rootfs, check)
1746+
}
1747+
ContainerOpts::PostChrootCleanup { rootfs, check } => {
1748+
crate::finalize_rootfs::post_chroot_cleanup(&rootfs, check)
1749+
}
17151750
},
17161751
Opt::Completion { shell } => {
17171752
use clap_complete::aot::generate;

0 commit comments

Comments
 (0)