Skip to content

Commit 8b79ec5

Browse files
committed
Squashed commit of the following:
commit a65c6f4 Merge: 9d32bc5 ce1b629 Author: Morris Richman <81453549+Mcrich23@users.noreply.github.com> Date: Tue Feb 3 20:08:38 2026 -0800 Merge branch 'apple:main' into main commit ce1b629 Author: Manoj Mahapatra <mahaplipsa@gmail.com> Date: Tue Feb 3 13:43:07 2026 -0800 [Docs] Fix typo in BUILDING.md: launchd -> launchctl (apple#1146) ## Type of Change - [ ] Bug fix - [ ] New feature - [ ] Breaking change - [x] Documentation update ## Motivation and Context The debug instructions in `BUILDING.md` incorrectly reference launchd list instead of `launchctl` list. `launchd` is the daemon itself and cannot be invoked directly. ## Testing - [ ] Tested locally - [ ] Added/updated tests - [x] Added/updated docs commit 3e49dce Author: Danny Canter <danny_canter@apple.com> Date: Tue Feb 3 00:45:01 2026 -0800 Add in missing rlimits (apple#1140) Containerization didn't have these defined until a recent tag. commit c4c2e85 Author: J Logan <john_logan@apple.com> Date: Tue Feb 3 00:27:09 2026 -0800 Upgrade kernel to Kata 3.26.0. (apple#1134) - Upgrade to containerization 0.24.5 to pick up zstd decompression enhancement. - Closes apple#767. - Closes apple#988. - Closes apple#1132. - Requires apple/containerization#508. commit 5c86337 Author: William Laverty <developer@william-laverty.com> Date: Mon Feb 2 13:57:59 2026 -0800 Add explanatory message before admin password prompt in uninstall script (apple#1118) - Added message: "This script requires an administrator password to remove the application files from system directories." - Fixes apple#1111 commit 7da25e1 Author: Danny Canter <danny_canter@apple.com> Date: Mon Feb 2 13:35:02 2026 -0800 Deps: Bump Containerization to 0.24.0 (apple#1127) Brings in some rlimit bumps/adjustments commit 7dfe27d Author: Danny Canter <danny_canter@apple.com> Date: Mon Feb 2 13:30:19 2026 -0800 CLI: Add support for rlimits (apple#1129) Closes apple#1097. commit b3b5c3e Author: J Logan <john_logan@apple.com> Date: Mon Feb 2 12:24:27 2026 -0800 Use labels instead of id to discriminate the builtin network. (apple#1123) - Closes apple#1122. - Adds placeholder ManagedResource and unit tests. Nothing is using these yet. - Adds system-defined resource labels for owning plugin and resource role. The system discriminates the builtin network using role "builtin". - Adds builtin role when creating builtin network at startup, and ensures that a preexisting network with ID "default" gets updated with the role label. - Replace all network ID checks for "default" with the builtin role check. - Adds "builder" role to builder VM. ## Type of Change - [ ] Bug fix - [x] New feature - [ ] Breaking change - [ ] Documentation update ## Motivation and Context Role and owner labels should make cross-cutting resource policy easier to implement. ## Testing - [x] Tested locally - [x] Added/updated tests - [ ] Added/updated docs commit 1dae1cd Author: w-ferg <43309695+w-ferg@users.noreply.github.com> Date: Sun Feb 1 18:14:41 2026 -0500 Fix pfctl executable path in PacketFilter DNS reload (apple#1128) ## Summary The `reload()` method in `PacketFilter.swift` references `/sbin/reloadProcess` (the local variable name) instead of `/sbin/pfctl`. This causes all DNS create and delete operations to fail: ``` Error: internalError: "pfctl reload exec failed: "Error Domain=NSCocoaErrorDomain Code=4 "The file "reloadProcess" doesn't exist."" ``` ## Fix One-line change: `/sbin/reloadProcess` → `/sbin/pfctl` ## Testing Verified on macOS 26 (Tahoe) with Apple Silicon: - `sudo container system dns create test.sdc.internal --localhost 203.0.113.1` succeeds without error - Container can resolve and reach host services through the DNS redirect commit 113a6ec Author: Ronit Sabhaya <ronitsabhaya75@gmail.com> Date: Fri Jan 30 21:54:57 2026 -0600 Fix file descriptor leak in DirectoryWatcher (apple#1104) - `DirectoryWatcher` opens file descriptors for monitoring directories but never closes them, causing a file descriptor leak. - Adds `setCancelHandler` to properly close file descriptors when the `DispatchSource` is cancelled. Signed-off-by: Ronit Sabhaya <ronitsabhaya75@gmail.com> commit 72f04b6 Author: Saehej Kang <saehej.kang@gmail.com> Date: Fri Jan 30 19:10:03 2026 -0800 [docs]: update steps on building with containerization project (apple#1116) - Closes apple#1095 - Just added a few more details about how to build with the local `containerization` dependency. commit 3a0ad58 Author: Raj <rajaryan_singh@apple.com> Date: Fri Jan 30 16:17:43 2026 -0800 Add resource.role label to builder container (apple#1120) Add resource.role label to builder container commit 1c01d0c Author: J Logan <john_logan@apple.com> Date: Fri Jan 30 11:07:49 2026 -0800 Update to kata 3.20.0 kernel. (apple#1114) - Closes apple#1113. - This is the newest we can do until we address apple#767. - Slight change to PacketFilter error handling so unit tests work more reliably. - Try making CLINetworkTests serialized to see if parallel execution is causing flakes. commit 3f2060e Author: Danny Canter <danny_canter@apple.com> Date: Thu Jan 29 18:25:48 2026 -0800 DirectoryWatcher: Small adjustments (apple#1112) - Have the handler throw - Log the failure at error level commit 0a7fb07 Author: Danny Canter <danny_canter@apple.com> Date: Thu Jan 29 14:21:12 2026 -0800 Set mtu to old Containerization default (apple#1110) The old mtu default in containerization was 1280 to account for some alpine/musl images that have issues with 1500. This changed in the last couple tags to be modifiable, but the new default is the standard 1500. Ideally we eventually allow supplying the mtu to be used when you create a network (or possibly a container creation setting), but for now just default in here back to what CZ used to use. commit 0bceb23 Author: Aditya Ramani <a_ramani@apple.com> Date: Thu Jan 29 12:08:42 2026 +0900 Bump to use containerization 0.23.2 (apple#1106) Updating the package dependency on apple/containerization to pick up bug fixes Signed-off-by: Aditya Ramani <a_ramani@apple.com> Co-authored-by: J Logan <john_logan@apple.com> commit d762fe5 Author: jwhur <57657645+JaewonHur@users.noreply.github.com> Date: Wed Jan 28 18:22:33 2026 -0800 Launch a service with waitForDebugger if specified (apple#1101) This PR enables launching a service with `waitForDebugger` flag if the service label matches a given env variable `CONTAINER_DEBUG`. commit 4f93e3e Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed Jan 28 18:21:08 2026 -0800 ci: bump actions/checkout from 6.0.1 to 6.0.2 in the github-actions group (apple#1100) - Updates `actions/checkout` from 6.0.1 to 6.0.2 Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> commit 371db6d Author: jwhur <57657645+JaewonHur@users.noreply.github.com> Date: Wed Jan 28 17:17:08 2026 -0800 Fix testExecOnExitingContainer (apple#1107) Check the container remains only, not its status as the status might not have been updated at the time checking. commit d872270 Author: J Logan <john_logan@apple.com> Date: Wed Jan 28 09:04:58 2026 -0800 Removes ArgumentParser import from NetworkMode. (apple#1102) - ContainerResources shouldn't need to know anything about CLI stuff. - Move ExpressibleByArgument protocol conformance to an extension in the package where it's needed. commit 3abf81f Author: Saehej Kang <saehej.kang@gmail.com> Date: Tue Jan 27 20:00:43 2026 -0800 [image-list]: Add full size field to json output (apple#1098) - Refer to apple#862 - Updated `SIZE` field to `FULL SIZE`, as it seemed more appropriate so it does not get mixed up with the `descriptor size` field - Closes apple#860 commit 24cbed5 Author: ChengHao Yang <17496418+tico88612@users.noreply.github.com> Date: Wed Jan 28 06:55:49 2026 +0800 Implement container prune (apple#904) - Fixed apple#892. - By contrast with `rm`, `prune` should display the amount of reclaimed storage, so added code to retrieve it. Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com> commit a57527e Author: jwhur <57657645+JaewonHur@users.noreply.github.com> Date: Tue Jan 27 11:15:22 2026 -0800 Refactor container lifecycle functions to perform scoped rollback on failure (apple#1080) - Closes apple#977. - Closes apple#1058. - Prevents unexpected removal of containers on bootstrapping and starting failures, by reorganizing error handling for container `run`, `start`, and `exec` so that error handling only unwinds that which was done in the current scope. - Relies on apple/containerization#495. commit 6244129 Author: c <claudeaceae@icloud.com> Date: Mon Jan 26 23:30:45 2026 -0500 Fix grammar in BUILDING.md (apple#984) - Fixes a grammar error in the local Containerization development instructions. commit 9d4cded Author: jwhur <57657645+JaewonHur@users.noreply.github.com> Date: Mon Jan 26 19:35:41 2026 -0800 Isolated network (apple#1079) - Closes apple#1037. - Adds a `--mode` flag that has `nat` and `hostOnly` options. The host-only option selects the vmnet host-only mode, where containers attached to the network can reach each other and the host, but not external systems. commit 033c999 Author: J Logan <john_logan@apple.com> Date: Mon Jan 26 14:07:00 2026 -0800 Make TerminalProgress a library. (apple#1093) - Closes apple#1092. - Allows 3rd party CLI plugins to use the progress indicator. commit b371aee Author: ChengHao Yang <17496418+tico88612@users.noreply.github.com> Date: Tue Jan 27 05:07:05 2026 +0800 Feat: container image delete force option (apple#1096) - Fixed apple#1087 Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com> commit ed1185d Author: jwhur <57657645+JaewonHur@users.noreply.github.com> Date: Fri Jan 23 17:59:28 2026 -0800 Container-to-host networking. (apple#1078) - Closes apple#346. - This PR enables connecting host's localhost ports from containers. - It adds an option `--localhost <localhost>` to DNS create command, after which the packets heading ip address in container are redirected to localhost in host machine. Packet filter rule is added and deleted along with the creation and deletion of localhost domain. commit 14c279f Author: Patrick Linnane <patrick@linnane.io> Date: Fri Jan 23 17:56:35 2026 -0800 Add option to stop services in all launchd domains (apple#1077) - Services started from Terminal run in the `gui/$uid` launchd domain. When `ensure-container-stopped.sh` runs from a different context, `launchctl managername` may return a different domain, causing the script to check the wrong domain and miss running services. I noticed this after upgrading `container` via Homebrew. - Introduces a getopt option `-a` that allows booting out all domains explicitly. Also adds `-h` for a usage message. Signed-off-by: Patrick Linnane <patrick@linnane.io> commit 751c1fc Author: Stanislav Antonichev <cympak2@users.noreply.github.com> Date: Fri Jan 23 23:01:26 2026 +0200 Add --dns support to build command for custom DNS resolution (apple#1067) This change adds --dns parameter support to the build command, matching the existing functionality in the run command. This allows users to specify custom DNS nameservers (like Google DNS 8.8.8.8) when building container images, which is essential when the host machine uses a local DNS resolver (e.g., 127.0.0.2) that doesn't work inside containers. Changes: - Added --dns option to BuildCommand to accept DNS nameserver IP addresses - Modified build logic to detect DNS configuration changes and recreate the builder container when DNS settings differ - Passed DNS configuration to BuilderStart.start() method - Updated builder container creation to use specified DNS nameservers or fall back to network gateway ## Type of Change - [ ] Bug fix - [X] New feature - [ ] Breaking change - [ ] Documentation update ## Motivation and Context This change adds --dns parameter support to the build command, matching the existing functionality in the run command. This allows users to specify custom DNS nameservers (like Google DNS 8.8.8.8) when building container images, which is essential when the host machine uses a local DNS resolver (e.g., 127.0.0.2) that doesn't work inside containers. ## Testing - [X] Tested locally - [ ] Added/updated tests - [ ] Added/updated docs --------- Co-authored-by: J Logan <sgtbakerrahulnet@yahoo.com> commit 55f2112 Author: J Logan <john_logan@apple.com> Date: Fri Jan 23 11:35:10 2026 -0800 Place image store data correctly for app-root path. (apple#1085) - Closes apple#1084. commit 5746ec3 Author: ChengHao Yang <17496418+tico88612@users.noreply.github.com> Date: Sat Jan 24 03:32:59 2026 +0800 Fix: prevent delete default network (apple#1083) - Fixed apple#1073 - Move the conditional check to the front; there's no need to check for a default network after filtering. Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com> commit 9d32bc5 Merge: a2b4486 69445b9 Author: Morris Richman <81453549+Mcrich23@users.noreply.github.com> Date: Mon Jan 19 19:20:12 2026 -0800 Merge branch 'apple:main' into main commit a2b4486 Merge: 27a94a0 bfc5ca9 Author: Morris Richman <81453549+Mcrich23@users.noreply.github.com> Date: Fri Oct 3 23:03:02 2025 -0700 Merge branch 'apple:main' into main commit 27a94a0 Author: Morris Richman <81453549+Mcrich23@users.noreply.github.com> Date: Thu Sep 18 17:07:12 2025 -0700 chore(fmt): auto-format before push commit 4a4d0a9 Author: Morris Richman <81453549+Mcrich23@users.noreply.github.com> Date: Thu Sep 18 17:07:06 2025 -0700 Update PropertySet.swift commit 665d813 Author: Morris Richman <81453549+Mcrich23@users.noreply.github.com> Date: Thu Sep 18 17:02:09 2025 -0700 Update PropertySet.swift commit 01a474e Author: Morris Richman <81453549+Mcrich23@users.noreply.github.com> Date: Thu Sep 18 16:57:41 2025 -0700 chore(fmt): auto-format before push commit e7c68b5 Author: Morris Richman <81453549+Mcrich23@users.noreply.github.com> Date: Thu Sep 18 16:57:01 2025 -0700 Update SystemProperty.swift
1 parent c7adfe7 commit 8b79ec5

File tree

62 files changed

+1997
-227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1997
-227
lines changed

.github/workflows/common.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
packages: read
2323
steps:
2424
- name: Checkout repository
25-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
25+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2626
with:
2727
fetch-depth: 0
2828

.github/workflows/pr-label-apply.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
steps:
2222
- name: Checkout repository
23-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
23+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2424

2525
- name: Download PR metadata artifact
2626
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7

BUILDING.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,27 @@ to prepare your build environment.
5858
bin/container system stop
5959
```
6060

61-
4. Use the Swift package manager to configure use your local `containerization` package and update your `Package.resolved` file.
61+
4. Reconfigure the Swift project to use your local `containerization` package and update your `Package.resolved` file.
6262

6363
```bash
6464
/usr/bin/swift package edit --path ../containerization containerization
6565
/usr/bin/swift package update containerization
6666
```
6767

6868
> [!IMPORTANT]
69-
> If you are using Xcode, you will need to temporarily modify `Package.swift` instead of using `swift package edit`, using a path dependency in place of the versioned `container` dependency:
69+
> If you are using Xcode, do **not** run `swift package edit`. Instead, temporarily modify `Package.swift` to replace the versioned `containerization` dependency:
7070
>
71-
> ```swift
72-
> .package(path: "../containerization"),
73-
> ```
71+
> ```swift
72+
> .package(url: "https://github.com/apple/containerization.git", exact: Version(stringLiteral: scVersion)),
73+
> ```
74+
>
75+
> with the local path dependency:
76+
>
77+
> ```swift
78+
> .package(path: "../containerization"),
79+
> ```
80+
>
81+
> **Note:** If you have already run `swift package edit`, whether intentionally or by accident, follow the steps in the next section to restore the normal `containerization` dependency. Otherwise, the modified `Package.swift` file will not work, and the project may fail to build.
7482

7583
5. If you want `container` to use any changes you made in the `vminit` subproject of Containerization, update the system property to use the locally built init filesystem image:
7684

@@ -119,6 +127,42 @@ To revert to using the Containerization dependency from your `Package.swift`:
119127
bin/container system start
120128
```
121129

130+
## Debug XPC Helpers
131+
132+
Attach debugger to the XPC helpers using their launchd service labels:
133+
134+
1. Find launchd service labels:
135+
136+
```console
137+
% container system start
138+
% container run -d --name test debian:bookworm sleep infinity
139+
test
140+
% launchctl list | grep container
141+
27068 0 com.apple.container.container-network-vmnet.default
142+
27072 0 com.apple.container.container-core-images
143+
26980 0 com.apple.container.apiserver
144+
27331 0 com.apple.container.container-runtime-linux.test
145+
```
146+
147+
2. Stop container and start again after setting the environment variable `CONTAINER_DEBUG_LAUNCHD_LABEL` to the label of service to attach debugger. Services whose label starts with the `CONTAINER_DEBUG_LAUNCHD_LABEL` will wait the debugger:
148+
149+
```console
150+
% export CONTAINER_DEBUG_LAUNCHD_LABEL=com.apple.container.container-runtime-linux.test
151+
% container system start # Only the service `com.apple.container.container-runtime-linux.test` waits debugger
152+
```
153+
154+
```console
155+
% export CONTAINER_DEBUG_LAUNCHD_LABEL=com.apple.container.container-runtime-linux
156+
% container system start # Every service starting with `com.apple.container.container-runtime-linux` waits debugger
157+
```
158+
159+
3. Run the command to launch the service, and attach debugger:
160+
161+
```console
162+
% container run -it --name test debian:bookworm
163+
⠧ [6/6] Starting container [0s] # It hangs as the service is waiting for debugger
164+
```
165+
122166
## Pre-commit hook
123167

124168
Run `make pre-commit` to install a pre-commit hook that ensures that your changes have correct formatting and license headers when you run `git commit`.

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ integration: init-block
187187
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIRunCommand1 || exit_code=1 ; \
188188
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIRunCommand2 || exit_code=1 ; \
189189
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIRunCommand3 || exit_code=1 ; \
190+
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIPruneCommand || exit_code=1 ; \
190191
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIStatsCommand || exit_code=1 ; \
191192
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIImagesCommand || exit_code=1 ; \
192193
$(SWIFT) test -c $(BUILD_CONFIGURATION) $(SWIFT_CONFIGURATION) --filter TestCLIRunBase || exit_code=1 ; \

Package.resolved

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import PackageDescription
2424
let releaseVersion = ProcessInfo.processInfo.environment["RELEASE_VERSION"] ?? "0.0.0"
2525
let gitCommit = ProcessInfo.processInfo.environment["GIT_COMMIT"] ?? "unspecified"
2626
let builderShimVersion = "0.7.0"
27-
let scVersion = "0.21.1"
27+
let scVersion = "0.24.5"
2828

2929
let package = Package(
3030
name: "container",
@@ -44,6 +44,7 @@ let package = Package(
4444
.library(name: "ContainerVersion", targets: ["ContainerVersion"]),
4545
.library(name: "ContainerXPC", targets: ["ContainerXPC"]),
4646
.library(name: "SocketForwarder", targets: ["SocketForwarder"]),
47+
.library(name: "TerminalProgress", targets: ["TerminalProgress"]),
4748
],
4849
dependencies: [
4950
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),

Sources/ContainerBuild/Builder.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import NIOHPACK
2525
import NIOHTTP2
2626

2727
public struct Builder: Sendable {
28+
public static let builderContainerId = "buildkit"
29+
2830
let client: BuilderClientProtocol
2931
let clientAsync: BuilderClientAsyncProtocol
3032
let group: EventLoopGroup

Sources/ContainerCommands/Application.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public struct Application: AsyncLoggableCommand {
6262
ContainerStart.self,
6363
ContainerStats.self,
6464
ContainerStop.self,
65+
ContainerPrune.self,
6566
]
6667
),
6768
CommandGroup(

Sources/ContainerCommands/BuildCommand.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ extension Application {
125125
@OptionGroup
126126
public var logOptions: Flags.Logging
127127

128+
@OptionGroup
129+
public var dns: Flags.DNS
130+
128131
@Argument(help: "Build directory")
129132
var contextDir: String = "."
130133

@@ -143,12 +146,13 @@ extension Application {
143146

144147
progress.set(description: "Dialing builder")
145148

146-
let builder: Builder? = try await withThrowingTaskGroup(of: Builder.self) { [vsockPort, cpus, memory] group in
149+
let dnsNameservers = self.dns.nameservers
150+
let builder: Builder? = try await withThrowingTaskGroup(of: Builder.self) { [vsockPort, cpus, memory, dnsNameservers] group in
147151
defer {
148152
group.cancelAll()
149153
}
150154

151-
group.addTask { [vsockPort, cpus, memory, log] in
155+
group.addTask { [vsockPort, cpus, memory, log, dnsNameservers] in
152156
while true {
153157
do {
154158
let container = try await ClientContainer.get(id: "buildkit")
@@ -170,6 +174,7 @@ extension Application {
170174
cpus: cpus,
171175
memory: memory,
172176
log: log,
177+
dnsNameservers: dnsNameservers,
173178
progressUpdate: progress.handler
174179
)
175180

Sources/ContainerCommands/Builder/BuilderStart.swift

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ extension Application {
4545
)
4646
var memory: String = "2048MB"
4747

48+
@OptionGroup
49+
public var dns: Flags.DNS
50+
4851
@OptionGroup
4952
public var logOptions: Flags.Logging
5053

@@ -61,11 +64,29 @@ extension Application {
6164
progress.finish()
6265
}
6366
progress.start()
64-
try await Self.start(cpus: self.cpus, memory: self.memory, log: log, progressUpdate: progress.handler)
67+
try await Self.start(
68+
cpus: self.cpus,
69+
memory: self.memory,
70+
log: log,
71+
dnsNameservers: self.dns.nameservers,
72+
dnsDomain: self.dns.domain,
73+
dnsSearchDomains: self.dns.searchDomains,
74+
dnsOptions: self.dns.options,
75+
progressUpdate: progress.handler
76+
)
6577
progress.finish()
6678
}
6779

68-
static func start(cpus: Int64?, memory: String?, log: Logger, progressUpdate: @escaping ProgressUpdateHandler) async throws {
80+
static func start(
81+
cpus: Int64?,
82+
memory: String?,
83+
log: Logger,
84+
dnsNameservers: [String] = [],
85+
dnsDomain: String? = nil,
86+
dnsSearchDomains: [String] = [],
87+
dnsOptions: [String] = [],
88+
progressUpdate: @escaping ProgressUpdateHandler
89+
) async throws {
6990
await progressUpdate([
7091
.setDescription("Fetching BuildKit image"),
7192
.setItemsName("blobs"),
@@ -103,6 +124,7 @@ extension Application {
103124
let existingImage = existingContainer.configuration.image.reference
104125
let existingResources = existingContainer.configuration.resources
105126
let existingEnv = existingContainer.configuration.initProcess.environment
127+
let existingDNS = existingContainer.configuration.dns
106128

107129
let existingManagedEnv = existingEnv.filter { envVar in
108130
envVar.hasPrefix("BUILDKIT_COLORS=") || envVar.hasPrefix("NO_COLOR=")
@@ -129,11 +151,26 @@ extension Application {
129151
}
130152
return false
131153
}()
154+
let dnsChanged = {
155+
if !dnsNameservers.isEmpty {
156+
return existingDNS?.nameservers != dnsNameservers
157+
}
158+
if dnsDomain != nil {
159+
return existingDNS?.domain != dnsDomain
160+
}
161+
if !dnsSearchDomains.isEmpty {
162+
return existingDNS?.searchDomains != dnsSearchDomains
163+
}
164+
if !dnsOptions.isEmpty {
165+
return existingDNS?.options != dnsOptions
166+
}
167+
return false
168+
}()
132169

133170
switch existingContainer.status {
134171
case .running:
135-
guard imageChanged || cpuChanged || memChanged || envChanged else {
136-
// If image, mem and cpu are the same, continue using the existing builder
172+
guard imageChanged || cpuChanged || memChanged || envChanged || dnsChanged else {
173+
// If image, mem, cpu, env, and DNS are the same, continue using the existing builder
137174
return
138175
}
139176
// If they changed, stop and delete the existing builder
@@ -142,7 +179,7 @@ extension Application {
142179
case .stopped:
143180
// If the builder is stopped and matches our requirements, start it
144181
// Otherwise, delete it and create a new one
145-
guard imageChanged || cpuChanged || memChanged || envChanged else {
182+
guard imageChanged || cpuChanged || memChanged || envChanged || dnsChanged else {
146183
try await existingContainer.startBuildKit(progressUpdate, nil)
147184
return
148185
}
@@ -164,8 +201,7 @@ extension Application {
164201
useRosetta ? nil : "--enable-qemu",
165202
].compactMap { $0 }
166203

167-
let id = "buildkit"
168-
try ContainerAPIClient.Utility.validEntityName(id)
204+
try ContainerAPIClient.Utility.validEntityName(Builder.builderContainerId)
169205

170206
let image = try await ClientImage.fetch(
171207
reference: builderImage,
@@ -207,8 +243,9 @@ extension Application {
207243
memory: memory
208244
)
209245

210-
var config = ContainerConfiguration(id: id, image: imageDesc, process: processConfig)
246+
var config = ContainerConfiguration(id: Builder.builderContainerId, image: imageDesc, process: processConfig)
211247
config.resources = resources
248+
config.labels = [ResourceLabelKeys.role: ResourceRoleValues.builder]
212249
config.mounts = [
213250
.init(
214251
type: .tmpfs,
@@ -226,15 +263,24 @@ extension Application {
226263
// Enable Rosetta only if the user didn't ask to disable it
227264
config.rosetta = useRosetta
228265

229-
let network = try await ClientNetwork.get(id: ClientNetwork.defaultNetworkName)
230-
guard case .running(_, let networkStatus) = network else {
266+
guard let defaultNetwork = try await ClientNetwork.builtin else {
267+
throw ContainerizationError(.invalidState, message: "default network is not present")
268+
}
269+
guard case .running(_, let networkStatus) = defaultNetwork else {
231270
throw ContainerizationError(.invalidState, message: "default network is not running")
232271
}
233-
config.networks = [AttachmentConfiguration(network: network.id, options: AttachmentOptions(hostname: id))]
272+
config.networks = [
273+
AttachmentConfiguration(network: defaultNetwork.id, options: AttachmentOptions(hostname: Builder.builderContainerId))
274+
]
234275
let subnet = networkStatus.ipv4Subnet
235276
let nameserver = IPv4Address(subnet.lower.value + 1).description
236-
let nameservers = [nameserver]
237-
config.dns = ContainerConfiguration.DNSConfiguration(nameservers: nameservers)
277+
let nameservers = dnsNameservers.isEmpty ? [nameserver] : dnsNameservers
278+
config.dns = ContainerConfiguration.DNSConfiguration(
279+
nameservers: nameservers,
280+
domain: dnsDomain,
281+
searchDomains: dnsSearchDomains,
282+
options: dnsOptions
283+
)
238284

239285
let kernel = try await {
240286
await progressUpdate([

0 commit comments

Comments
 (0)