Skip to content

Commit a65c6f4

Browse files
authored
Merge branch 'apple:main' into main
2 parents 9d32bc5 + ce1b629 commit a65c6f4

File tree

120 files changed

+2329
-383
lines changed

Some content is hidden

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

120 files changed

+2329
-383
lines changed

.github/workflows/common.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
name: Build and test the project
1717
if: github.repository == 'apple/container'
1818
timeout-minutes: 60
19-
runs-on: [self-hosted, macos, sequoia, ARM64]
19+
runs-on: [self-hosted, macos, tahoe, ARM64]
2020
permissions:
2121
contents: read
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

@@ -73,6 +73,10 @@ jobs:
7373
APP_ROOT=$(mktemp -d -p "${RUNNER_TEMP}")
7474
trap 'rm -rf "${APP_ROOT}"; echo Removing data directory ${APP_ROOT}' EXIT
7575
echo "Created data directory ${APP_ROOT}"
76+
export NO_PROXY="${NO_PROXY},192.168.0.0/16,fe80::/10"
77+
echo NO_PROXY=${NO_PROXY}
78+
export no_proxy="${no_proxy},192.168.0.0/16,fe80::/10"
79+
echo no_proxy=${no_proxy}
7680
make APP_ROOT="${APP_ROOT}" test install-kernel integration
7781
env:
7882
DEVELOPER_DIR: "/Applications/Xcode-latest.app/Contents/Developer"

.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: 12 additions & 3 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
@@ -23,7 +23,7 @@ import PackageDescription
2323
let releaseVersion = ProcessInfo.processInfo.environment["RELEASE_VERSION"] ?? "0.0.0"
2424
let gitCommit = ProcessInfo.processInfo.environment["GIT_COMMIT"] ?? "unspecified"
2525
let builderShimVersion = "0.7.0"
26-
let scVersion = "0.21.0"
26+
let scVersion = "0.24.5"
2727

2828
let package = Package(
2929
name: "container",
@@ -43,6 +43,7 @@ let package = Package(
4343
.library(name: "ContainerVersion", targets: ["ContainerVersion"]),
4444
.library(name: "ContainerXPC", targets: ["ContainerXPC"]),
4545
.library(name: "SocketForwarder", targets: ["SocketForwarder"]),
46+
.library(name: "TerminalProgress", targets: ["TerminalProgress"]),
4647
],
4748
dependencies: [
4849
.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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@ import Foundation
2525
import Logging
2626
import TerminalProgress
2727

28+
// This logger is only used until `asyncCommand.run()`.
2829
// `log` is updated only once in the `validate()` method.
29-
nonisolated(unsafe) var log = {
30-
LoggingSystem.bootstrap(StreamLogHandler.standardError)
30+
private nonisolated(unsafe) var bootstrapLogger = {
31+
LoggingSystem.bootstrap({ _ in StderrLogHandler() })
3132
var log = Logger(label: "com.apple.container")
3233
log.logLevel = .info
3334
return log
3435
}()
3536

36-
public struct Application: AsyncParsableCommand {
37+
public struct Application: AsyncLoggableCommand {
3738
@OptionGroup
38-
var global: Flags.Global
39+
public var logOptions: Flags.Logging
3940

4041
public init() {}
4142

@@ -61,6 +62,7 @@ public struct Application: AsyncParsableCommand {
6162
ContainerStart.self,
6263
ContainerStats.self,
6364
ContainerStop.self,
65+
ContainerPrune.self,
6466
]
6567
),
6668
CommandGroup(
@@ -171,16 +173,16 @@ public struct Application: AsyncParsableCommand {
171173
installRoot: systemHealth.installRoot,
172174
pluginDirectories: pluginDirectories,
173175
pluginFactories: pluginFactories,
174-
log: log
176+
log: bootstrapLogger
175177
)
176178
}
177179

178180
public func validate() throws {
179181
// Not really a "validation", but a cheat to run this before
180182
// any of the commands do their business.
181183
let debugEnvVar = ProcessInfo.processInfo.environment["CONTAINER_DEBUG"]
182-
if self.global.debug || debugEnvVar != nil {
183-
log.logLevel = .debug
184+
if self.logOptions.debug || debugEnvVar != nil {
185+
bootstrapLogger.logLevel = .debug
184186
}
185187
// Ensure we're not running under Rosetta.
186188
if try isTranslated() {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===----------------------------------------------------------------------===//
2+
// Copyright © 2026 Apple Inc. and the container project authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//===----------------------------------------------------------------------===//
16+
17+
import ArgumentParser
18+
import ContainerAPIClient
19+
import ContainerLog
20+
import Logging
21+
22+
public protocol AsyncLoggableCommand: AsyncParsableCommand {
23+
var logOptions: Flags.Logging { get }
24+
}
25+
26+
extension AsyncLoggableCommand {
27+
/// A shared logger instance configured based on the command's options
28+
public var log: Logger {
29+
var logger = Logger(label: "container", factory: { _ in StderrLogHandler() })
30+
31+
logger.logLevel = logOptions.debug ? .debug : .info
32+
33+
return logger
34+
}
35+
}

Sources/ContainerCommands/BuildCommand.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import NIO
2727
import TerminalProgress
2828

2929
extension Application {
30-
public struct BuildCommand: AsyncParsableCommand {
30+
public struct BuildCommand: AsyncLoggableCommand {
3131
public init() {}
3232
public static var configuration: CommandConfiguration {
3333
var config = CommandConfiguration()
@@ -122,6 +122,12 @@ extension Application {
122122
@Option(name: .long, help: ArgumentHelp("Builder shim vsock port", valueName: "port"))
123123
var vsockPort: UInt32 = 8088
124124

125+
@OptionGroup
126+
public var logOptions: Flags.Logging
127+
128+
@OptionGroup
129+
public var dns: Flags.DNS
130+
125131
@Argument(help: "Build directory")
126132
var contextDir: String = "."
127133

@@ -140,12 +146,13 @@ extension Application {
140146

141147
progress.set(description: "Dialing builder")
142148

143-
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
144151
defer {
145152
group.cancelAll()
146153
}
147154

148-
group.addTask { [vsockPort, cpus, memory] in
155+
group.addTask { [vsockPort, cpus, memory, log, dnsNameservers] in
149156
while true {
150157
do {
151158
let container = try await ClientContainer.get(id: "buildkit")
@@ -166,6 +173,8 @@ extension Application {
166173
try await BuilderStart.start(
167174
cpus: cpus,
168175
memory: memory,
176+
log: log,
177+
dnsNameservers: dnsNameservers,
169178
progressUpdate: progress.handler
170179
)
171180

0 commit comments

Comments
 (0)