feat: add user-specified mounts to container machines - #1837
danielsyauqi wants to merge 2 commits into
Conversation
|
@danielsyauqi can you describe how to test these changes locally? You didn't check the
I have also tried it with running a local |
|
This feature is great and exactly what I wanted. I hope it continues to be developed to meet the requirements for merging pull requests. |
cee5710 to
eb6be3b
Compare
|
@mareksapota Thanks for testing this, and sorry for the slow follow-up. The important detail is that machine operations go through the launchd-managed I rebased the branch and retested it with the CLI and every service plugin built from the same revision. Here is the matched-stack procedure I used: make container
bin/container system stop
TEST_ROOT="$(mktemp -d)"
mkdir -p "$TEST_ROOT/rw" "$TEST_ROOT/ro" "$TEST_ROOT/logs"
bin/container --debug system start \
--app-root "$TEST_ROOT/app" \
--install-root "$PWD" \
--log-root "$TEST_ROOT/logs" \
--enable-kernel-install \
--timeout 90
bin/container machine create --no-boot \
--name test-machine \
--home-mount=none \
--mount "$TEST_ROOT/rw:/audit-rw:rw" \
--mount "$TEST_ROOT/ro:/audit-ro:ro" \
ghcr.io/linuxcontainers/alpine:3.20
bin/container machine inspect test-machine | jq '.[0].mounts'
bin/container machine run --root -n test-machine -- touch /audit-rw/from-guest
test -f "$TEST_ROOT/rw/from-guest"
# This command should fail with "Read-only file system".
bin/container machine run --root -n test-machine -- touch /audit-ro/blocked
bin/container machine stop test-machine
bin/container machine rm test-machine
bin/container system stopI also added integration coverage for the create and inspect path plus the actual guest read-write and read-only behavior. If you still get an empty mount list with this setup, please share the output from |
|
Hi @katiewasnothere and @mareksapota! This PR adds user-specified mounts for container machines. It has been rebased and now includes matched-stack integration coverage plus manual guest read-write/read-only verification. Could you take a look when you have time? Thanks! |
|
I've been using this PR for a few days without any problems. This seems like it should be an included feature. |
Great! Hope the maintainer can approve this PR feature to be deployed 😢 |
|
Sorry if this isn't the right place or time to ask. Is it possible to add additional binds to an existing machine? |
|
Yes, this should be possible without recreating the machine, although it would require stopping and restarting it, the mounts are applied at boot rather than hot-plugged into a running machine. I can look into adding support for updating an existing machine if the maintainers would prefer it in this PR. |
Add a repeatable --mount host:guest[:ro|rw] option to container machine create. Persist validated mounts in the machine boot configuration, expose them through inspect, and add them as virtiofs shares at boot. Include backward-compatible decoding, documentation, and unit and integration coverage.
2332c52 to
aba26f5
Compare
|
Hi @jglogan, could you help triage this PR or point me to the appropriate reviewer? It implements #1805 and is rebased onto current main. The branch now complies with the signed-commit requirement, and the resulting tree is identical to the version covered by the unit, integration, and manual runtime tests described above. I’m happy to adjust the create-time-only scope if the team prefers. Thanks! |
|
@katiewasnothere @egernst, could either of you help review or route this PR when you have time? The multiple-mount capability being independently requested in #2278. The scope remains limited to create-time, repeatable I’m happy to adjust the scope or implementation if the maintainers prefer a different direction. |
Type of Change
Motivation and Context
Closes #1805.
container machinecurrently mounts only the user's home directory, configurable through--home-mount. There is no way to bind-mount additional arbitrary host directories into a machine, which the issue requests for parity with the container--volumeworkflow.This change adds a repeatable
--mount host:guest[:ro|rw]option tocontainer machine create:Summary of changes:
MachineConfiggains a self-containedMounttype (source,destination,readOnly) and amountsfield. Specifications are parsed and validated inwith(_:mounts:): the host path must be an existing directory, the guest path must be absolute, the mode must beroorrw(defaultrw), and duplicate destinations are rejected. Paths are resolved to absolute form at parse time.ConfigSnapshotDecoderpath because the system-wide[machine]TOML section cannot represent arrays of structs. Mounts are a per-machine value carried inboot-config.jsononly.MachinesService.toContainerConfigappends each configured mount as a virtiofs share at boot, alongside the existing home mount.container machine inspectsurfaces the configured mounts.Scope is limited to create time for this revision. Mounts are fixed for the lifetime of a machine. Adding or removing mounts on an existing machine through
container machine setis deferred because the currentkey=valuelast-wins semantics do not fit a repeatable list.Testing
Tested on Apple M5, macOS 26.5, Swift 6.3.3, using a debug build with all CLI and service components built from the same revision.
make container: passed and packaged the CLI and service plugins.make test: warnings-as-errors build passed, followed by all 765 non-integration tests.swift test --filter MachineConfigTests: all 22 tests passed.TestCLIMachineCommand/testCreateWithMounts: passed. It verifies that repeated read-write and read-only mount options survive create, persistence, and inspect.TestCLIMachineRuntimeSerial/testUserMountsReadWriteAndReadOnly: passed. It boots the machine, writes from the guest through the read-write mount, verifies the file on the host, and confirms that the read-only mount rejects writes.The same read-write propagation and read-only enforcement were also verified manually against an isolated application root.