Repository navigation
feat: add user-specified mounts to container machines - #1837
danielsyauqi wants to merge 6 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. |
|
@danielsyauqi I tried using your branch but it didnt work for me. I wanted to mount a sub-folder of my home directory as home directory inside machine (do not want to expose full home inside machine). Is this use case supported in your PR? |
|
Thanks for trying it, @deepio-oc. Yes, that use case should be supported at machine creation by disabling the default full-home mount and mounting the selected subfolder at the guest home path: This currently requires a new machine because mounts are fixed at creation time. Also, please ensure the CLI and machine-apiserver plugin are built and running from the same revision. If this still fails, could you share the exact command, bin/container system version, and bin/container machine inspect test-machine output? I’ll reproduce this specific home-replacement case and add coverage if needed. |
|
@danielsyauqi I just tried with your latest code and I dont think it is working. how do I update the apiserver from the generated binaries? |
|
Thanks for the detailed output. Your CLI is built from the PR branch, but system version shows the running container-apiserver is still 1.4.1. From the PR branch’s root, please run: In system status, |
|
@danielsyauqi I updated the apiserver. One issue I see with your example command is that machine is failing to create user (since home is already mounted I think) |
|
Thanks for confirming that the CLI and apiserver now match. You're right: my example exposed a separate first-boot user setup bug. The guest home mount is present before user creation, and setup was trying to initialize the host-backed directory. Sorry for the misleading example. I pushed The test bundle builds and the non-integration tests pass. I added regression cases for a nonempty home directory and for the full machine create/boot path; the VM cases have not been run locally. Could you rebuild the CLI and restart the machine-apiserver from this updated branch, confirm both report |
|
Thanks for picking this up. Could the same flag also accept a named volume as the source, the way Various use cases, for this: data that must survive
This also connects to the flag name, which is not consistent with containers. Hoping for a review on this! |
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.