Inject universal /slim/init instead of requiring container-specific setup
CI / build (pull_request) Successful in 12s

slim now works with any Containerfile by injecting distro-agnostic scripts
at build time:

- /slim/init: mounts special filesystems, configures networking (static
  QEMU slirp), sets up cgroup2, timezone, and rootless container prereqs.
  Parses slim.cmd=<base64> from the kernel cmdline for runtime overrides,
  otherwise execs /slim/exec.

- /slim/exec: generated from the image's CMD/ENTRYPOINT (via podman image
  inspect), overridable via --cmd at build and run time.

Changes:
- New src/inject.rs: inspect image config, infer command, generate
  /slim/exec script, inject /slim/ into mounted rootfs
- New src/scripts/slim-init.sh: the universal init script (include_str!)
- build.rs: rename --init to --cmd, inject scripts before packing,
  drop Meta::save, restructure to ensure unmount always runs
- qemu.rs: hardcode init=/slim/init, add --cmd (base64 on cmdline),
  drop Meta::load, add -no-reboot
- Remove src/meta.rs and meta.toml (no longer needed)
- Cargo.toml: add serde_json + base64, remove unused walkdir + cpio + toml
- Example Containerfiles simplified to plain FROM + CMD
- New example/test.sh for manual verification
- README updated for new workflow
This commit is contained in:
2026-09-08 21:43:38 +02:00
parent 506213ed9a
commit 1eed382172
14 changed files with 525 additions and 287 deletions
+3 -4
View File
@@ -5,14 +5,13 @@ edition = "2024"
[dependencies]
anyhow = "1.0.104"
base64 = "0.22"
clap = { version = "4.6.6", features = ["derive"] }
flate2 = "1.1.9"
walkdir = "2.5.0"
cpio = "0.4.1"
serde = { version = "1.0.229", features = ["derive"] }
serde_json = "1.0"
xdg = "3.0.0"
tempfile = "3.27.0"
toml = "1.1.4"
serde = { version = "1.0.229", features = ["derive"] }
[dev-dependencies]
tempfile = "3.27.0"