Support host:guest mount syntax with WORKINGDIR resolution
CI / build (pull_request) Successful in 13s
CI / build (push) Successful in 13s

--mount now accepts <host-path>:<guest-path> (Docker-style). When the
guest path is omitted, the host path is used. Non-absolute guest paths
are resolved against the image WORKINGDIR, which is written to
/slim/workdir at build time and read by slim-init.sh at boot.

Changes:
- qemu.rs: Parse host:guest spec, pass guest path (not host path) on
  the kernel cmdline as slim.mount=<tag>:<base64(guest_path)>
- inject.rs: Accept working_dir param, write /slim/workdir into rootfs
- build.rs: Pass config.working_dir to inject()
- slim-init.sh: Read /slim/workdir, resolve relative guest paths
  against it before mounting
- test.sh: Test host:guest absolute paths (multi-mount) and relative
  guest path resolved against WORKINGDIR

Addresses PR #9 review comment from @hulthe.
This commit was merged in pull request #9.
This commit is contained in:
2026-09-10 12:21:44 +02:00
parent c3b6a72d39
commit 93cbf7ca47
3 changed files with 38 additions and 17 deletions
+12 -3
View File
@@ -100,9 +100,14 @@ fn install_into_rootfs(mount: &str, name: &str, mode: &str, content: &str) -> Re
Ok(())
}
/// Inject /slim/init, /slim/exec, and optionally /slim/user into a mounted
/// container image rootfs.
pub fn inject(mount_path: &Path, exec_script: &str, user: Option<&str>) -> Result<()> {
/// Inject /slim/init, /slim/exec, and optionally /slim/user and /slim/workdir
/// into a mounted container image rootfs.
pub fn inject(
mount_path: &Path,
exec_script: &str,
user: Option<&str>,
working_dir: Option<&str>,
) -> Result<()> {
let mount_str = mount_path.to_str().context("mount path is not UTF-8")?;
install_into_rootfs(mount_str, "init", "755", SLIM_INIT)?;
@@ -112,5 +117,9 @@ pub fn inject(mount_path: &Path, exec_script: &str, user: Option<&str>) -> Resul
install_into_rootfs(mount_str, "user", "644", user)?;
}
if let Some(dir) = working_dir.filter(|d| !d.is_empty()) {
install_into_rootfs(mount_str, "workdir", "644", dir)?;
}
Ok(())
}