255 Commits

Author SHA1 Message Date
Noah Thornton edd6dee2db Integration coverage xpc helpers (#1551)
- This fixes the LLVM coverage data not properly being emitted for XPC
  services. It requires piping the `LLVM_PROFILE_FILE` environment
  variable through to all the services and plugins. The variable itself
  also required the "%c" formatter to ensure that it continuously emits
  coverage data, otherwise when XPC services are killed via "bootout" they
  do not emit coverage.
2026-07-06 15:43:30 -07:00
J Logan 3ad6e9b8ba Removes obsolete CLITests directory. (#1886)
- Closes #1833.
2026-07-02 17:30:31 -07:00
J Logan 76f387e3be Restore reverted migrations, migrate last tests. (#1880)
- Part of #1833.
- CLI progress and registry test migrations were inadventently reverted
by #1857.
- Migrate TestCLINoParallelCases to TestCLIImagePruneSerial and
TestCLINetworkPruneSerial.
- Clean up test selection patterns in Makefile.
- Remove all legacy CLITests files.
- Use swift-testing `withKnownIssue` to run but ignore failures on flaky
`testCreateNameLongestValid` and `testIsolatedNetwork`.
- Extracts a fixture helper for tests requiring a retry loop.
2026-07-02 15:34:46 -07:00
Kathryn Baldauf d9fdf39af6 Add TestCLISystemLogs and TestCLITermIO integration tests in new integration test suite (#1879)
This PR adds two test suites that were missing from the new integration
test suite

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-07-01 20:18:31 -07:00
Kathryn Baldauf 4a79060595 Ensure test filenames match test suite names and each file has a single suite defined (#1877)
This PR cleans up some of the new IntegrationTests files to ensure that
each file has a single test suite defined within it and the name of the
file matches the name of the test suite.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-07-01 16:03:03 -07:00
J Logan 69a2505aeb Migrates container run integration tests. (#1857)
- Part of #1833.
2026-07-01 13:23:16 -07:00
J Logan 9bd3c47345 Migrates container create, run-lifecycle, exec, remove, copy. (#1844)
- Part of #1833.
2026-06-30 17:37:51 -07:00
J Logan 88ab3192f9 Migrate image, volume and miscellaneous system tests. (#1868)
- Part of #1833.
- Distributes fixture extensions for images and containers added as part
of previous builder PR to more sensible locations.
2026-06-30 15:25:16 -07:00
J Logan 586fa07d2a Migrate registry tests to new test support types. (#1845)
- Part of #1833.
2026-06-30 10:40:26 -07:00
J Logan d29e6edd5e Migrates network integration tests. (#1858)
- Part of #1833.
2026-06-30 10:00:34 -07:00
J Logan 3842977f4a Migrate basic system tests to new test support types. (#1841)
- Part of #1833.
2026-06-29 16:40:06 -07:00
J Logan c37c405bbd Migrates container machine tests. (#1856)
- Part of #1833.
2026-06-29 15:58:19 -07:00
J Logan 6317a832d4 Adds build fixture and migrates build CLI tests. (#1848)
- Part of #1833.
- Also changes test directory names to include test ID so that they are
easily identifiable.
2026-06-29 12:12:31 -07:00
J Logan be3b1f20c4 Migrate some container tests, remove concurrent demo tests. (#1840)
- Part of #1833.
- Tweaks `ContainerFixture.withContainer()` to support the legacy
`longRun()` pattern without boilerplate.
2026-06-26 14:17:18 -07:00
J Logan 649164d9e2 Enhanced test fixtures for integration tests. (#1834)
- Part of #1833.
- Adds `ContainerFixture` with scoped resource lifecycle and cleanup in
place of implementation inheritance for test support functions. The
fixture also handles resource prefixing and uses a more ergonomic
`CommandResult` in place of a tuple for return values.
- `ImageWarmup` suite pre-pulls well-known images, and
`copyWarmupImage()` tags test-local refs, keeping the canonical image
store untouched.
- Three-phase `integration-new`: warmup, followed by concurrent tests
(managed by the swift test
`--experimental-maximum-parallelization-width` flag), followed by
serialized tests.
- `coverage-new` merges unit + integration-new profraw, replacing
`coverage` in CI as a migration progress indicator.
- Updates GH workflow so non-coverage invokes both the `integration` and
`integration-new` Makefile targets, while coverage runs invoke the
`coverage-new` target.
2026-06-26 12:00:44 -07:00
John Costa aa7fef3d1d Route container image save reference list to stderr in stdout mode (#1804)
- Fixes #1801.
- When `container image save` runs without `--output`,
  stdout carries the OCI tar archive. The command writes 
  the archive bytes to stdout and then `print(reference)`s
  each saved image reference to stdout afterward,
  appending non-archive text after the tar EOF marker,
  which will cause strict tar/OCI consumers to fail.
- This routes the saved-reference list to stderr in the
  no-`--output` branch, so stdout contains only archive
  bytes. When saving to a file via `--output`, stdout is
  free, so the references continue to print to stdout
  exactly as before.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 10:04:30 -07:00
Hugo, CY LAU 0c95007763 perf(parser): add collection capacity hints to known-size loops (#1791)
- For result sets with known sizes, it's more efficient
  to supply the size as a capacity hint.
2026-06-25 19:42:37 -07:00
J Logan 984c4c2c5a Disable flaky CLI test temporarily. (#1828)
- PRs are backed up. We need to rework the CLI tests
  to shorten test time and fix conflicts between tests.

## Testing
- [ ] Tested locally
- [x] Added/updated tests
- [ ] Added/updated docs
2026-06-25 08:42:01 -07:00
adityabagchi24 09489cba45 fix(cp): resolve relative host paths against current directory (#1741)
Fixes #1738

`container cp` fails when the host source path is relative (e.g.
`container cp file foo:/root/`), because `NSString.standardizingPath`
only canonicalizes paths but does not make them absolute. The unchanged
relative path is then interpreted as `/file` (root-absolute) by
`URL(fileURLWithPath:)` on the runtime side.

Fixed by resolving relative paths against the current working directory
before use, matching the pattern already used by `container export`,
`container image save`, and `container image load`.

The same fix was also applied to the copy-out destination path (line
68), which had the same issue.

## Type of Change

- [x] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context

`container cp file foo:/root/` fails with `"copyIn: source not found
'/file'"` because the relative path `file` is never expanded to an
absolute path. Using `$PWD/file` works, but relative paths should work
too — every other command in the codebase handles this correctly.

## Testing

- [x] Tested locally — builds and all existing tests pass
- [ ] Added/updated tests
- [ ] Added/updated docs

---------

Co-authored-by: jwhur <57657645+JaewonHur@users.noreply.github.com>
2026-06-22 11:54:00 -07:00
J Logan 888582b4c8 Propagate permissions for all host-to-container socket mounts. (#1751)
- Closes #1750.
- Applies permission code used for the `--ssh` mount to all
host-to-container socket mounts.
- Adds a user option to the `doExec` test support function.
- Updates the `testRunCommandUnixSocketMount` to install `nc` in the
test container, and check the socket permission, and check the mounted
socket using `nc` as the guest user.
2026-06-18 11:45:24 -07:00
Michael Crosby c4a22389ac add container machine nested virt (#1742)
This also includes custom kernels for container machine. Its required
with nested virt as CONFIG_KVM needs to be enabled.

---------

Signed-off-by: michael_crosby <michael_crosby@apple.com>
2026-06-18 06:53:21 -07:00
J Logan ee848e3ebf Add backward compat for ContainerConfig cpuOverhead. (#1665)
1.0 data migration requirement
2026-06-08 15:02:18 -07:00
Raj b2994ac369 Add container machine for managing persistent Linux VMs (#1662)
## Type of Change
- [ ] Bug fix
- [x] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
`container` runs each workload in an ephemeral VM, so there's no
built-in way to keep a persistent Linux environment you can log into and
work in. `container machine` adds one.

A container machine is a lightweight, persistent, and integrated Linux
environments that feel like an extension of your Mac, created from
standard OCI images with a familiar UX. The login user matches your host
account with passwordless `sudo`, your home directory is mounted inside
the VM, and each machine keeps its filesystem and runs the image's own
init system (such as`systemd` or `openrc`).

```bash
container machine create alpine:3.22 --name my-machine
container machine run -n my-machine # interactive shell
container machine set -n my-machine cpus=4 memory=8G
```

Subcommands: `create`, `run`, `list` (`ls`), `inspect`, `set`,
`set-default`, `logs`, `stop`, `delete` (`rm`); `m` aliases `machine`.
Docs added to `docs/command-reference.md` (Machine Management) and
`docs/how-to.md` ("Use container machines").

## Testing
- [x] Tested locally
- [x] Added/updated tests
- [x] Added/updated docs

Signed-off-by: Raj Aryan Singh <rajaryan_singh@apple.com>
Co-authored-by: Jaewon Hur <jaewon_hur@apple.com>
Co-authored-by: John Logan <john_logan@apple.com>
Co-authored-by: Michael Crosby <michael_crosby@apple.com>
Co-authored-by: Eric Ernst <eric_ernst@apple.com>
Co-authored-by: Danny Canter <danny_canter@apple.com>
2026-06-08 11:38:49 -07:00
AJ Emory 847a004eac Conform containers to ManagedResource (#1656)
- Closes #1651 
- Adds ManagedContainer that conforms to Managed Resource
2026-06-05 17:27:56 -07:00
Kathryn Baldauf d855978113 Remove duplicated image name in image JSON output (#1655)
https://github.com/apple/container/pull/1652 rearranged the JSON output
for image resources and included a duplicate "name" field. After further
discussion, we've decided to remove the duplicate field.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-06-05 15:11:06 -07:00
J Logan 90cc3c15af Omit hash scheme from image.id. (#1658)
- Closes #1657.
- Also reduces `trimDigest()` output to 12 characters and gets rid of
the trailing ellipsis.
2026-06-05 14:43:20 -07:00
Raj 822b47b877 Fix --format yaml and toml output (#1653)
- Closes #1528.
- Several commands (`builder status`, `image list`,
  `stats`, `system df`, `system status`) advertised
  `--format yaml` and `--format toml` but only handled
  `json`, and every other format fell through to the
  table. With this PR, we now route them through one
  shared renderer with an exhaustive switch over the
  format enum, so a missing format would now be a
  compile error, and not just fail silently.
- Since TOML has no top level array, TOML output
  now wraps list payloads under an `items` key,
  because otherwise it was returning nothing for lists.
- `stats` now prints one static result for machine
  readable formats instead of opening its live table
  view.
- `builder status` now returns an empty list for
  json/yaml/toml when no builder is running, instead 
  of the unparseable "builder is not running" text.
  The table view keeps the message.
- with `--quiet` and no builder it now exits 0 with
  no output, earlier it exited non-zero.
2026-06-05 08:32:12 -07:00
J Logan 59e015acd1 Use name instead of id in NetworkConfiguration. (#1648)
- Closes #1647.
- `id` will become a system assigned (Docker-like) identifier
  for the managed resource, and `configuration.name` is the
  user-assigned name.
2026-06-04 13:03:29 -07:00
AJ Emory 605045faeb Fix make test SIGSEGV on Swift 6.2 (#1638)
- Closes #1637.
2026-06-03 18:37:16 -07:00
J Logan 89fa98c55a Write log/error output from commands to stderr. (#1632)
- Closes #1631.
- The standard output should only contain result data,
  so that scripts consuming stdout don't need to scrape.
2026-06-03 16:17:59 -07:00
Di Warachet S. 4c22305eda Fix TestCLIVersion build-type check for release CI (#1627)
Fix TestCLIVersion build-type check for release CI (#1627)
- Refer to https://github.com/apple/container/issues/1626
2026-06-02 11:02:38 -07:00
J Logan e20aca8203 Normalize JSON output for network and volume resources. (#1624)
Normalize JSON output for network and volume resources. (#1624)
- Reworks both JSON output presets to use sorted keys, ISO timestamps.
`compact` is used for `ls` output, and `pretty` is used for `inspect`.
- Extracts non-DRY option configuration into presets.
- Closes #1623.
2026-06-01 21:42:10 -07:00
Di Warachet S. 34cff5925f Use a consistent container CLI path in integration tests (#1621)
Use a consistent container CLI path in integration tests. See https://github.com/apple/container/issues/1602.
2026-06-01 21:38:10 -07:00
Kathryn Baldauf 55f1e4fdf4 Create ImageResource conforming to ManagedResource (#1619)
- Closes #1625.
- For now, the ImageResource compliance happens
  at the CLI level. We will work on pushing that into or
  closer to the APIServer at a later time.

## Testing
- [x] Tested locally

---------

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-06-01 17:01:20 -07:00
Raj 7358102c68 Fix system df to count content blobs and deduplicate shared storage (#1555)
- Closes #1526 and #1527.

## Type of Change
- [x] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
This PR fixes `system df` to report actual on-disk allocated bytes
(content blobs + snapshots) instead of summing per-image snapshot sizes.
Orphaned blobs are now included as reclaimable, and storage shared
across tags is no longer double counted. Also consolidates three
identical `calculateDirectorySize` implementations into a shared
`FileManager.allocatedSize(of:)` extension.

## Testing
- [x] Tested locally
- [x] Added/updated tests
- [ ] Added/updated docs
2026-06-01 15:44:43 -07:00
Chris George da8daf31de Use FilePath for PublishSocket (#1594)
- Closes #1593.
2026-06-01 13:35:58 -07:00
J Logan 37595a734c Remove XPC compatibility code, simplify network model. (#1616)
- Refactor network model types: replace `NetworkState` enum and
phase-based NetworkStatus with a flat `NetworkStatus` struct.
- Simplify API server ↔ plugin protocol: plugin `status()` returns
runtime status only, API server owns configuration.
- `NetworksService` `list()`/`create()` now return `NetworkResource`
directly.
- Remove lifecycle phase checks and state machine guards throughout CLI
and API server.
- `variant` is plugin-specific, it's not a required property. This PR
replaces `NetworkPluginInfo` with a `plugin` name property on
`NetworkConfiguration` and an `options` list similar to that for
volumes.
- Moved `variant` to the option list.
2026-05-29 12:33:45 -07:00
J Logan c5a8d7a802 Reorganize Swift package targets for network plugin. (#1615)
- Part of #1404.
- Updates containerization to 0.33.2.
- Reorganizes network plugin targets into:
  - `ContainerNetworkClient` - network plugin client and default types
- `ContainerNetworkServer` - separate protocols for `Network` which
manages the underlying virtual network, `NetworkService`, which takes a
network and implements the API, and an actor `NetworkHarness` that
marshals between the API and the XPC protocol. The service-harness
separation will help us ensure XPC protocol compatibility in both
directions as we evolve the plugin APIs.
- Removes `disableAllocator()` which is no longer used since #1545
switched over to using XPC connections between runtime and network
plugin instances to track whether a network has attached containers.
2026-05-28 15:26:31 -07:00
J Logan 445c90f927 Fix potential integer math crash on PublishPort. (#1612)
- Closes #1610.
- Discovered, and originally filed as a security advisory, by:
PresidentL <131139636+liyander@users.noreply.github.com>.
- `PublishPort` currently can store invalid combinations of starting
port and range that can overflow UInt16 values when summed, crashing the
process.
- Updates `PublishPort` to validate inputs on initialization.
2026-05-28 11:12:04 -07:00
Kathryn Baldauf 046884df37 Use ManagedResource for volumes in CLI commands (#1607)
## Type of Change
- [x] New feature  

## Motivation and Context
Related to https://github.com/apple/container/issues/1404.

This PR adds the initial work to have volume resources conform to
ManagedResource, in alignment with other resources such as networks (see
[here](https://github.com/apple/container/pull/1421)). Further work is
necessary to move the use of `VolumeResource` down to the APIServer (in
the VolumesService) and in the volume client. Volumes do not currently
have any plugin or runtime state, so that information is not included in
the `VolumeResource`, but could be added later if needed.

## Testing
- [x] Tested locally

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-05-28 09:33:21 -07:00
J Logan d43b58ec73 Align JSON output with shape for container resource. (#1611)
- Part of #1404.
- Use `configuration` for configuration properties, `state` for current
state label, `status` for status properties.
2026-05-28 09:07:01 -07:00
NONE 685966d026 cli: resolve subcommand path in container help (#1587)
- Fixes #1509. The CLI's own help text tells users to
  run `container help <subcommand>`, but every form
  of that results in an error.
- Added a captured subcommand path, walked 
  Application`'s `subcommands` + `groupedSubcommands`
  tree (matching `commandName` and `aliases`), and
  printed `Application.helpMessage(for:)` for the resolved
  target. Empty path keeps existing plugin-aware top-level
  help; unknown path throws `ValidationError`.
2026-05-27 10:54:49 -07:00
J Logan ca3a4d6670 Use FilePath for app, install, and log roots. (#1558)
- Closes #1557.
- Replaces `executableURL` utility function for getting app executable
path with `executablePath`.
- Adds `FilePath.resolvingSymlinks()` extension.
- Also converts for FilePath for types in `ContainerVersion` target.
2026-05-26 13:58:55 -07:00
Erwan Legrand 831a6bfe1c fix: clamp ProgressBar barLength to non-negative value to avoid crash (#1525)
- Closes #1547.
- A negative progress value (e.g. from a race in progress events) would
produce a negative barLength and crash inside String(repeating:count:).
Wrap the computed length in max(0, ...) and add a regression test that
calls set(size: -10) and exercises draw(state:detail:).
2026-05-21 19:11:28 -07:00
Danny Canter de780c1478 cli: Add support for --stop-signal (#1462)
- Closes #1581.
- This adds stop signal support to the cli. The priority is:
  1. If an explicit stop signal is passed on the cli use this.
  2. If not, check if there is a stop signal in the image config.
  3. Finally, use the default (TERM).
2026-05-21 17:55:48 -07:00
jwhur 145867e6e2 Add more tests for container copy (#1579) 2026-05-20 13:04:49 -07:00
AJ Emory afeceb05d4 Reorganize runtime targets for scalable plugin support (#1577)
## Type of Change
- [x] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
Closes #1569

Separates generic runtime infrastructure from Linux-specific
implementation into distinct SPM targets:

- ContainerRuntimeClient — generic runtime plugin client API
- ContainerRuntimeLinuxClient — Linux-specific types
- ContainerRuntimeLinuxServer — Linux runtime service + interface
strategy implementations

Renames types to reflect the runtime/sandbox distinction:
- SandboxClient → RuntimeClient
- SandboxService → RuntimeService
- SandboxRoutes → RuntimeRoutes
- SandboxKeys → RuntimeKeys

Breaking for external consumers:
- ContainerSandboxService removed, replaced by ContainerRuntimeClient +
ContainerRuntimeLinuxServer
- Public types renamed

## Testing
- [x] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs
2026-05-20 12:57:10 -07:00
Saehej Kang 4f097eb891 [images]: fix image load error to write to stderr and use FilePath (#1570)
- Closes #1535.
- Closes #1573.
2026-05-20 10:46:17 -07:00
Simone Panico 9895ba8d08 Add container copy/cp command for host-container file transfer (#1190)
## Type of Change
- [ ] Bug fix
- [x] New feature  
- [ ] Breaking change
- [x] Documentation update

## Motivation and Context
Adds the `container copy` (aliased as `cp`) command to copy files
between a running container and the local filesystem.

I saw [#1023](https://github.com/apple/container/pull/1023) and the
feedback from @dcantah — the previous attempt relied on tar being
installed inside the container.
This implementation takes the recommended approach:
file transfers go through the guest agent via the existing
`copyIn`/`copyOut` methods on the core `Containerization`, with no
dependency on container tooling.

## Testing
- [x] Tested locally
- [x] Added/updated tests
- [x] Added/updated docs

---------

Co-authored-by: jwhur <57657645+JaewonHur@users.noreply.github.com>
2026-05-20 10:03:36 -07:00
Raj bd1916f9b3 Make inspect error handling for missing resources consistent (#1564)
- Closes #1539.
- All `inspect` commands now consistently return
  exit 1 with a clear error when a requested resource
  is missing.
2026-05-16 08:28:37 -07:00