Skip to content

Commit 55fc6a1

Browse files
authored
Merge branch 'main' into fix-image-size
2 parents 39fcdc1 + 3e49dce commit 55fc6a1

22 files changed

Lines changed: 654 additions & 52 deletions

File tree

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: 1 addition & 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.23.2"
26+
let scVersion = "0.24.5"
2727

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

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/Builder/BuilderStart.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ extension Application {
201201
useRosetta ? nil : "--enable-qemu",
202202
].compactMap { $0 }
203203

204-
let id = "buildkit"
205-
try ContainerAPIClient.Utility.validEntityName(id)
204+
try ContainerAPIClient.Utility.validEntityName(Builder.builderContainerId)
206205

207206
let image = try await ClientImage.fetch(
208207
reference: builderImage,
@@ -244,9 +243,9 @@ extension Application {
244243
memory: memory
245244
)
246245

247-
var config = ContainerConfiguration(id: id, image: imageDesc, process: processConfig)
246+
var config = ContainerConfiguration(id: Builder.builderContainerId, image: imageDesc, process: processConfig)
248247
config.resources = resources
249-
config.labels = ["com.apple.container.resource.role": "builder"]
248+
config.labels = [ResourceLabelKeys.role: ResourceRoleValues.builder]
250249
config.mounts = [
251250
.init(
252251
type: .tmpfs,
@@ -264,11 +263,15 @@ extension Application {
264263
// Enable Rosetta only if the user didn't ask to disable it
265264
config.rosetta = useRosetta
266265

267-
let network = try await ClientNetwork.get(id: ClientNetwork.defaultNetworkName)
268-
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 {
269270
throw ContainerizationError(.invalidState, message: "default network is not running")
270271
}
271-
config.networks = [AttachmentConfiguration(network: network.id, options: AttachmentOptions(hostname: id))]
272+
config.networks = [
273+
AttachmentConfiguration(network: defaultNetwork.id, options: AttachmentOptions(hostname: Builder.builderContainerId))
274+
]
272275
let subnet = networkStatus.ipv4Subnet
273276
let nameserver = IPv4Address(subnet.lower.value + 1).description
274277
let nameservers = dnsNameservers.isEmpty ? [nameserver] : dnsNameservers

Sources/ContainerCommands/Network/NetworkDelete.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,22 @@ extension Application {
5454
let uniqueNetworkNames = Set<String>(networkNames)
5555
let networks: [NetworkState]
5656

57-
if uniqueNetworkNames.contains(ClientNetwork.defaultNetworkName) {
58-
throw ContainerizationError(
59-
.invalidArgument,
60-
message: "cannot delete the default network"
61-
)
62-
}
63-
6457
if all {
6558
networks = try await ClientNetwork.list()
66-
.filter { $0.id != ClientNetwork.defaultNetworkName }
59+
.filter { !$0.isBuiltin }
6760
} else {
6861
networks = try await ClientNetwork.list()
6962
.filter { c in
70-
uniqueNetworkNames.contains(c.id)
63+
guard uniqueNetworkNames.contains(c.id) else {
64+
return false
65+
}
66+
guard !c.isBuiltin else {
67+
throw ContainerizationError(
68+
.invalidArgument,
69+
message: "cannot delete a builtin network: \(c.id)"
70+
)
71+
}
72+
return true
7173
}
7274

7375
// If one of the networks requested isn't present lets throw. We don't need to do

Sources/ContainerCommands/Network/NetworkPrune.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension Application.NetworkCommand {
4141
}
4242

4343
let networksToPrune = allNetworks.filter { network in
44-
network.id != ClientNetwork.defaultNetworkName && !networksInUse.contains(network.id)
44+
!network.isBuiltin && !networksInUse.contains(network.id)
4545
}
4646

4747
var prunedNetworks = [String]()

Sources/ContainerPersistence/DefaultsStore.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import ContainerizationError
2020
import Foundation
2121

2222
public enum DefaultsStore {
23-
private static let userDefaultDomain = "com.apple.container.defaults"
23+
public static let userDefaultDomain = "com.apple.container.defaults"
2424

2525
public enum Keys: String {
2626
case buildRosetta = "build.rosetta"
@@ -181,9 +181,9 @@ extension DefaultsStore.Keys {
181181
}
182182
return "ghcr.io/apple/containerization/vminit:\(tag)"
183183
case .defaultKernelBinaryPath:
184-
return "opt/kata/share/kata-containers/vmlinux-6.12.42-162"
184+
return "opt/kata/share/kata-containers/vmlinux-6.18.5-177"
185185
case .defaultKernelURL:
186-
return "https://github.com/kata-containers/kata-containers/releases/download/3.20.0/kata-static-3.20.0-arm64.tar.xz"
186+
return "https://github.com/kata-containers/kata-containers/releases/download/3.26.0/kata-static-3.26.0-arm64.tar.zst"
187187
case .defaultSubnet:
188188
return "192.168.64.1/24"
189189
case .defaultIPv6Subnet:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 Foundation
18+
19+
/// Common properties for all managed resources.
20+
public protocol ManagedResource: Identifiable, Sendable, Codable {
21+
/// A 64 byte hexadecimal string, assigned by the system, that uniquely
22+
/// identifies the resource.
23+
var id: String { get }
24+
25+
/// A user assigned name that shall be unique within the namespace of
26+
/// the resource category. If the user does not assign a name, this value
27+
/// shall be the same as the system-assigned identifier.
28+
var name: String { get }
29+
30+
/// The time at which the system created the resource.
31+
var creationDate: Date { get }
32+
33+
/// Key-value properties for the resource. The user and system may both
34+
/// make use of labels to read and write annotations or other metadata.
35+
/// A good practice is to use
36+
var labels: [String: String] { get }
37+
38+
/// Generates a unique resource ID value.
39+
static func generateId() -> String
40+
41+
/// Returns true only if the specified resource name is syntactically valid.
42+
static func nameValid(_ name: String) -> Bool
43+
}
44+
45+
extension ManagedResource {
46+
/// Generate a random identifier that has the format of an ASCII SHA-256 hash.
47+
public static func generateId() -> String {
48+
(0..<2)
49+
.map { _ in UInt128.random(in: 0...UInt128.max) }
50+
.map { String($0, radix: 16).padding(toLength: 32, withPad: "0", startingAt: 0) }
51+
.joined()
52+
}
53+
}
54+
55+
// FIXME: This moves to ManagedResource and/or a ResourceLabels typealias eventually.
56+
extension [String: String] {
57+
public var isBuiltin: Bool { self.contains { $0 == ResourceLabelKeys.role && $1 == ResourceRoleValues.builtin } }
58+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
/// System-defined keys for resource labels.
18+
public struct ResourceLabelKeys {
19+
/// Indicates a owner of a resource managed by a plugin.
20+
public static let plugin = "com.apple.container.plugin"
21+
22+
/// Indicates a resource with a reserved or dedicated purpose.
23+
public static let role = "com.apple.container.resource.role"
24+
}
25+
26+
/// System-defined values for resource the resource role label.
27+
public struct ResourceRoleValues {
28+
/// Indicates a container that can build images.
29+
public static let builder = "builder"
30+
31+
/// Indicates a system-created resource that cannot be deleted by the user.
32+
public static let builtin = "builtin"
33+
}

Sources/ContainerResource/Network/NetworkState.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ public enum NetworkState: Codable, Sendable {
5757

5858
public var id: String {
5959
switch self {
60-
case .created(let configuration): configuration.id
61-
case .running(let configuration, _): configuration.id
60+
case .created(let config), .running(let config, _): config.id
6261
}
6362
}
6463

6564
public var creationDate: Date {
6665
switch self {
67-
case .created(let configuration): configuration.creationDate
68-
case .running(let configuration, _): configuration.creationDate
66+
case .created(let config), .running(let config, _): config.creationDate
67+
}
68+
}
69+
70+
public var isBuiltin: Bool {
71+
switch self {
72+
case .created(let config), .running(let config, _): config.labels.isBuiltin
6973
}
7074
}
7175
}

0 commit comments

Comments
 (0)