Commit Graph
139 Commits
Author SHA1 Message Date
Danny Canter f254f48bfc LinuxContainer: Add ability to close stdin (#201)
This allows the user the ability to raise an EOF for the containers
stdin. Today there's no way to close stdin so something as simple as
"cat" and relying on EOF to move the process forward doesn't work
2025-07-08 18:38:04 -07:00
Raj ad219fecf1 Make MTU configurable for Netlink (#204)
Here we add the implementation to make MTU value configurable instead of
hardcoding in `linkSet`.
2025-07-08 15:54:57 -07:00
Michael Crosby d16893d7b9 guard arch around Rosetta API (#203)
While this only supports AS, xcode's default will build all arches, so
this presents a bit nicer default for Archiving an xcode application
that utilizes containerization.

Fixes #179

Signed-off-by: crosbymichael <michael_crosby@apple.com>
2025-07-08 11:55:27 -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
Joseph Heck 28b97f2917 update SPI manifest to build on 6.2 only (#196)
adds configuration to SwiftPackageIndex manifest to request builds
happen explicitly on Swift 6.2 vs whatever the current default it
2025-07-04 11:12:19 -07:00
Dmitry Kovba 969703d9ad Replace NSLock with Mutex (#193)
This PR replaces `NSLock` with `Mutex`. Thanks @dcantah for the idea!
2025-07-03 16:11:38 -07:00
Danny Canter 9775528495 Vminitd: Rework ManagedProcess.IO protocols (#194)
I think the way these types were structured made reasoning about them a
bit difficult. I don't think this fully solves the problem, but this
change aims to make things a bit simpler by hoisting a lot of the logic
for the IO relays to a new IOPair type thats goal is to simply take in a
reader and writer and handle their resource cleanup after a relay
finishes. Bundled in with this is also the buffer we'll use to copy
between them.

This change:

- Alters ManagedProcess.IO `start` to take in the process to alter
instead of this just being a side effect of the constructors.
- Gets rid of `close()` in favor of `CloseStdin`. The IO will get closed
when the relays finish, which will naturally happen if the process exits
or just closes its side of the pipes/pty. This makes it so that the one
special case (a client wants to signal no more input is coming) is still
sane.
- Move all relay logic and resource cleanup to a new IOPair type that
takes in protocols that are easily conformable by all of our various io
types ( Socket, Terminal, FileHandle).
2025-07-03 14:11:29 -07:00
Danny Canter d3ca580a6d ContainerizationOS: Alter Terminal.close() (#195)
Change to calling close on the underlying FileHandle as it already has
logic to set the fd to an invalid value and prevent double closes.
2025-07-03 10:44:01 -04:00
Dmitry Kovba 8573b80fac Use a State struct for mutable properties in Sendable types (#191)
This PR introduces a pattern of grouping mutable properties within the
`Sendable` types, encapsulated within a `State` struct. This approach
enables simultaneous updates to multiple properties and serves as a tool
against reentrancy issues.
2025-07-03 01:19:55 -07:00
Danny Canter 633205f171 Vminitd: Change some process log levels (#192)
The two starting and exiting logs I feel are important enough to get
promoted to info level.
2025-07-02 13:01:28 -04:00
Aditya Ramani b24b72a7e4 Reference image via sha for test (#190)
CI was failing since the test image we use had a tag re-pushed. Pinning
the test to reference the image version by its sha

---------

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-07-01 17:58:40 -07:00
Danny Canter 61b01cc1ee LCShim: Add CZ prefixes/pidfd wrappers (#189)
We should namespace these a bit, and we need pidfd for some upcoming
terminal work. This also just gets rid of syscall2 and replaces with a
pivot_root wrapper.
2025-07-01 02:16:17 -07:00
Aditya Ramani bdba5b5740 Create unpacker protocol + ext4 unpacker (#151)
Creates a new Unpacker protocol that defines a single method

```
func unpack(_ image: Image, for platform: Platform, at path: URL, progress: ProgressHandler?) async throws -> Mount
```

This change also removes the `unpack(...)` method from the Image type.

Before
```
let mount = try await image.unpack(for: platform, at: path)
```
After
```
let unpacker = EXT4Unpacker(blockSizeInBytes: 2.gib())
let mount = try await unpacker.unpack(image, for: platform, at: path)
```

---------

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-30 11:06:38 -07:00
Danny Canter 631676b855 Remove preconcurrency from Virtualization import (#184)
I don't believe we need this for anything here (maybe we once did).
2025-06-30 12:39:12 -04:00
Dmitry Kovba 382c73ae78 Use a consistent capitalization in a bug report template (#181) 2025-06-27 15:51:47 -07:00
J Logan 1a59de82b0 Makes interface gateway configuration optional. (#156)
Here we implement the mechanism for ensuring that `container` doesn't
set up two default routes on containers that connect to multiple
networks. We'll implement the policy in apple/container#243.
2025-06-27 15:16:15 -04:00
Luis David Garcia 885db858a5 Updated documentation link in README (#161)
## Description of Change

- I updated the documentation link in the README: [Documentation
Tab](https://github.com/apple/containerization?tab=readme-ov-file#documentation)
- The original link (`open http://localhost:8000/documentation/`) was
returning a **404 error**, as shown in the screenshot below.
- I fixed the issue by updating the link to: `open
http://127.0.0.1:8000/containerization/documentation/`, which works
correctly.

## Screenshot of the 404 Error and the Fix

Here’s the screenshot showing the error and the fix:

![404 Error Shown and 200
Fix](https://github.com/user-attachments/assets/4198d381-80de-4bca-a9f4-5455eee887f6)
2025-06-27 15:14:33 -04:00
Kathryn Baldauf 73097b795c Remove use of triage label (#180)
Tags on the repo should be a way to classify an item instead of denoting
workflow or status of the item. Remove the addition of the triage label
on bug and feature issues.

Related to https://github.com/apple/container/pull/262

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-27 14:08:01 -04:00
Danny Canter c7763c76cf vmexec: Set perms on stdio (#174)
We don't chown the container's stdio today.
2025-06-27 11:03:21 -04: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
Aditya Ramani 638bb96e3f Better error message for image pull failures (#175)
Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-26 15:47:35 -07:00
Danny Canter e274a79123 Pin Swift 6.2 version and Linux SDK (#178)
Until 6.2 officially releases lets pin to a static version of the 6.2
snapshots. The Linux SDK and swift version must be aligned so this
should be less fickle than using `6.2-snapshot` as this is a friendly
identifier to choose the latest uploaded snapshot.
2025-06-26 14:20:26 -07:00
Elijah Wright 538ea78c33 run cleanupRelay only once in TerminalIO and StandardIO (#153) 2025-06-26 12:03:17 -04:00
Kathryn Baldauf 958a83b23b Switch to using issue types for bugs and features (#170)
Matches https://github.com/apple/container/pull/258

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-06-25 17:09:53 -07: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
Danny Canter 5559dd5a3d VZVirtualMachineInstance: Rework installRosetta flow (#169)
Because we were installing rosetta directly in the constructor for
VZVirtualMachineInstance, and we'd prefer to not have the constructor
async as it pollutes so much more, we had devised this gnarly callback
approach for the install that is a bit of an eyesore. This changes focus
is on moving the install flow to a method that is already async so we
can piggyback off of it, and removing the install logic from the config
-> VZConfig conversion. Now the install will occur during start() if
rosetta is not installed.
2025-06-25 14:11:23 -04:00
Danny Canter 2dfabeb4f9 Vminitd: Rework ManagedContainer (#168)
This gets rid of some design decisions that I was not fond of. This
changes the process start for both execs and the init process to happen
internally in the object, as well as makes it so that all exec
functionalities can happen on the container object itself. This allows
us to get rid of the `if request.id == containerID` branches in the
rpcs, and handle this entirely in the object itself using its internal
state.

The existing integration tests should stress this just fine I believe.
2025-06-25 14:07:31 -04:00
Dmitry Kovba 4bacf4c578 Remove the support for CURRENT_SDK (#164)
This PR removes the no longer needed support for `CURRENT_SDK`.
2025-06-25 12:30:06 -04:00
Dmitry Kovba b626d32a48 Fix compilation warnings (#163)
This PR fixes compilation warnings observed in:
```
swift -v --version
Apple Swift version 6.2-dev (LLVM 5fbc818cf26c90b, Swift 2e1897356956e43)
Target: arm64-apple-macosx26.0
/Users/Dmitry/Library/Developer/Toolchains/swift-6.2-DEVELOPMENT-SNAPSHOT-2025-06-17-a.xctoolchain/usr/bin/swift-frontend --version
Apple Swift version 6.2-dev (LLVM 5fbc818cf26c90b, Swift 2e1897356956e43)
Target: arm64-apple-macosx26.0
Build config: +assertions
```
2025-06-24 13:15:44 -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
Dmitry Kovba f2a2bd7fa5 Add a link to the container repository (#157)
This PR adds a link to the container repository on top of the
`README.md`:

<img width="877" alt="Screenshot 2025-06-20 at 7 54 46 PM"
src="https://github.com/user-attachments/assets/3aff3c13-b0ed-4bf6-b2c8-bb4e8ad64355"
/>
2025-06-24 12:48:28 -07:00
Dmitry Kovba 910992e4d8 Update Static Linux SDK to the latest version (#162)
Currently, when a user runs `make cross-prep`, we install the latest
version of Swift. This requires installing the latest version of Static
Linux SDK, which we should update as a new version is released.
2025-06-24 12:44:42 -07:00
Dmitry Kovba 5da0125228 Redirect to the documentation from the homepage (#159)
This PR fixes the homepage at https://apple.github.io/containerization/
2025-06-23 10:19:16 -07:00
Satyam Singh 22f2efd8d1 fix: correct release condition in GitHub Actions and globalize enviro… (#127)
# Refactor GitHub Actions Workflow: Containerization Build
## 🛠 Summary
This PR introduces several important improvements and cleanups to the
build-containerization-template GitHub Actions workflow for better
maintainability, correctness, and readability.

### 🔧 Changes Made
#### 1.  Fix invalid conditional syntax
- **!= is not supported in expressions** with **if**: in GitHub Actions.

- Only logical operators like !, &&, || are valid.

#### 2.  Globalized environment variables
- Moved CURRENT_SDK and DEVELOPER_DIR to the job-level env: block to:

- Avoid redundancy across steps

- Make the workflow more maintainable

### 3.  Replaced `secrets.GITHUB_TOKEN` with `github.token`
- Prefer github.token for GitHub-provided auth token to improve clarity
and scoping.

@katiewasnothere
2025-06-23 09:26:50 -07:00
Dmitry Kovba a339606068 Fix the Swiftly bin path (#158)
This PR resolves the following error for new users:

```
% make cross-prep
Installing Swiftly...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 8549k  100 8549k    0     0  14.7M      0 --:--:-- --:--:-- --:--:-- 14.8M
installer: Package name is 
installer: Installing at base path /Users/Dmitry
installer: The install was successful.
Welcome to swiftly, the Swift toolchain manager for Linux and macOS!

Please read the following information carefully before proceeding with the installation. If you
wish to customize the steps performed during the installation process, refer to 'swiftly init -h'
for configuration options.

Swiftly installs files into the following locations:

/Users/Dmitry/.swiftly - Directory for configuration files
/Users/Dmitry/.swiftly/bin - Links to the binaries of the active toolchain
/Users/Dmitry/Library/Developer/Toolchains - Directory hosting installed toolchains

These locations can be changed by setting the environment variables
SWIFTLY_HOME_DIR, SWIFTLY_BIN_DIR, and SWIFTLY_TOOLCHAINS_DIR before running 'swiftly init' again.

For your convenience, swiftly will also attempt to modify your shell's profile file to make
installed items available in your environment upon login. This can be suppressed with the
'--no-modify-profile' option.

Proceed? (Y/n): 

Installing swiftly in /Users/Dmitry/.swiftly/bin/swiftly...
Error: The file “swiftly” couldn’t be opened because there is no such file.
make[1]: *** [swiftly] Error 1
make: *** [cross-prep] Error 2
```
2025-06-20 20:02:23 -07:00
Aditya Ramani 016c80fac0 Better parsing for www-authenticate headers (#155)
There was a bug where the `www-authenticate` header in the HTTP response
from a registry would not be parsed accurately.

Specifically, if the header value had more than one `<space>` character,
the entire header would be ignored. This PR fixes this bug and adds unit
test to detect this in the future.


Fixes https://github.com/apple/container/issues/240
And most likely fixes https://github.com/apple/container/issues/237

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-20 15:51:47 -07:00
Cornelius Roemer cad00de874 Fix typo in README (#54) 2025-06-18 17:31:58 -07:00
Danny Canter 2a96a0d447 Containerization: Always set TERM (#146)
Make sure we always set TERM for containers that ask for a tty. Right
now this handling was spread around in a bunch of spots, but I'd wager
setting it for the client on the host via LinuxContainer/Process is more
sane and already what we do for a lot of the other fields.
2025-06-18 17:00:00 -07:00
Danny Canter 1992cfe779 Containerization: Reduce allocations for image subsystems (#152)
Continue the allocations journey for anything that is in the codepaths
for pulling images. This time there's a couple spots in archive and ext4
we can get rid of some copies.
2025-06-18 16:11:46 -07:00
Nandha Reddy 35a821f041 fix: vminitd incorrectly overwrites custom HOME environment variable (#136)
## Summary

The vminitd service was using `process.env.contains("HOME")` which
checks for exact string match rather than environment variables starting
with "HOME=".

Since environment variables are stored as `"KEY=value"` strings, the
condition was always false, causing vminitd to always override custom
HOME values even when explicitly provided by the client.

## Changes

- Updates the logic in `vminitd/Sources/vminitd/Server+GRPC.swift` to
use `contains(where: { $0.hasPrefix("HOME=") })` to properly detect
existing HOME environment variables
- Adds regression test `testProcessCustomHomeEnvvar()` to verify that
custom HOME environment variables are preserved when provided by the
client

## Testing

The fix has been tested with the new integration test that:
  - Sets a custom HOME environment variable (`HOME=/tmp/custom/home`)
- Runs a shell command that outputs the HOME variable on the container
runtime
- Verifies the custom HOME value is preserved and not overwritten with
the default

## Environment

  - macOS: 26.0 (25A5279m)
  - Hardware: M4 Pro
  - Xcode: 26 beta
  - Swift: 6.2-dev

Fixes #135
2025-06-17 21:51:11 -07:00
Joseph Heck 445450dcce limits buildAndTest to Apple repository (#150)
Constrains the buildAndTest job to only run on the
`apple/containerization` repository due to Runner constraints.

Simplest solution - fixes #132
2025-06-17 14:20:20 -07:00
Alexey Makhov 689af841d6 Sort keys in image index to keep the digest consistent (#149)
The digest is calculated based on written json data, but JSONEncoder
doesn't preserve order bby default, so the digest is not consistent.

Signed-off-by: Alexey <makhov.alex@gmail.com>
2025-06-17 12:23:25 -07:00
Alexey Makhov 4a196b6dc2 Adds some context to fetchToken errors (#129)
Fixes https://github.com/apple/container/issues/182 and
https://github.com/apple/container/issues/183

Signed-off-by: Alexey <makhov.alex@gmail.com>
2025-06-17 08:26:46 -07:00
Riya Amemiya 4a482a00c0 Fix typos in README and LinuxContainer.swift comments (#144)
## Changes 

### README.md

- Fixed grammatical error: "when a process is ran" → "when a process is
run"
- Fixed plural form: "for instruction on" → "for instructions on"

### kernel/README.md

- Fixed numbering sequence: "4. Run `make`" → "3. Run `make`" in build
instructions

### Sources/Containerization/LinuxContainer.swift

- Fixed grammatical error in comment: "The container has ran" → "The
container has run"
2025-06-17 02:40:05 -07:00
Danny Canter 328221e44c ContainerizationOCI: Cut down on allocations (#141)
We were doing intermediate step copies to Data objects both for push and
pull. We only need the data for the lifetime of the singular writes to
update the state of the checksums and to write to disk somewhere, so we
can use a view into the buffer from the http client to satisfy this.
2025-06-16 22:18:36 -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
Dmitry Kovba b14395515c Fix warnings in make docs (#139)
This PR also has additional small improvements.
2025-06-16 17:22:22 -07:00
Josh Soref c00ede68c1 fix comment misspellings (#131)
This PR corrects misspellings identified by the [check-spelling
action](https://github.com/marketplace/actions/check-spelling)

The misspellings have been reported at
https://github.com/jsoref/containerization/actions/runs/15662940240/attempts/1#summary-44123291170
The action reports that the changes in this PR would make it happy:
https://github.com/jsoref/containerization/actions/runs/15662940315/attempts/1#summary-44123291367

---------

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2025-06-16 16:06:37 -04:00
Aditya Ramani f4177e7d67 More informative errors from RegistryClient (#134)
Also creates an `ErrorResponse` type to model the errors typically
returned by a container registry.

Reference: https://distribution.github.io/distribution/spec/api/#errors

Example error message:
```
Error: HTTP request to https://ghcr.io/token?client_id=containerization-registry-client&service=ghcr.io&scope=repository:user/image:pull failed with response: 403 Forbidden. Reason: {"errors":[{"message":"requested access to the resource is denied","code":"DENIED"}]}
```

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
2025-06-16 11:07:32 -07:00
Danny Canter 77c54434b8 LinuxProcess: Always return CZError (#111)
We should return our own error type always for our methods. This wraps
all of the public methods on the process to return a more full featured
error than the rpcerrors we get today.
2025-06-16 13:40:36 -04:00