Skip to content

Commit 94461b5

Browse files
authored
Merge branch 'main' into feature/runtime-flag
2 parents 1353dc6 + fdeb1b1 commit 94461b5

89 files changed

Lines changed: 1883 additions & 479 deletions

File tree

Some content is hidden

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

.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-build.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ on:
88
types: [opened, reopened, synchronize]
99

1010
jobs:
11+
verify-signatures:
12+
name: Verify commit signatures
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check all commits are signed
16+
env:
17+
GH_TOKEN: ${{ github.token }}
18+
run: |
19+
commits=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits --paginate)
20+
unsigned_commits=""
21+
22+
while IFS='|' read -r sha author verified; do
23+
if [ "$verified" != "true" ]; then
24+
unsigned_commits="$unsigned_commits - $sha by $author\n"
25+
fi
26+
done < <(echo "$commits" | jq -r '.[] | "\(.sha)|\(.commit.author.name)|\(.commit.verification.verified)"')
27+
28+
if [ -n "$unsigned_commits" ]; then
29+
echo "::error::The following commits are not signed:"
30+
echo -e "$unsigned_commits"
31+
echo ""
32+
echo "Please sign your commits. See:"
33+
echo " - https://github.com/apple/containerization/blob/main/CONTRIBUTING.md#pull-requests"
34+
echo " - https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits"
35+
exit 1
36+
fi
37+
38+
echo "All commits are signed!"
39+
1140
build:
1241
name: Invoke build
1342
uses: ./.github/workflows/common.yml

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

Lines changed: 2 additions & 10 deletions
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
@@ -29,20 +29,12 @@ jobs:
2929
run-id: ${{ github.event.workflow_run.id }}
3030
pattern: pr-metadata-*
3131
merge-multiple: false
32-
continue-on-error: true
3332
id: download-artifact
3433

3534
- name: Read PR number
3635
id: pr-number
3736
run: |
38-
METADATA_DIR=$(find . -type d -name "pr-metadata-*" 2>/dev/null | head -n 1)
39-
40-
if [ -z "$METADATA_DIR" ]; then
41-
echo "No metadata found"
42-
exit 1
43-
fi
44-
45-
PR_NUMBER=$(cat "${METADATA_DIR}/pr-number.txt")
37+
PR_NUMBER=$(cat "pr-number.txt")
4638
echo "number=${PR_NUMBER}" >> $GITHUB_OUTPUT
4739
echo "PR Number: ${PR_NUMBER}"
4840

BUILDING.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,19 @@ to prepare your build environment.
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import PackageDescription
2222

2323
let releaseVersion = ProcessInfo.processInfo.environment["RELEASE_VERSION"] ?? "0.0.0"
2424
let gitCommit = ProcessInfo.processInfo.environment["GIT_COMMIT"] ?? "unspecified"
25-
let builderShimVersion = "0.7.0"
26-
let scVersion = "0.21.1"
25+
let builderShimVersion = "0.8.0"
26+
let scVersion = "0.25.0"
2727

2828
let package = Package(
2929
name: "container",

Sources/ContainerBuild/BuildFSSync.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Collections
1818
import ContainerAPIClient
1919
import ContainerizationArchive
2020
import ContainerizationOCI
21+
import CryptoKit
2122
import Foundation
2223
import GRPC
2324

@@ -199,7 +200,7 @@ actor BuildFSSync: BuildPipelineHandler {
199200
format: .paxRestricted,
200201
filter: .none)
201202

202-
try Archiver.compress(
203+
let tarHash = try Archiver.compress(
203204
source: contextDir,
204205
destination: tarURL,
205206
writerConfiguration: writerCfg
@@ -229,6 +230,25 @@ actor BuildFSSync: BuildPipelineHandler {
229230
pathInArchive: URL(fileURLWithPath: rel))
230231
}
231232

233+
let hash = tarHash.compactMap { String(format: "%02x", $0) }.joined()
234+
let header = BuildTransfer(
235+
id: packet.id,
236+
source: tarURL.path,
237+
complete: false,
238+
isDir: false,
239+
metadata: [
240+
"os": "linux",
241+
"stage": "fssync",
242+
"mode": "tar",
243+
"hash": hash,
244+
]
245+
)
246+
var resp = ClientStream()
247+
resp.buildID = buildID
248+
resp.buildTransfer = header
249+
resp.packetType = .buildTransfer(header)
250+
sender.yield(resp)
251+
232252
for try await chunk in try tarURL.bufferedCopyReader() {
233253
let part = BuildTransfer(
234254
id: packet.id,

Sources/ContainerBuild/BuildImageResolver.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ struct BuildImageResolver: BuildPipelineHandler {
2626
let contentStore: ContentStore
2727
let quiet: Bool
2828
let output: FileHandle
29+
let pull: Bool
2930

30-
public init(_ contentStore: ContentStore, quiet: Bool = false, output: FileHandle = FileHandle.standardError) throws {
31+
public init(_ contentStore: ContentStore, quiet: Bool = false, output: FileHandle = FileHandle.standardError, pull: Bool = false) throws {
3132
self.contentStore = contentStore
3233
self.quiet = quiet
3334
self.output = output
35+
self.pull = pull
3436
}
3537

3638
func accept(_ packet: ServerStream) throws -> Bool {
@@ -72,6 +74,9 @@ struct BuildImageResolver: BuildPipelineHandler {
7274
defer { progress.finish() }
7375
progress.start()
7476

77+
if self.pull {
78+
return try await ClientImage.pull(reference: ref, platform: platform, progressUpdate: progress.handler)
79+
}
7580
// Use fetch() which checks cache first, then pulls if needed
7681
return try await ClientImage.fetch(reference: ref, platform: platform, progressUpdate: progress.handler)
7782
}()

Sources/ContainerBuild/BuildPipelineHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public actor BuildPipeline {
3030
[
3131
try BuildFSSync(URL(filePath: config.contextDir)),
3232
try BuildRemoteContentProxy(config.contentStore),
33-
try BuildImageResolver(config.contentStore, quiet: config.quiet, output: config.terminal?.handle ?? FileHandle.standardError),
33+
try BuildImageResolver(config.contentStore, quiet: config.quiet, output: config.terminal?.handle ?? FileHandle.standardError, pull: config.pull),
3434
try BuildStdio(quiet: config.quiet, output: config.terminal?.handle ?? FileHandle.standardError),
3535
]
3636
}

0 commit comments

Comments
 (0)