Skip to content

install: Add an experimental library API for installers (PoC) - #37

Closed
cgwalters-bot wants to merge 2 commits into
mainfrom
bot/install-library-poc
Closed

cgwalters-bot wants to merge 2 commits into
mainfrom
bot/install-library-poc

Conversation

@cgwalters-bot

Copy link
Copy Markdown
Collaborator

Proof of concept for bootc-dev#542, as a draft to discuss the shape: bootc install to-filesystem exposed as a Rust API for installers. The caller partitions and mounts the target, then gets progress through a callback, an outcome with the deployment's paths, and typed errors.

use bootc_lib::install_api::{Event, FilesystemTarget, Installer};

let outcome = Installer::new("oci:/run/install/image")   // any source transport
    .target_imgref("quay.io/example/os:latest")           // what it updates from
    .karg("console=ttyS0")
    .on_progress(|ev| { let _ = tx.send(ev.clone()); })  // Event::StepStarted(Step::Deploy), ...
    .install_to_filesystem(&FilesystemTarget::new("/mnt/sysroot"))
    .await?;                                              // Err(install_api::Error), with .kind()
// outcome.etc_path == "ostree/deploy/default/deploy/<checksum>.0/etc", relative to the root

What's in:

  • bootc_lib::install_api, documented as unstable. It has an Installer builder, FilesystemTarget, progress Events for the steps (Prepare, Deploy, Bootloader, BoundImages, Finalize), and InstallOutcome. The outcome holds the backend, stateroot, deployment, /etc and /var paths, and bootloader. It is Serialize, so the same struct could back the --output-json/--output-pairs idea from Consider designing bootc as a library to be used by installer applications bootc-dev/bootc#542. Errors are an Error with ErrorKind::{InvalidOptions, Environment, Install}.
  • In library mode bootc never re-executes its caller. Where the CLI would re-exec itself into install_t, the SELinux setup returns an Environment error instead. The source is always explicit (--source-imgref semantics), which already skips the mount namespace re-exec.
  • crates/lib/examples/install-to-loopback.rs: a minimal installer that partitions and formats a loop disk with sfdisk/mkfs, then installs to it.

What's out: to-disk, to-existing-root and reset. The composefs backend's outcome is wired up but not tested end to end. There's no byte-level pull progress. Status lines still go to stdout. Nothing is published to crates.io, and there's no C ABI or varlink.

Testing, on a 16-core RHEL 10 devspace (no fork CI):

  • just build passed, including the image's bootc container lint --fatal-warnings. just unit-tests passed (bootc-lib: 287, including the 4 new ones), and so did just validate.
  • End to end: in a bcvk ephemeral VM, the example installed quay.io/centos-bootc/centos-bootc:stream10 from an OCI directory to a 10G loopback disk. It reported all five steps, the outcome paths were right, and ostree fsck was clean. A systemd unit written into the reported etcPath then ran on first boot, under qemu with both SeaBIOS and OVMF, with SELinux enforcing.
  • The library SELinux path, run on that booted system: confined as initrc_t (no mac_admin), the install failed with ErrorKind::Environment and no re-exec. After setenforce 0 it succeeded.
  • Found along the way: --source-imgref fails on an ostree-booted host whose repo has several commits (bootc install to-existing-root fails when run on ostree based system bootc-dev/bootc#1343). That affects installers running from a bootc-based live environment. The SELinux check above hid /sysroot/ostree to get past it.

Open questions:

  • Stability: is an unstable, documented module in bootc-lib the right first step, or should it start behind a cargo feature?
  • Semver and crate split: should this become its own crate (e.g. bootc-install) with a semver promise, separate from the internal bootc-lib, and published to crates.io?
  • Other languages: is a C ABI wanted (Anaconda is Python, remoting API bootc-dev/bootc#522 asks about Go), or is varlink over a socketpair the better cross-language answer, with this API underneath it?
  • Should the progress events reuse the --progress-fd JSON event types, so the library and CLI share one protocol?

xref bootc-dev#542

Generated-by: https://github.com/cgwalters/#llms


Review draft in cgwalters-forge, not upstream yet. This section is removed when the PR is opened upstream.

  • Upstream: bootc-dev/bootc, base main
  • Board item: PVTI_lADOE9oHIs4BlJLczg-Ke4c
  • Fork CI: off; the devspace testing described above is this PR's CI, and upstream CI runs once it is opened there

To review:

  • Approve, or comment /promote on a line of its own, to open it upstream, ready for review. Either covers only the commits pushed so far.
  • If upstream requires DCO, approving also signs off: promote adds Signed-off-by: Colin Walters <[email protected]> to the commits lacking it (the bot's and yours; anyone else's only if you ask), with you as committer.
  • Add a /draft line (in the same comment or before) to open it upstream as a draft (/ready undoes that).
  • Close to drop it.
  • Edit the title and description freely: they become the upstream PR's. Review comments are squashed into the commits they concern, with a reply here.

Installers that build on bootc today fork/exec `bootc install
to-filesystem` and get back only human-oriented stdout: there is no
progress to show in a GUI, and finding the new deployment's /etc and
/var to inject configuration before the first boot means poking at the
ostree layout (bootc-dev#536). The install code already lives in bootc-lib, so
expose that path as a small Rust API instead: the caller partitions and
mounts the target as with to-filesystem, then gets step progress via a
callback, an outcome with the deployment's paths, and errors that carry
a kind rather than an exit status.

A library must not re-exec its caller, so in this mode the SELinux
setup reports a typed environment error when the process can't write
arbitrary labels, instead of re-executing itself into install_t. The
source image is always given explicitly, as with --source-imgref, which
already skips the mount namespace re-exec.

This is a proof of concept for discussion in bootc-dev#542; the module is
documented as unstable. bootc's status lines still go to stdout.

Generated-by: AI
A minimal consumer of the installer API, playing the part of an
installer: it partitions and formats a disk image through a loop device,
installs to it while printing progress, and writes the outcome as JSON.
It is also a handy way to check by hand that the API produces a
bootable disk.

Generated-by: AI
@cgwalters-bot
cgwalters-bot force-pushed the bot/install-library-poc branch from 0daf35c to 04fd1b3 Compare October 2, 2026 17:39

@cgwalters-bot cgwalters-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review guide for head 04fd1b33b1: where to look closely and what is safe to skim. It is advice from the bot's reviewer and doesn't replace reading the diff; the review app walks it.

Exposes bootc install to-filesystem as an unstable Rust API (bootc_lib::install_api): a builder that maps onto InstallToFilesystemOpts, a step progress callback, an InstallOutcome with the deployment's etc/var paths, and errors with a kind. The CLI path gains an Invocation parameter; in library mode bootc refuses to re-exec for SELinux and skips the completion message. Risk is mostly in the SELinux library branch, the outcome paths (especially composefs, untested end to end), and side effects the library still has on the caller's process: mounts on /tmp and efivarfs, and stdout status lines. A unit test now checks that the builder produces exactly what clap parses for the equivalent CLI flags.

Hotspots

  1. look-closely · logic — crates/lib/src/install.rs:1498-1511 (a10465e): Library mode never re-execs into install_t and has no setenforce fallback; it relies on test_install_t succeeding (install_t or permissive host). Check this is the behaviour wanted for installers like Anaconda.
  2. look-closely · logic — crates/lib/src/install.rs:2274-2280 (a10465e): Composefs outcome hardcodes the default stateroot and shared var path; it was not tested end to end, so verify these match where composefs deployments really put etc and var.
  3. note · error-handling — crates/lib/src/install/api.rs:430-452 (a10465e): Only empty source, non-root/CAP_SYS_ADMIN and host-root targets get InvalidOptions/Environment up front; other bad options (bad transport, composefs conflicts) still surface as Install.
  4. note · test-gap — crates/lib/src/install/api.rs:457-510 (a10465e): Parity test against clap; it already caught the target transport being docker:// instead of registry. New builder options should be added to its cases.

Safe to skim

  • crates/lib/src/cli.rs: Mechanical: pass Invocation::Cli and drop the outcome.
  • crates/lib/src/lsm.rs: Visibility change only.
  • crates/lib/src/lib.rs: Module re-export and doc index.

@cgwalters-bot

Copy link
Copy Markdown
Collaborator Author

Independent review: minor fixes, now amended into the two commits (head 04fd1b3). The shape holds up. The builder maps onto the CLI's to-filesystem path, the SELinux library branch errors instead of re-executing, the outcome paths match the ostree layout, and the module docs mark it unstable.

What I checked: the builder against the CLI defaults (SELinux, stateroot, kargs, bound images, composefs, target transport), the error classification, re-exec and stdout/exit in the library path, the progress step order for both backends, the docs, the example, the tests, and AGENTS.md/REVIEW_RUST.md. I also checked the reply on bootc-dev#542 against the code. It is accurate, so I didn't post a correction there.

What I changed:

  • The builder test now compares to_cli_opts() with what clap parses for the equivalent bootc install to-filesystem flags, for both the defaults and every option. This caught a real divergence: the builder set target_transport to docker:// where the CLI sets registry. Both resolve to the same transport, so nothing broke, but it now uses a shared DEFAULT_TARGET_TRANSPORT constant.
  • The library's privilege check now uses cli::require_root, which also checks CAP_SYS_ADMIN. Before, a process without that capability failed later and got the Install kind.
  • A target on the running system's root filesystem is now refused with InvalidOptions. Before, the library reached the CLI's 20-second "interrupt to cancel" countdown, with a spinner on stderr.
  • Module docs: the CLI path mounts a tmpfs over /tmp when it isn't one, so the docs now say that, next to the existing note about efivarfs. That matters for a GUI installer that doesn't unshare. They also say that the install config and prepare-root.conf are read from the running root, as with --source-imgref. InvalidOptions and Environment now say "the target was not modified" instead of "nothing was changed", since host mounts may already have happened.
  • The example now builds on arches other than x86_64 and aarch64. ROOT_TYPE was undefined there, which would break cargo test, and so the RPM's %check, on s390x and ppc64le.

Not changed, but worth knowing:

  • Most bad options (a bad transport, composefs conflicts, a target that isn't a mount point) still surface as Install, whose doc says the target "may have been" partially written.
  • bootc install to-existing-root fails when run on ostree based system bootc-dev/bootc#1343, cited for the --source-imgref failure with several commits, is closed as a duplicate. The rev-parse --single code it describes is still there, so the upstream PR may want a fresh issue for that.

Tested on a 16-core RHEL 10 devspace. Clippy for bootc-lib passed with --all-targets (so the example is covered) and the Makefile's lint set. -D clippy::disallowed-methods hits one pre-existing str::len in deploy.rs, which this PR doesn't touch. just unit-tests passed: bootc-lib 287 passed, including the 4 install_api tests.

Generated-by: https://github.com/cgwalters/#llms

@cgwalters-bot

Copy link
Copy Markdown
Collaborator Author

Superseded by #38, which adds the --output-{json,pairs}-{path,fd} options that were actually asked for instead of a Rust API.

Generated-by: https://github.com/cgwalters/#llms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant