@@ -192,13 +192,37 @@ public struct ContainerManager: Sendable {
192
192
}
193
193
}
194
194
195
- /// Create a new manager with the provided kernel and initfs mount.
195
+ /// Create a new manager with the provided kernel, initfs mount, image store
196
+ /// and optional network implementation.
196
197
public init (
197
198
kernel: Kernel ,
198
199
initfs: Mount ,
200
+ imageStore: ImageStore ,
199
201
network: Network ? = nil
200
202
) throws {
201
- self . imageStore = ImageStore . default
203
+ self . imageStore = imageStore
204
+ self . network = network
205
+ try Self . createRootDirectory ( path: self . imageStore. path)
206
+ self . vmm = VZVirtualMachineManager (
207
+ kernel: kernel,
208
+ initialFilesystem: initfs,
209
+ bootlog: self . imageStore. path. appendingPathComponent ( " bootlog.log " ) . absolutePath ( )
210
+ )
211
+ }
212
+
213
+ /// Create a new manager with the provided kernel, initfs mount, root state
214
+ /// directory and optional network implementation.
215
+ public init (
216
+ kernel: Kernel ,
217
+ initfs: Mount ,
218
+ root: URL ? = nil ,
219
+ network: Network ? = nil
220
+ ) throws {
221
+ if let root {
222
+ self . imageStore = try ImageStore ( path: root)
223
+ } else {
224
+ self . imageStore = ImageStore . default
225
+ }
202
226
self . network = network
203
227
try Self . createRootDirectory ( path: self . imageStore. path)
204
228
self . vmm = VZVirtualMachineManager (
@@ -208,13 +232,55 @@ public struct ContainerManager: Sendable {
208
232
)
209
233
}
210
234
235
+ /// Create a new manager with the provided kernel, initfs reference, image store
236
+ /// and optional network implementation.
237
+ public init (
238
+ kernel: Kernel ,
239
+ initfsReference: String ,
240
+ imageStore: ImageStore ,
241
+ network: Network ? = nil
242
+ ) async throws {
243
+ self . imageStore = imageStore
244
+ self . network = network
245
+ try Self . createRootDirectory ( path: self . imageStore. path)
246
+
247
+ let initPath = self . imageStore. path. appendingPathComponent ( " initfs.ext4 " )
248
+ let initImage = try await self . imageStore. getInitImage ( reference: initfsReference)
249
+ let initfs = try await {
250
+ do {
251
+ return try await initImage. initBlock ( at: initPath, for: . linuxArm)
252
+ } catch let err as ContainerizationError {
253
+ guard err. code == . exists else {
254
+ throw err
255
+ }
256
+ return . block(
257
+ format: " ext4 " ,
258
+ source: initPath. absolutePath ( ) ,
259
+ destination: " / " ,
260
+ options: [ " ro " ]
261
+ )
262
+ }
263
+ } ( )
264
+
265
+ self . vmm = VZVirtualMachineManager (
266
+ kernel: kernel,
267
+ initialFilesystem: initfs,
268
+ bootlog: self . imageStore. path. appendingPathComponent ( " bootlog.log " ) . absolutePath ( )
269
+ )
270
+ }
271
+
211
272
/// Create a new manager with the provided kernel and image reference for the initfs.
212
273
public init (
213
274
kernel: Kernel ,
214
275
initfsReference: String ,
276
+ root: URL ? = nil ,
215
277
network: Network ? = nil
216
278
) async throws {
217
- self . imageStore = ImageStore . default
279
+ if let root {
280
+ self . imageStore = try ImageStore ( path: root)
281
+ } else {
282
+ self . imageStore = ImageStore . default
283
+ }
218
284
self . network = network
219
285
try Self . createRootDirectory ( path: self . imageStore. path)
220
286
0 commit comments