39 Commits

Author SHA1 Message Date
Aditya Ramani 5796abeaea Use a custom volume for build cache inside of a container (#828)
Keep in-container Swift build directories away from the virtiofs
`/workspace` share and use a named volume instead for the cache store
2026-07-31 10:51:05 -07:00
Kathryn Baldauf 3a224e9f90 Make nested virt optional for makefile linux_run helper function (#822)
This PR allows callers to use `linux_run` in the makefile without
relying on nested virtualization by default. This allows us to build a
subset of makefile targets on machines where nested virtualization is
not supported.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-07-28 11:15:27 -07:00
Michael Crosby a4d2510a3c Fix virtiofs makefile syntax (#815)
Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-07-27 12:08:45 -04:00
Michael Crosby 74ace148de Build vminitd and initfs inside the dev container (#810)
Build containerization / containerization (push) Failing after 1s
Build containerization / Verify commit signatures (push) Has been cancelled
Linux build / Determine Swift version (push) Has been cancelled
Linux build / Linux compile check (push) Has been cancelled
Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-07-24 11:04:06 -04:00
Michael Crosby 2563ed5736 feat: virtiofs rootfs hotplug for LinuxPod on cloud-hypervisor (#809)
Build containerization / containerization (push) Failing after 2s
Build containerization / Verify commit signatures (push) Has been cancelled
Linux build / Determine Swift version (push) Has been cancelled
Linux build / Linux compile check (push) Has been cancelled
Release containerization / containerization (push) Failing after 1s
Release containerization / deployDocs (push) Has been cancelled
Release containerization / Publish release (push) Has been cancelled
Allow a container hotplugged into an already-running LinuxPod VM
(addContainer after create()) to have a virtiofs (directory-share)
rootfs, not just an ext4 virtio-blk image, on the cloud-hypervisor
backend.

Host side:
- Generalize CHHotplugProvider.hotplug to branch on the rootfs
runtimeOptions (.virtioblk / .virtiofs / unsupported), reusing the
per-tag virtiofsd/vm.add-fs machinery factored into a new
ensureVirtiofsDevice helper. Make registerMounts the sole writer of the
per-VM mount registry so the rootfs is always first and mounts are not
double-registered (also fixes a latent ordering bug on the block path).
Exclude the rootfs from the /run/virtiofs holding-dir loop in
addContainer.

Guest side (fixes a pre-existing, feature-independent bug):
- The addContainer-after-create (runtime hotplug) path had never been
exercised by any test. cloud-hypervisor adds hot-plugged
virtio-blk/virtio-fs devices to the guest PCI bus but the guest does not
auto-probe them, so a mount by /dev/vdX or virtio-fs tag fails (ENOENT /
tag-not-found) for ALL CH hotplug.
- vminitd's mount RPC now, on a mount failure for a hot-plug-candidate
source (virtiofs type or /dev/vd* source), forces /sys/bus/pci/rescan
and retries with a bounded wait. Scoped so boot-time and non-device
mounts are unaffected.

Tests / build:
- First coverage of LinuxPod.addContainer after create() (CH-only; VZ
has no runtime hotplug): pod hotplug virtiofs rootfs and pod hotplug
block rootfs, registered in a Linux-only test list, plus a
directory-rootfs unpack helper.
- make linux-integration gains an optional FILTER passthrough (make
linux-integration FILTER="pod hotplug").

Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-07-23 11:00:57 -04:00
Michael Crosby b438e97b93 Add cloud-hypervisor VMM backend for Linux hosts (#782)
apple/containerization currently runs containers in per-container VMs on
macOS hosts via Virtualization.framework. This adds a second VMM backend
so the same Swift orchestration layer (LinuxContainer / LinuxPod /
Vminitd gRPC contract) runs on Linux hosts via cloud-hypervisor + KVM.

**CloudHypervisor Swift package** (`Sources/CloudHypervisor/`) — a thin
client for cloud-hypervisor's REST-over-UDS API, layered on
AsyncHTTPClient. Endpoints cover VMM / VM lifecycle / hotplug (disk, fs,
net, vsock, remove-device). Cross-platform (compiles on macOS for unit
tests; consumed at runtime only by the Linux side of Containerization).

**CH backend in Containerization** — one cloud-hypervisor subprocess per
VM, gated behind `#if os(Linux)`. CHVirtualMachineManager /
CHVirtualMachineInstance mirror the VZ shape behind the existing
VirtualMachineManager / VirtualMachineInstance protocol. CHProcess and
VirtiofsdProcess manage the binaries; CHHotplugProvider handles
virtio-blk and virtio-fs runtime hotplug (with one virtiofsd per unique
source-hash tag, refcounted across containers).

**Linux host networking** — BridgeManager brings up a Linux bridge with
an IPv4 subnet and (opt-in via `--enable-nat`) iptables MASQUERADE +
scoped FORWARD rules. LinuxBridgedNetwork enslaves a fresh TAP per
container to the bridge. State is recorded under `/run/containerization`
so `cctl bridge delete` reverses exactly what create did. Bridge
teardown verifies the link kind via sysfs to refuse deleting non-bridge
interfaces.

**cctl run / bridge** — end-to-end Linux container run path (image pull,
ext4 rootfs assembly, VM boot, container exec) plus `cctl bridge
create|delete` for the host network plumbing.

**Build & dist** — `make linux-build` / `make linux-integration` build
and exercise the host side inside an apple/container `--virtualization`
dev container. `make dist-x86_64` produces a deployment tarball (cctl +
cloud-hypervisor + virtiofsd + initfs + kernel) cross-compiled from the
aarch64 dev container; pipeline documented in `docs/x86_64-build.md`.
Static-musl C deps and the Zig cross compiler are pinned by SHA256.

The host orchestrator runs as root. Per-VM runtime state lives under
`/run/containerization/ch/<UUID>` with mode 0700; UDS sockets inside are
bound with mode 0600. Vminitd's gRPC channel inherits that trust
boundary — socket-file perms are the auth.

Sandbox flags are upstream-secure by default. Two per-component opt-outs
exist for the apple/container dev-container case (where the host seccomp
profile SIGSYS-kills CH and virtiofsd):
- `CONTAINERIZATION_NO_CH_SECCOMP=1` — `cloud-hypervisor --seccomp
false`.
- `CONTAINERIZATION_NO_VIRTIOFSD_SANDBOX=1` — `virtiofsd --sandbox
none`. Each emits a one-shot `logger.warning` at process start. Legacy
alias `CONTAINERIZATION_RELAXED_SANDBOX=1` flips both. cctl spawns both
binaries with `setsid` and a minimal env allowlist (PATH / HOME /
RUST_LOG / RUST_BACKTRACE) so the parent's secrets don't leak to
children.

`make linux-integration` runs the cross-platform integration suite
against a real cloud-hypervisor VM inside the dev container. Linux runs
the cross-platform subset (`process true`/`false`/`echo hi`, virtiofs
round-trip, hotplug); the macOS suite is unchanged.

Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-07-02 11:20:22 -04:00
Michael Crosby ddd19a61a8 add x86 kernel config (#765)
Add x86 kernel config and build scripts.

Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-06-16 12:47:20 -04:00
Danny Canter 9275f365dd [Experimental] Add Sandboxy binary (#607)
Release containerization / deployDocs (push) Has been cancelled
Release containerization / Publish release (push) Has been cancelled
Release containerization / containerization (push) Successful in 1s
Sandboxy is an example tool to run isolated coding agents.
2026-06-03 12:27:49 -04:00
Michael Crosby 5fef4e0e10 produce initfs.ext4 for package creation (#706)
This does not break and prevent any other asset from being produced.

Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-04-28 09:54:41 -07:00
Danny Canter 0f4c8cf592 Make unit tests runnable on Linux (#686)
Closes #606

This lets the unit tests be runnable on linux. The change:

- Adds a linux-test makefile target so we can run the unit tests locally
- Fixes up some test code to work on Linux (mostly ifdefs)
- Runs the unit tests in CI now
2026-04-15 16:58:03 -07:00
Danny Canter 6f7e7f98ba makefile: Add goal to build the project in a linux container (#674)
Today our CI builds all of the linux code we have with musl and libc to
ensure everything is silky smooth. We should have a way to do the same
locally. This adds a new macOS only goal that spins up a container
(requires `container` to be installed) that builds an image with our
deps (libarchive and compression libs) and then builds the project. It
supports supplying whatever libc (musl or glibc) to verify they both
work.
2026-04-09 12:19:34 -07:00
Danny Canter a1038a9841 make default goal compile on Linux (#648)
To be able to test vminitd/vmexec/linux specific packages on ci it'd be
a heck of a lot easier if `make` just worked. This should be the last
bit needed. The default goal currently compiles just fine after the
linux specific `make deps` is ran. Next in line would be adding decent
unit tests/actually getting ci setup for the linux bits.
2026-04-06 11:13:16 -07:00
Danny Canter c32d0f3716 makefile: Don't point to /usr/bin/swift on non-macOS (#644)
We hardcode /usr/bin/swift to point to your xcodes swift for the host
code. This isn't the usual path on other OS'.
2026-04-03 12:37:18 -07:00
splint-disk-8i d1b5bdb166 Fix misleading echo in swift-fmt-check target (#585)
Small documentation and Makefile fixes:

- Makefile: swift-fmt-check echo says "Applying" but the target only
checks/lints — changed to "Checking code formatting compliance"
- README.md: "libraries surface" → "libraries' API surface"
- README.md: "light weight" → "lightweight" (consistent with rest of
doc)
- README.md: "for use a default" → missing comma, grammar fix
- CONTRIBUTING.md: "To clarify of what" → "To clarify what"
2026-03-23 12:05:57 -07:00
J Logan 3cfd54cb8a Disable automatic resolution for builds. (#526)
- Improves build reproducibility by using only the pinned dependencies
in Package.resolved.
- Closes #299.
2026-02-09 13:05:40 -08:00
J Logan dadfdcefae Adds opt-in precommit hook to check formatting. (#483) 2026-01-21 11:34:16 -08:00
Kathryn Baldauf ec2ee3e94d Update license header on all files to include the current year (#470)
Related to https://github.com/apple/container/pull/1024

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-01-05 13:08:48 -08:00
Dmitry Kovba aa591a4801 Improvements to Makefile (#370)
Improvement to `Makefile`. Also see
https://github.com/apple/container/pull/822.
2025-10-29 15:38:49 -07:00
Danny Canter 22f7b6ac13 LinuxContainer: Add bootlog as configuration field (#344)
Closes #227

Previously, the bootlog was supplied once in the constructor to
VZVirtualMachineManager which meant that if you used this same manager
for multiple ctrs that all logs would end up going to the same file,
which becomes quite cumbersome to follow..

This change moves bootlog to be a container configuration param and also
moves it to be a VMConfiguration param, so it can be threaded through
from LinuxContainer -> vmm.create() and be truly container unique now.
The largest driver for this was the integration tests which today every
single test spits out logs to a singular file, making guest
investigations tricky to actually look into.

Result after:
```
➜  containerization git:(bootlog-per-ctr) ✗ ls -alh bin/bootlogs
total 1520
drwxr-xr-x@ 24 dcantah  staff   768B Oct 22 17:34 .
drwxr-xr-x@  8 dcantah  staff   256B Oct 22 17:34 ..
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-cat-mount.log
-rw-------@  1 dcantah  staff    22K Oct 22 17:34 test-cgroup-limits.log
-rw-------@  1 dcantah  staff   249K Oct 22 17:34 test-concurrent-processes-output-stress.log
-rw-------@  1 dcantah  staff   167K Oct 22 17:34 test-concurrent-processes.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-devconsole.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-hostname.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-hosts-file.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-manager.log
-rw-------@  1 dcantah  staff    22K Oct 22 17:34 test-container-reuse.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-statistics.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-container-stdin.log
-rw-------@  1 dcantah  staff     0B Oct 22 17:34 test-nested-virt.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-pause-resume-io.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-pause-resume-wait.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-pause-resume.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-custom-home-envvar.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-echo-hi.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-false.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-home-envvar.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-true.log
-rw-------@  1 dcantah  staff    11K Oct 22 17:34 test-process-tty-envvar.log
-rw-------@  1 dcantah  staff    38K Oct 22 17:34 test-process-user.log
```
2025-10-23 03:27:24 -07:00
Eric Ernst 85de8fc0c5 make: fix coverage target (#313)
Address capitalization error

Signed-off-by: Eric Ernst <eric_ernst@apple.com>
2025-10-06 11:16:14 -07:00
J Logan 995a231348 Removes "all rights reserved" from license header. (#309) 2025-10-03 13:27:59 -07:00
Eric Ernst f9ae8f7801 make: add coverage target (#307)
Add coverage target for getting csv code-coverage output

Signed-off-by: Eric Ernst <eric_ernst@apple.com>
2025-10-03 01:43:11 -07:00
J Logan b61b932adf Adds --add-file to allow adding files to initfs. (#302)
- Motivation is to be able to add the `swift-backtrace-static` binary as
needed.
- Use singlular `--add-file` and `--label` options since both accept
multiple invocations with single values each.

Example usage:

```bash
./bin/cctl rootfs create \
                --vminitd vminitd/bin/vminitd \
                --vmexec vminitd/bin/vmexec \
                --add-file /Users/john/.swiftpm/swift-sdks/swift-6.2-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.2-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/aarch64/usr/libexec/swift/linux-static/swift-backtrace-static:sbin/swift-backtrace \
                --label org.opencontainers.image.source=https://github.com/apple/containerization \
                --image vminit:latest \
                bin/init.rootfs.tar.gz
```
2025-09-29 12:38:45 -07:00
Dmitry Kovba 31bfef4a8e Print the Swift version before building (#286)
With the changes in this PR, we'll print the Swift version before
building. This mirrors a similar change in container, introduced in
https://github.com/apple/container/pull/550.
2025-09-11 10:17:24 -07:00
Dmitry Kovba 6a31184ea5 Handle warnings as errors (#271)
To handle warnings as errors when building, use `make`. To allow
warnings, use `make WARNINGS_AS_ERRORS=false test`.

Also see https://github.com/apple/container/pull/535.
2025-08-28 10:39:17 -04:00
Michael Crosby 54980872d9 add ability to export initfs as block (#268)
This refactors the rootfs command to produce an image and have the
ability to create an ext4 formatted block of the init filesystem
directly from the command.

closes #220

Signed-off-by: crosbymichael <michael_crosby@apple.com>
2025-08-15 00:12:14 -07:00
Dmitry Kovba 36a5cd505a Replace public computed properties with locks in setters (#242)
This PR replaces public computed properties with setters in the
`NATNetworkInterface` class with constants to avoid using locks in the
setters. A new instance of `NATNetworkInterface` should be created to
change these values.
2025-08-06 18:29:07 -07:00
Ed Singleton 6dc5489bbe Handle spaces in current dir by quoting paths (#199)
Added "" around some paths so that spaces in directory names will work
2025-07-07 18:27:26 -07:00
Danny Canter 059ff4033f Makefile: Revert recent reworking (#177)
Reverts f9198d6ff7

We can explore better approaches to some of the targets, but for now
lets revert as it interferes with being able to build even if we have
local changes.
2025-06-26 19:31:46 -04:00
Mike Drob f9198d6ff7 Provides explicit makefile targets for files (#167)
fixes #165

`init` depends on `vminitd/bin/vminitd`, `vminitd/bin/vmexec`, and
`bin/cctl`
`integration` depends on `bin/containerization-integration`
`bin/*` get generated via `make containerization`
2025-06-25 13:53:35 -07:00
Dmitry Kovba ebcaf74f42 Regenerate documentation on make docs (#160)
This PR allows using `make docs` without manually removing the existing
`_site` folder.
2025-06-24 13:09:20 -07:00
Danny Canter 5a360242d3 Fix make release goal (#140)
We were using a := assignment for BUILD_BIN_DIR which evaluates any
variables immediately. Our make release logic sets the envvar and then
invokes `all` but at that point the value of BUILD_BIN_DIR has already
been determined.
2025-06-16 17:40:25 -07:00
Michael Crosby 5d2d7a1bc3 update license header removing new line (#99)
Fixes #63

Signed-off-by: crosbymichael <michael_crosby@apple.com>
2025-06-12 09:57:35 -04:00
J Logan 4981faadef Adds base path for GitHub Pages publishing. (#48) 2025-06-09 15:07:50 -07:00
Michael Crosby 9959810656 separate fetch-default-kernel make target (#27)
Signed-off-by: michael crosby <michael_crosby@apple.com>
2025-06-06 15:05:24 -07:00
Danny Canter f49f668936 Updates to license headers (#17)
- Capitalize containerization.
- Wrap "All rights reserved" to a new line.

Signed-off-by: Danny Canter <danny_canter@apple.com>
2025-06-05 16:16:22 -07:00
Kathryn Baldauf 502dab6108 Update containerization apple main (#4)
Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-05 16:15:44 -07:00
Kathryn Baldauf 74dd129094 Update licenses (#3)
Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-05 16:15:39 -07:00
Kathryn Baldauf 3407cc3f16 initial commit
Co-authored-by: Aditya Ramani <a_ramani@apple.com>
Co-authored-by: Agam Dua <agam_dua@apple.com>
Co-authored-by: Danny Canter <danny_canter@apple.com>
Co-authored-by: Dmitry Kovba <dkovba@apple.com>
Co-authored-by: Eric Ernst <eric_ernst@apple.com>
Co-authored-by: Evan Hazlett <ehazlett@apple.com>
Co-authored-by: Gilbert Song <gilbertsong@apple.com>
Co-authored-by: Hugh Bussell <hbussell@apple.com>
Co-authored-by: John Logan <john_logan@apple.com>
Co-authored-by: Kathryn Baldauf <k_baldauf@apple.com>
Co-authored-by: Madhu Venugopal <mvenugopal@apple.com>
Co-authored-by: Michael Crosby <michael_crosby@apple.com>
Co-authored-by: Sidhartha Mani <sidhartha_mani@apple.com>
Co-authored-by: Tanweer Noor <tnoor@apple.com>
Co-authored-by: Ximena Perez Diaz <xperez528@gmail.com>
Co-authored-by: Yibo Zhuang <yzhuang@apple.com>
2025-06-05 16:15:21 -07:00