Commit Graph

219 Commits

Author SHA1 Message Date
Morris Richman dd6bdc20cf Expose Command Structs for Plugins (#603)
## Type of Change
- [ ] Bug fix
- [x] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
Plugins technically exist, but to add shortcuts or to do existing things
with functions in `container` requires calling a compiled binary. This
pull request aims to remove that hurdle and instability by exposing
commands as a new `ContainerCommands ` target.

Simply import `ContainerCommands` and you can access almost
any command as if it were a native part of the binary. This makes
plugin development significantly easier.

Closes #609.
2025-09-17 15:24:26 -07:00
Dmitry Kovba 3e52a3c305 Fix failing network tests (#620)
This PR fixes failing network tests by using lowercased names.
Additionally, it reduces code duplication.
2025-09-17 09:59:43 -07:00
Dmitry Kovba c571546f60 Use a lock consistently in the ExecutionContext class (#619)
The changes in this PR improve the consistency of using a lock in the
`ExecutionContext` class.
2025-09-17 09:49:30 -07:00
J Logan 449f1d23df Replace scattered defaults subcommands with system property. (#604)
Common subcommands for all defaults.

- Closes #384.
- Replaces `registry default` and `system dns default` subcommands with
`system property`.
- Users can use `system property ls` to see details about each supported
default value.
- `system property set` implements reasonable validation for all
properties.
- NOTE: Probing of the registry for `registry default set` was removed,
which means users will find out about a botched setting when pulling or
pushing.
- Updates docs.

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

## Motivation and Context
See #384.

## Testing
- [x] Tested locally
- [x] Added/updated tests
- [x] Added/updated docs
2025-09-16 13:37:55 -07:00
Kathryn Baldauf 386fd87b5d Enumerate using relative paths to avoid mismatch with symlink resolution of special paths like /tmp (#613)
## Type of Change
- [x] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
Fixes https://github.com/apple/container/issues/588. This PR changes the
archiver compression file enumeration to use the
[enumerator(atPath:)](https://developer.apple.com/documentation/foundation/filemanager/enumerator(atpath:))
version. This version returns relative paths instead of full file paths
from the filesystem. /tmp is symlinked to /private/tmp and some swift
packages will handle that path differently. While a call to Foundation's
`URL.resolvingSymlinksInPath()` will return "/tmp", a call to
`FileManager.enumerator(at:)` will return "/private/tmp". This
difference causes a container image build to fail when the user is using
a path under /tmp or other special case paths as the context directory.

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

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-09-16 10:52:08 -07:00
J Logan 79cc363e78 Relocates API server to Helpers, service to Services. (#616)
- Closes #615.

Improves project organization. Separates service so it can be tested and
used separately from the executable target. No functional changes.
2025-09-16 10:14:14 -07:00
J Logan a54be363f7 Add --labels for networks. (#600)
- Closes #557.
- Breaking change: removes `.upToNextOption` for labels on volumes as
this is not what is done for containers, and it forces the argument to
precede the options if a label is supplied, which is non-intuitive.

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

## Motivation and Context
Consistent features and UX across managed resources.

## Testing
- [x] Tested locally
- [x] Added/updated tests
- [x] Added/updated docs
2025-09-15 11:27:51 -07:00
J Logan 9692d79040 Bump containerization dependency to 0.7.2. (#610)
## Type of Change
- [ ] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
0.7.1 containerization contained a couple inadvertent commit reverts.

## Testing
- [ ] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs
2025-09-15 09:07:42 -07:00
Kathryn Baldauf 1b68728629 Update builder shim version to 0.6.1 to support default global args (#605)
## Type of Change
- [x] Dependency update

## Motivation and Context
A change was made in container-builder-shim to support BuildKit's
default global args
https://github.com/apple/container-builder-shim/pull/44. A new tag of
container-builder-shim was made with this change and this PR updates to
that new tag for container-builder-shim.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-09-12 15:11:49 -07:00
J Logan 243115504e Use containerization 0.7.1. (#606)
- Makes available the proxy utility from containerization#288.

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

## Motivation and Context
The proxy utility allows forward progress on #533.

## Testing
- [x] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs
2025-09-12 12:49:57 -07:00
Dmitry Kovba 32e8c23265 Remove per-target concurrency checking (#601)
With `swift-tools-version: 6.2`, strict concurrency checking is enabled
by default - there is no need to enable it explicitly.
2025-09-11 11:42:02 -07:00
J Logan 58e0ddd948 Revert inadvertent pull platform filtering from #545. (#593)
- Reverts an inadvertent "fix" from #545.
- Closes #592.

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

## Motivation and Context
See #592 

## Testing
- [x] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs
2025-09-10 10:22:55 -07:00
J Logan 0ba2c42d95 Pass DNS integration tests when default domain is set. (#594)
- Closes #547.
- Reduce DNS test count, make tests more readable.

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

## Motivation and Context
Painful to have to unset the default domain on a dev system to pass
local integration tests.

## Testing
- [x] Tested locally
- [x] Added/updated tests
- [ ] Added/updated docs
2025-09-10 10:22:34 -07:00
J Logan 9db6c5f974 Docs: Update upgrade process in README.md. (#595)
- Closes #568.

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

## Motivation and Context
Uninstall script will fail with an informative message if the users
doesn't run `container system stop`, but including this step in the
upgrade process reinforces the need to do this. Upgrading without
restarting the service can lead to unexpected failures due to API or
persistent data incompatibility.

## Testing
- [ ] Tested locally
- [ ] Added/updated tests
- [x] Added/updated docs
2025-09-10 10:07:09 -07:00
J Logan 6da5ecf838 Remove images alias for image subcommand. (#597)
- Closes #596.

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

## Motivation and Context
- Part of UX audit #385.
- All other resource subcommands are singular and have no plural alias.
- `container image` corresponds to `docker image`; `container images`
does not.

## Testing
- [x] Tested locally
- [x] Added/updated tests
- [x] Added/updated docs
2025-09-10 10:06:48 -07:00
Dmitry Kovba f3db805e3a Add a build parameter to handle warnings as errors (#591)
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/containerization/pull/271.
2025-09-09 17:39:50 -07:00
J Logan 98402bf4e6 Adds multiple image save to tarfile. (#560)
## Type of Change
- [ ] Bug fix
- [x] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Description

```bash
% container image save -o container.tar python:alpine alpine:latest
Warning! Running debug build. Performance may be degraded.
Image(s) saved        

% tar tf container.tar 
oci-layout
blobs/
blobs/sha256/
blobs/sha256/02f8efbefad605a169e89926147edd0676646263268f303c6fb3cdfdbc4a9612
blobs/sha256/a4bb08daca6b0385b17761b170fc91b20ab2ec072f70f9260149f8d61846ac13
blobs/sha256/588270f913bc82b4dbeee27bc249e4d314894becd18cccdc13645f669972c91e
blobs/sha256/692b7bac6678f5809640189eb1d95a3277689ec643201c465ecd44e72db7d029
blobs/sha256/1d24a57b1de9b287d9a9e1e231b71a235b836dc1852155b943b927a411d8c394
blobs/sha256/f9841e55dcbf5a6fcc702b25ce6e411ebdcb30680f94afd8060cb20bb20bd75c
blobs/sha256/0b83d017db6efafadf6b3f18d087d2ce1d67d8f0e927dc7254b0ad088074cd3a
blobs/sha256/b2236d9e1563c507613962c1ebbd7b3d307969ec2ee355b781b68440f4f0bee3
blobs/sha256/6e174226ea690ced550e5641249a412cdbefd2d09871f3e64ab52137a54ba606
blobs/sha256/c879780ac011609647c8714eef9e6490c42bf20128b32f4b31c4daad1242647b
blobs/sha256/26a1da51444d4cbbba3233caa342d0397ac4f93dc8e305e31989fd782b3107da
index.json

% tar -xOf container.tar index.json | python3 -m json.tool
{
    "schemaVersion": 2,
    "mediaType": "application/vnd.oci.image.index.v1+json",
    "manifests": [
        {
            "mediaType": "application/vnd.oci.image.index.v1+json",
            "annotations": {
                "org.opencontainers.image.ref.name": "docker.io/library/python:alpine",
                "io.containerd.image.name": "docker.io/library/python:alpine",
                "com.apple.containerization.image.name": "docker.io/library/python:alpine"
            },
            "size": 944,
            "digest": "sha256:1d24a57b1de9b287d9a9e1e231b71a235b836dc1852155b943b927a411d8c394"
        },
        {
            "mediaType": "application/vnd.oci.image.index.v1+json",
            "annotations": {
                "io.containerd.image.name": "docker.io/library/alpine:latest",
                "org.opencontainers.image.ref.name": "docker.io/library/alpine:latest",
                "com.apple.containerization.image.name": "docker.io/library/alpine:latest"
            },
            "size": 497,
            "digest": "sha256:692b7bac6678f5809640189eb1d95a3277689ec643201c465ecd44e72db7d029"
        }
    ]
}
```

## Motivation and Context
`image load` can read multiple images from a tar file, but `image save`
cannot save multiple images today.

## Testing
- [x] Tested locally
- [ ] Added/updated tests (TODO: roundtrip test pull-save-rm-load)
- [ ] Added/updated docs (TODO: check command reference)
2025-09-09 16:46:18 -07:00
mazdak be89df833b Make "Plugin not found" message more descriptive (#569)
Users frequently saw “failed to find plugin …” when the system services
weren’t running; the message didn’t explain the root cause or where
plugins are looked up. No change to plugin execution flow; only error
messaging and path discovery hints are improved for a better UX.
2025-09-08 16:13:23 -07:00
Danny Canter 8f6f39e89b Package.swift: Bump CZ to 0.7.0 (#584)
Closes #585

Has a fix for if a uid doesn't exist in /etc/passwd.
2025-09-08 11:35:30 -07:00
mazdak bd2c228b57 DefaultCommand signal behavior improvements for plugins (#570)
## Type of Change
- [x] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Description
Correct signal semantics for plugins: Container binary currently execs
into plugin binaries. If the parent CLI keeps SIGINT/SIGTERM handlers
installed, it can intercept/alter signal behavior intended for the
plugin (e.g., preventing graceful shutdown in foreground workflows).

## Motivation and Context
During the development of a plugin (docker compose compatibility
plugin), I encountered a major issues where CTRL-C (SIGTERM) was not
being sent to my plugin. CLI plugins, especially those that have long
running tasks need a way to handle signals from the OS. Current, we exec
into plugin binaries. If the parent CLI keeps SIGINT/SIGTERM handlers
installed, it can intercept/alter signal behavior intended for the
plugin (e.g., preventing graceful shutdown in foreground workflows).

### What we changed:
- Signals handed back to plugins: 
- DefaultCommand resets SIGINT/SIGTERM to defaults immediately before
exec’ing the plugin.
- Rationale: since exec replaces the process image, signals should be
delivered to (and handled by) the plugin without parent interference.
  - Non‑plugin commands remain unaffected by this change.
  - Compatibility: No change to plugin ABI or exec flow.

### Alternatives considered:
- Supervising child instead of exec: central forwarding of signals from
parent to plugin. Rejected for now to avoid changing process tree/stdio
semantics; resetting to defaults before exec preserves current model
while fixing signal interference.

## Testing
- [X] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs
2025-09-05 20:49:54 -07:00
Kathryn Baldauf 7bd9e5ac82 Remove description field in PR template (#583)
## Type of Change
- [x] Process update

## Description
Remove description field in PR template 

## Motivation and Context
I think having separate `Description` and `Motivation and Context`
sections have been redundant in recent usage of the PR template. This PR
removes the `Description` section. Ideally the PR title should cover the
same content previously in the `Description` section.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-09-05 13:54:35 -07:00
Kathryn Baldauf 17a1a3e2c7 Allow kernel set with tar to use relative paths to tar file (#582)
## Type of Change
- [x] Bug fix

## Description
Allow kernel set with tar to use relative paths to tar file. Fixes
https://github.com/apple/container/issues/573.

## Motivation and Context
`absoluteString` will prefix a scheme to the file path that looks like
"file://". This will cause file manager to fail to find the file at the
file path even if it exists. Change to instead just get the `path` of
the file, which does not add a scheme prefix.

## Testing
- [x] Tested locally

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-09-05 11:55:36 -07:00
Kathryn Baldauf d6b2243c75 Add force option to kernel set and add tests for kernel setting (#579)
## Type of Change
- [x] New feature  

## Description
Add option to force kernel setting and tests for CLI `kernel set`.
Related to https://github.com/apple/container/pull/575.

## Motivation and Context
This PR adds additional tests to ensure that we can set kernels from
local files, remote tar files, and local tar files. A new option `force`
is added to the `kernel set` subcommand which will overwrite an existing
kernel with the same name if one exists to make testing easier. The
tests ensure that a container can be started with the newly set kernel
and resets to the default recommended kernel when complete.

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

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-09-05 11:51:07 -07:00
Kathryn Baldauf cb2f424420 Support following symlinks in tar when setting default kernel (#575)
## Type of Change
- [x] Bug fix

## Description
This PR checks if the found entry in the archive for the requested
kernel path is a symlink, and if so, follows the symlink. I've opened a
separate issue to track creating tests for kernel downloading here
https://github.com/apple/container/issues/574 and will create a
follow-up PR for those.

## Motivation and Context
This PR fixes an issue reported in
https://github.com/apple/container/issues/475 where installing a kernel
from a tar archive does not follow symlinks in the archive.

## Testing
- [x] Tested locally

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-09-04 14:10:37 -07:00
Raj 20de8504de Fix relative path bind mounts regression (#572)
## Type of Change
- [x] Bug fix

## Description
Resolves #565. Relative paths in type=bind mounts now resolve to
absolute paths instead of being validated as volume names. Added some
tests generated using gen AI for this scenario.
2025-09-03 15:13:21 -07:00
Kathryn Baldauf 2525d557ef Uninstaller: call usage if incorrect number of options are provided (#556)
This PR improves the user experience when using the uninstall script to
include usage output when an incorrect number of options are provided to
the script.

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-08-29 14:19:44 -07:00
Sidhartha Mani e42fe80aa0 Create command-reference.md (#445)
Fixes https://github.com/apple/container/issues/375
2025-08-29 10:23:45 -07:00
J Logan 4ac18b54f3 Test fixes for 0.4.1 release. (#550)
- Disabled tests that failed with release config.
- Changed so merge builds build with release config so this doesn't burn
us next release.
- Added `swift --version` to Makefile so we can see what we're running
up in CI.
0.4.1
2025-08-27 18:04:00 -07:00
J Logan a8c779fd65 Uniform support for --platform, --os, --arch. (#545)
- Fixes #231.
- Extends #313 (@dcantah) so that all of `container create`, `container
run`, `container build`, `container image pull`, and `container image
save` accept the three options.
- `container build` now processes comma-separated lists for
`--platform`, `--arch`, and `--os`. It first checks `--platform`,
assembling the union of all platform values. If that set is non-empty,
the builder builds the values in the set. Otherwise, the set consists of
all combinations of the specified architecture and os values, finally
defaulting to `linux` and the host architecture if no options are
provided.
- All other commands work accept a single platform, preferring the
`--platform` option over `--arch` and `--os` when both are specified.
`--os` defaults to `linux`, and `--arch` defaults to the host
architecture.
- Clarify help messages and present the args in consistent order, with
platform first since it takes precedence if present.
- Deduplicate redundant platform options for `container build`.
0.4.0
2025-08-27 13:26:01 -07:00
Danny Canter df1cc1b184 Revert "Integration: Log container bootlog in run test failures (#541)" (#548)
This reverts commit 41add29673.

We've discovered a quite fun issue with some of our rpcs (stop+delete)
in sequence when done fast enough. It needs a bit of reworking to get
into shape. While the work here is very useful, we can add this back
after the rpc ordering is solved.
2025-08-27 12:32:26 -07:00
Danny Canter c2d6ffc89a CLI: Send logs to stderr (#544)
I'm not sure why we had these going to OSLog, but I'd wager they're a
bit more useful being displayed directly to the user during the command
they're running.
2025-08-26 17:33:47 -07:00
Danny Canter c65e892243 ContainerService: Remove lock from list() (#537) 2025-08-26 16:23:35 -07:00
Danny Canter 23c526233d ContainerService: Move force delete logic to daemon (#536)
Today force deleting (if a container is running then stop()'ing first)
is handled entirely in the cli, which is brittle. The CLI doesn't know
if the container was started with --rm so it would have to do a weird
timeout + list dance to check if the containers gone after stopping.
This change remedies this by just having the daemon take in a `force`
boolean to the delete rpc. If this is provided and the container is
running then we'll stop first, and then cleanup. We can additionally not
cleanup if --rm was provided as the daemon has the data to determine if
a container asked for autoRemove.
2025-08-26 14:23:39 -07:00
Danny Canter 41add29673 Integration: Log container bootlog in run test failures (#541)
If any of the container run tests fail on the basic setup phases (e.g.
actually starting the container) we should log the bootlog to see if we
can glean any info off of this.
2025-08-26 13:37:04 -07:00
Danny Canter b50dc253e9 Bump CZ to 0.6.2 (#543)
Hopefully fixes CI..
2025-08-26 10:39:07 -07:00
Danny Canter 7f7090ff87 Bump CZ to 0.6.1 (#540)
This has one change since 0.6.0 that just adds a log in the guest to see
the spec for any execed processes.
2025-08-25 13:38:21 -07:00
Dmitry Kovba 0fd7005119 Fix a warning when testing (#531)
Fixes a warning missed in https://github.com/apple/container/pull/516.
2025-08-21 10:08:27 -07:00
J Logan 879dff8fcf Allow traversing symlink when checking for builtin plugins. (#528)
- This helps with brew cask packaging, can postflight link
libexec/container/plugins to the appropriate cask location, and the
plugin discovery will traverse the link.
2025-08-20 23:52:24 -07:00
Dmitry Kovba 9a597eb6aa Add the support for ARG in the native builder parser (#516)
This PR adds the support for the ARG instruction in the native builder
parser, implements the support for different kinds of ARGs, and performs
the substitution of ARG variables in the supported instructions.
Resolves https://github.com/apple/container/issues/437.

Some features are currently blocked and not included into this PR:
- [Native builder: add the current target platform we're building use it
to set automatic platform ARGs
#522](https://github.com/apple/container/issues/522)
- [Native builder: add the support for the BuildKit built-in ARGs
#523](https://github.com/apple/container/issues/523)
- [Native builder: ensure pre-defined ARGs are excluded from the output
of the history #524](https://github.com/apple/container/issues/524)
- [Native builder: add the support for stage references and ARG
inheritance #525](https://github.com/apple/container/issues/525)
2025-08-20 14:57:24 -07:00
J Logan 6767144d43 Bump containerization dependency to 0.6.0 (#526) 2025-08-19 18:58:09 -07:00
J Logan 07679d99c7 Extract version output logic so --version is consistent. (#517) 2025-08-18 10:27:27 -07:00
Jacob Ford fe72d7ba41 Docs: clarify Xcode 26 beta must be the active developer directory (#238)
And add instructions for setting it so

Related: https://github.com/apple/containerization/issues/66
2025-08-18 12:11:54 -04:00
Renee Chang 3349a90ba7 Fix SSH forwarding for exec process (#506)
This PR fixes SSH forwarding for exec processes.

Currently, only init processes received the `SSH_AUTH_SOCK` environment
variable when using `--ssh` flag. Exec processes didn't have access to
the SSH agent socket, even though the socket was mounted.

Now we set environment variable for exec processes to match init process
behavior, ensuring SSH forwarding works consistently across processes,
and refactoring SSH forwarding condition into `hostSocketUrl()` helper
function.
2025-08-15 17:54:09 -07:00
J Logan e616143b95 Adds container builder rm alias. (#505) 2025-08-15 16:55:21 -07:00
J Logan 049adc96ea Adds how-to section for --ssh. (#503) 2025-08-15 15:37:58 -07:00
Renee Chang 94778981c8 Add SSH auth socket forwarding (#502)
Add `--ssh` flag to forward the host's SSH agent socket into the
container, so we can use SSH authentication for things like cloning
private repos, and also updates the socket path every time the container
starts to handle socket path changes like reboot/re-login.

Closes #498
2025-08-15 11:54:56 -07:00
J Logan a8dbf294f6 Ensure two containers cannot use the same DNS hostname. (#490)
- Closes #150, #394.
- Introduces `AttachmentConfiguration` type so that we can add key-value
options to `--network` in the future.
- Eliminates redundant `ContainersService.Item` type.
- Since we now ensure at ContainersService that hostnames will not
conflict, the network helper IP allocator now simply provides the
existing IP if for an allocation on an existing hostname, which should
handle (in an eventually consistent way) the case where a container
fails to deallocate an IP on shutdown.
2025-08-13 18:18:19 -07:00
Dmitry Kovba d2eb350393 Preserve permissions by default and fix warnings (#496)
Permissions should be preserved when copying by default. This PR also
fixes other warnings while building and testing.
2025-08-13 16:50:19 -07:00
J Logan b9a6bf52cc Fixes builder compiler errors and warnings. (#495) 2025-08-13 13:25:41 -07:00
Renee Chang 8db69e83b1 Make Parser functions public for CLI plugins (#494)
This PR makes `Parser` functions public to allow CLI plugins to access
for consistent argument parsing.
2025-08-13 13:20:34 -07:00