8000 microvm-rootfs: add ip and nsenter to the guest by norrietaylor · Pull Request #298 · gominimal/pkgs · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions < 8000 a title="packages/microvm-rootfs/build.ncl" class="Link--primary Truncate-text" href="#diff-17065604f76893400365af592f020988f3ea4ee42ec946dc4abfeb281a801b9a">packages/microvm-rootfs/build.ncl
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
let { BuildSpec, Local, OutputData, .. } = import "minimal.ncl" in
let { subsetOf, BuildSpec, Local, OutputData, .. } = import "minimal.ncl" in
let base = import "../base/build.ncl" in
let e2fsprogs = import "../e2fsprogs/build.ncl" in
let git = import "../git/build.ncl" in
let iproute2 = import "../iproute2/build.ncl" in
let util-linux = import "../util-linux/build.ncl" in
{
name = "microvm-rootfs",

# A read-only ext4 guest userland for a libkrun microVM. build.sh snapshots
# the runtime closure (base + git), prunes build-only bulk, and packs an ext4
# image loaded as a virtio-blk block device (/dev/vda). The guest minimald
# ships as the initramfs pid-1, mounts this image, and chroots into it — there
# is no standalone init in the image itself. e2fsprogs is build-only (mke2fs to
# pack the image) and its files are removed before packing, so the image ships
# only the runtime closure. git is in the closure because the in-guest minimald
# session bring-up inits a minimal context that shells out to git.
# the runtime closure (base + git + networking tools), prunes build-only bulk,
# and packs an ext4 image loaded as a virtio-blk block device (/dev/vda). The
# guest minimald ships as the initramfs pid-1, mounts this image, and chroots
# into it — there is no standalone init in the image itself. e2fsprogs is
# build-only (mke2fs to pack the image) and its files are removed before
# packing, so the image ships only the runtime closure. git is in the closure
# because the in-guest minimald session bring-up inits a minimal context that
# shells out to git. iproute2 (ip) and util-linux's nsenter give the guest
# network/namespace plumbing — only the nsenter output is pulled from
# util-linux (subsetOf), not its whole ~18 MB toolset.
runtime_deps = [
base,
git,
iproute2,
subsetOf util-linux ["nsenter"],
],
build_deps = [
{ file = "build.sh" } | Local,
Expand Down
17 changes: 13 additions & 4 deletions packages/microvm-rootfs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@ done
# e2fsprogs is a build-only dependency: it provides mke2fs to pack the image
# below (invoked from the build sandbox PATH, not from $STAGE), but the guest
# never needs it at runtime. Drop its staged files so the runtime image carries
# only the runtime closure. The symlink guard skips a usr-merged /usr/sbin.
if [ -d "$STAGE/usr/sbin" ] && [ ! -L "$STAGE/usr/sbin" ]; then
rm -rf "$STAGE/usr/sbin"
fi
# only the runtime closure. Remove e2fsprogs's sbin tools by name rather than
# nuking usr/sbin wholesale: iproute2 installs `ip` (and ss/tc/bridge) into
# /usr/sbin (SBINDIR=/usr/sbin) and that must survive into the guest. The list
# is the full e2fsprogs sbin set — nothing else in the runtime closure ships
# these names (util-linux is pulled as `subsetOf ["nsenter"]`, so its blkid/
# findfs/fsck/uuidd never reach the image and the e2fsprogs copies must go).
# rm -f tolerates names this e2fsprogs config happens not to build.
for tool in badblocks blkid debugfs dumpe2fs e2freefrag e2fsck e2image e2label \
e2mmpstatus e2scrub e2scrub_all e2undo e4crypt filefrag findfs fsck \
fsck.ext2 fsck.ext3 fsck.ext4 logsave mke2fs mkfs.ext2 mkfs.ext3 \
mkfs.ext4 mklost+found resize2fs tune2fs uuidd; do
rm -f "$STAGE/usr/sbin/$tool"
done
rm -f "$STAGE"/usr/bin/chattr "$STAGE"/usr/bin/lsattr "$STAGE"/usr/bin/uuidgen \
"$STAGE"/usr/bin/compile_et "$STAGE"/usr/bin/mk_cmds
# Note: `libss.so*` (not `libss*.so*`) — the latter also matches openssl's
Expand Down
8 changes: 6 additions & 2 deletions packages/opencode/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ cd "opencode-${MINIMAL_ARG_VERSION}"
bun_version="$(bun --version)"
sed -i "s/\"packageManager\": \"bun@[^\"]*\"/\"packageManager\": \"bun@${bun_version}\"/" package.json

# Install monorepo dependencies (requires network access).
bun install --frozen-lockfile --ignore-scripts
# Install monorepo dependencies (requires network access). NOT --frozen-lockfile:
# our shipped bun resolves upstream's committed lockfile differently and rejects
# it, and this install already network-fetches deps (so it isn't hermetic anyway),
# so let bun float the lockfile. Proper fix = a vendored, bun-version-matched
# bun.lock (tracked in a pkgs issue).
bun install --ignore-scripts

# The build script consults git for a channel name when these are unset;
# set them explicitly so it doesn't shell out to git in the sandbox.
Expand Down
5 changes: 5 additions & 0 deletions packages/util-linux/build.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ let version = "2.42.1" in
bins = { glob = "usr/bin/*" } | OutputBin,
sbins = { glob = "usr/sbin/*" } | OutputBin,

# Granular single-tool output so a consumer can `subsetOf util-linux
# ["nsenter"]` (just the binary + glibc) instead of pulling the whole
# ~18 MB toolset. nsenter links only libc, so no extra outputs are needed.
nsenter = { glob = "usr/bin/nsenter" } | OutputBin,

libblkid = { glob = "usr/lib/libblkid*.so*" } | OutputLib,
libfdisk = { glob = "usr/lib/libfdisk*.so*" } | OutputLib,
libmount = { glob = "usr/lib/libmount*.so*" } | OutputLib,
Expand Down
0