Skip to content

Commit 0547db2

Browse files
committed
Bump Containerization to 0.5.0
I'm happy with the config improvements, but because IO can only be setup at constructor time this makes it so that we need to supply IO at creation time of the VM or exec, which isn't the end of the world. So now boostrap() and createProcess() take in the filehandles.
1 parent 837ef61 commit 0547db2

File tree

11 files changed

+183
-133
lines changed

11 files changed

+183
-133
lines changed

Package.resolved

Lines changed: 3 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
@@ -22,7 +22,7 @@ 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 scVersion = "0.4.1"
25+
let scVersion = "0.5.0"
2626
let builderShimVersion = "0.6.0"
2727

2828
let package = Package(

Sources/CLI/Application.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct Application: AsyncParsableCommand {
182182
return -1
183183
}
184184

185-
try await process.start(io.stdio)
185+
try await process.start()
186186
defer {
187187
try? io.close()
188188
}

Sources/CLI/Builder/BuilderStart.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,12 @@ extension ClientContainer {
245245
detach: true
246246
)
247247
defer { try? io.close() }
248-
let process = try await bootstrap()
249-
_ = try await process.start(io.stdio)
248+
249+
let process = try await bootstrap(stdio: io.stdio)
250+
_ = try await process.start()
250251
await taskManager?.finish()
251252
try io.closeAfterStart()
253+
252254
log.debug("starting BuildKit and BuildKit-shim")
253255
} catch {
254256
try? await stop()

Sources/CLI/Container/ContainerExec.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ extension Application {
8181

8282
let process = try await container.createProcess(
8383
id: UUID().uuidString.lowercased(),
84-
configuration: config)
84+
configuration: config,
85+
stdio: io.stdio
86+
)
8587

8688
exitCode = try await Application.handleProcess(io: io, process: process)
8789
} catch {

Sources/CLI/Container/ContainerStart.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ extension Application {
5151
progress.start()
5252

5353
let container = try await ClientContainer.get(id: containerID)
54-
let process = try await container.bootstrap()
55-
56-
progress.set(description: "Starting init process")
57-
let detach = !self.attach && !self.interactive
5854
do {
55+
let detach = !self.attach && !self.interactive
5956
let io = try ProcessIO.create(
6057
tty: container.configuration.initProcess.terminal,
6158
interactive: self.interactive,
6259
detach: detach
6360
)
61+
62+
let process = try await container.bootstrap(stdio: io.stdio)
6463
progress.finish()
64+
6565
if detach {
66-
try await process.start(io.stdio)
66+
try await process.start()
6767
defer {
6868
try? io.close()
6969
}

Sources/CLI/RunCommand.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ extension Application {
110110

111111
let detach = self.managementFlags.detach
112112

113-
let process = try await container.bootstrap()
114-
progress.finish()
115-
116113
do {
117114
let io = try ProcessIO.create(
118115
tty: self.processFlags.tty,
119116
interactive: self.processFlags.interactive,
120117
detach: detach
121118
)
122119

120+
let process = try await container.bootstrap(stdio: io.stdio)
121+
progress.finish()
122+
123123
if !self.managementFlags.cidfile.isEmpty {
124124
let path = self.managementFlags.cidfile
125125
let data = id.data(using: .utf8)
@@ -137,7 +137,7 @@ extension Application {
137137
}
138138

139139
if detach {
140-
try await process.start(io.stdio)
140+
try await process.start()
141141
defer {
142142
try? io.close()
143143
}

Sources/ContainerClient/Core/ClientContainer.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ extension ClientContainer {
144144
}
145145

146146
extension ClientContainer {
147-
public func bootstrap() async throws -> ClientProcess {
147+
public func bootstrap(stdio: [FileHandle?]) async throws -> ClientProcess {
148148
let client = self.sandboxClient
149-
try await client.bootstrap()
149+
try await client.bootstrap(stdio: stdio)
150150
return ClientProcessImpl(containerId: self.id, client: self.sandboxClient)
151151
}
152152

@@ -183,10 +183,14 @@ extension ClientContainer {
183183

184184
extension ClientContainer {
185185
/// Execute a new process inside a running container.
186-
public func createProcess(id: String, configuration: ProcessConfiguration) async throws -> ClientProcess {
186+
public func createProcess(
187+
id: String,
188+
configuration: ProcessConfiguration,
189+
stdio: [FileHandle?]
190+
) async throws -> ClientProcess {
187191
do {
188192
let client = self.sandboxClient
189-
try await client.createProcess(id, config: configuration)
193+
try await client.createProcess(id, config: configuration, stdio: stdio)
190194
return ClientProcessImpl(containerId: self.id, processId: id, client: client)
191195
} catch {
192196
throw ContainerizationError(

Sources/ContainerClient/Core/ClientProcess.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public protocol ClientProcess: Sendable {
3232
var id: String { get }
3333

3434
/// Start the underlying process inside of the container.
35-
func start(_ stdio: [FileHandle?]) async throws
35+
func start() async throws
3636
/// Send a terminal resize request to the process `id`.
3737
func resize(_ size: Terminal.Size) async throws
3838
/// Send or "kill" a signal to the process `id`.
@@ -66,10 +66,10 @@ struct ClientProcessImpl: ClientProcess, Sendable {
6666
}
6767

6868
/// Start the container and return the initial process.
69-
public func start(_ stdio: [FileHandle?]) async throws {
69+
public func start() async throws {
7070
do {
7171
let client = self.client
72-
try await client.startProcess(self.id, stdio: stdio)
72+
try await client.startProcess(self.id)
7373
} catch {
7474
throw ContainerizationError(
7575
.internalError,

Sources/ContainerClient/SandboxClient.swift

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,27 @@ public struct SandboxClient: Sendable, Codable {
4444

4545
// Runtime Methods
4646
extension SandboxClient {
47-
public func bootstrap() async throws {
47+
public func bootstrap(stdio: [FileHandle?]) async throws {
4848
let request = XPCMessage(route: SandboxRoutes.bootstrap.rawValue)
4949
let client = createClient()
5050
defer { client.close() }
5151

52+
for (i, h) in stdio.enumerated() {
53+
let key: XPCKeys = {
54+
switch i {
55+
case 0: .stdin
56+
case 1: .stdout
57+
case 2: .stderr
58+
default:
59+
fatalError("invalid fd \(i)")
60+
}
61+
}()
62+
63+
if let h {
64+
request.set(key: key, value: h)
65+
}
66+
}
67+
5268
try await client.send(request)
5369
}
5470

@@ -61,19 +77,12 @@ extension SandboxClient {
6177
return try response.sandboxSnapshot()
6278
}
6379

64-
public func createProcess(_ id: String, config: ProcessConfiguration) async throws {
80+
public func createProcess(_ id: String, config: ProcessConfiguration, stdio: [FileHandle?]) async throws {
6581
let request = XPCMessage(route: SandboxRoutes.createProcess.rawValue)
6682
request.set(key: .id, value: id)
6783
let data = try JSONEncoder().encode(config)
6884
request.set(key: .processConfig, value: data)
6985

70-
let client = createClient()
71-
defer { client.close() }
72-
try await client.send(request)
73-
}
74-
75-
public func startProcess(_ id: String, stdio: [FileHandle?]) async throws {
76-
let request = XPCMessage(route: SandboxRoutes.start.rawValue)
7786
for (i, h) in stdio.enumerated() {
7887
let key: XPCKeys = {
7988
switch i {
@@ -89,6 +98,14 @@ extension SandboxClient {
8998
request.set(key: key, value: h)
9099
}
91100
}
101+
102+
let client = createClient()
103+
defer { client.close() }
104+
try await client.send(request)
105+
}
106+
107+
public func startProcess(_ id: String) async throws {
108+
let request = XPCMessage(route: SandboxRoutes.start.rawValue)
92109
request.set(key: .id, value: id)
93110

94111
let client = createClient()

0 commit comments

Comments
 (0)