feat: add user-specified mounts to container machines#1837
feat: add user-specified mounts to container machines#1837danielsyauqi wants to merge 2 commits into
Conversation
Adds a repeatable `--mount host:guest[:ro|rw]` flag to `container machine create`, letting users bind-mount arbitrary host directories into a machine the same way `--volume` works for containers. Closes apple#1805. - MachineConfig gains a self-contained `Mount` type and `mounts` field, parsed/validated in `with(_:mounts:)` (source must be an existing dir, guest path absolute, mode ro/rw; duplicate destinations rejected). - The field is Codable with back-compat: boot configs predating mounts decode to an empty list, and an empty list is omitted on encode. Mounts are skipped on the ConfigSnapshotDecoder path since the system-wide `[machine]` TOML config cannot represent arrays of structs. - MachinesService appends each mount as a virtiofs share at boot. - `container machine inspect` surfaces configured mounts. - Docs + 10 new unit tests; full unit suite (573 tests) passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The generic return value was unused at every call site, which fails the project's -warnings-as-errors build (used by make, not by plain swift test). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Local test verificationRun on Apple M5, macOS 26.5, Swift 6.3.2, debug build. Unit tests ( Integration tests, scoped to the machine suites via
The failure is unrelated to this change. It was reproduced on an unmodified This change and its verification were carried out by Claude (Anthropic) at the request of and under review by @danielsyauqi. |
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.json(JSON) only.MachinesService.toContainerConfigappends each configured mount as a virtiofs share at boot, alongside the existing home mount.container machine inspectsurfaces the configured mounts.docs/command-reference.mdanddocs/container-machine.md.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 via
container machine setis deferred, as the currentkey=valuelast-wins semantics do not fit a repeatable list.Testing
Ten unit tests were added to
MachineConfigTestscovering specification parsing (read-write, read-only, multiple mounts), validation failures (missing source, non-directory source, invalid mode, relative destination, malformed input, duplicate destinations), JSON round-tripping, and backward-compatible decoding of configurations without the field. The full unit suite (swift test --skip TestCLI, 573 tests) passes. The integration suite, which boots a virtual machine, has not been run in this environment and should be exercised on an Apple Silicon host before merge.This change was implemented by Claude (Anthropic), at the request of and reviewed by @danielsyauqi.