mirror of
https://github.com/apple/container.git
synced 2026-09-12 18:55:43 +00:00
Closes #227 Previously, the bootlog was supplied once in the constructor to VZVirtualMachineManager which meant that if you used this same manager for multiple ctrs that all logs would end up going to the same file, which becomes quite cumbersome to follow.. This change moves bootlog to be a container configuration param and also moves it to be a VMConfiguration param, so it can be threaded through from LinuxContainer -> vmm.create() and be truly container unique now. The largest driver for this was the integration tests which today every single test spits out logs to a singular file, making guest investigations tricky to actually look into. Result after: ``` ➜ containerization git:(bootlog-per-ctr) ✗ ls -alh bin/bootlogs total 1520 drwxr-xr-x@ 24 dcantah staff 768B Oct 22 17:34 . drwxr-xr-x@ 8 dcantah staff 256B Oct 22 17:34 .. -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-cat-mount.log -rw-------@ 1 dcantah staff 22K Oct 22 17:34 test-cgroup-limits.log -rw-------@ 1 dcantah staff 249K Oct 22 17:34 test-concurrent-processes-output-stress.log -rw-------@ 1 dcantah staff 167K Oct 22 17:34 test-concurrent-processes.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-container-devconsole.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-container-hostname.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-container-hosts-file.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-container-manager.log -rw-------@ 1 dcantah staff 22K Oct 22 17:34 test-container-reuse.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-container-statistics.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-container-stdin.log -rw-------@ 1 dcantah staff 0B Oct 22 17:34 test-nested-virt.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-pause-resume-io.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-pause-resume-wait.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-pause-resume.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-process-custom-home-envvar.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-process-echo-hi.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-process-false.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-process-home-envvar.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-process-true.log -rw-------@ 1 dcantah staff 11K Oct 22 17:34 test-process-tty-envvar.log -rw-------@ 1 dcantah staff 38K Oct 22 17:34 test-process-user.log ```
73 lines
2.7 KiB
Swift
73 lines
2.7 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
// Copyright © 2025 Apple Inc. and the Containerization project authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if os(macOS)
|
|
import ContainerizationError
|
|
import ContainerizationOCI
|
|
import Foundation
|
|
import Logging
|
|
|
|
/// A virtualization.framework backed `VirtualMachineManager` implementation.
|
|
public struct VZVirtualMachineManager: VirtualMachineManager {
|
|
private let kernel: Kernel
|
|
private let initialFilesystem: Mount
|
|
private let rosetta: Bool
|
|
private let nestedVirtualization: Bool
|
|
private let logger: Logger?
|
|
|
|
public init(
|
|
kernel: Kernel,
|
|
initialFilesystem: Mount,
|
|
rosetta: Bool = false,
|
|
nestedVirtualization: Bool = false,
|
|
logger: Logger? = nil
|
|
) {
|
|
self.kernel = kernel
|
|
self.initialFilesystem = initialFilesystem
|
|
self.rosetta = rosetta
|
|
self.nestedVirtualization = nestedVirtualization
|
|
self.logger = logger
|
|
}
|
|
|
|
public func create(config: some VMCreationConfig) throws -> any VirtualMachineInstance {
|
|
let vmConfig = config.configuration
|
|
|
|
// Use nested virtualization if requested in config or set as default in manager
|
|
let useNestedVirtualization = vmConfig.nestedVirtualization || self.nestedVirtualization
|
|
|
|
return try VZVirtualMachineInstance(
|
|
logger: self.logger,
|
|
with: { instanceConfig in
|
|
instanceConfig.cpus = vmConfig.cpus
|
|
instanceConfig.memoryInBytes = vmConfig.memoryInBytes
|
|
|
|
instanceConfig.kernel = self.kernel
|
|
instanceConfig.initialFilesystem = self.initialFilesystem
|
|
|
|
if let bootlog = vmConfig.bootlog {
|
|
instanceConfig.bootlog = bootlog
|
|
}
|
|
|
|
instanceConfig.interfaces = vmConfig.interfaces
|
|
instanceConfig.rosetta = self.rosetta
|
|
instanceConfig.nestedVirtualization = useNestedVirtualization
|
|
|
|
instanceConfig.mountsByID = vmConfig.mountsByID
|
|
})
|
|
}
|
|
}
|
|
#endif
|