mirror of
https://github.com/apple/container.git
synced 2026-09-19 14:15:53 +00:00
- Discussion topic #1336. - This change migrates away from using `UserDefaults`, instead providing a TOML configuration mechanism for user configurable settings. All existing system property settings keys are supported in the new configuration file. However, users will have to migrate any settings they have configured in the `UserDefaults` into TOML for these settings to take effect. - Breaking changes: * `container system property get` is removed in favor of users directly utilizing `container system property list --format toml | jq<>`. * `container system property set` is removed since the TOML configuration is effectively immutable during the lifetime of the `container` daemon. Uses can edit the TOML they have in their home directory, however no changes will take effect until the daemon is restarted via `container system stop && container system start` * `container system property list --format table` is removed as generating tabular format is non-trivial and the new TOML format is intended to be human readable
130 lines
6.0 KiB
Swift
130 lines
6.0 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
// Copyright © 2026 Apple Inc. and the container 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.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import ArgumentParser
|
|
import ContainerImagesService
|
|
import ContainerImagesServiceClient
|
|
import ContainerLog
|
|
import ContainerPersistence
|
|
import ContainerPlugin
|
|
import ContainerVersion
|
|
import ContainerXPC
|
|
import Containerization
|
|
import Foundation
|
|
import Logging
|
|
|
|
@main
|
|
struct ImagesHelper: AsyncParsableCommand {
|
|
static let configuration = CommandConfiguration(
|
|
commandName: "container-core-images",
|
|
abstract: "XPC service for managing OCI images",
|
|
version: ReleaseVersion.singleLine(appName: "container-core-images"),
|
|
subcommands: [
|
|
Start.self
|
|
]
|
|
)
|
|
}
|
|
|
|
extension ImagesHelper {
|
|
struct Start: AsyncParsableCommand {
|
|
static let configuration = CommandConfiguration(
|
|
commandName: "start",
|
|
abstract: "Starts the image plugin"
|
|
)
|
|
|
|
@Flag(name: .long, help: "Enable debug logging")
|
|
var debug = false
|
|
|
|
@Option(name: .long, help: "XPC service prefix")
|
|
var serviceIdentifier: String = "com.apple.container.core.container-core-images"
|
|
|
|
var appRoot = ApplicationRoot.url
|
|
|
|
var installRoot = InstallRoot.url
|
|
|
|
var logRoot = LogRoot.path
|
|
|
|
func run() async throws {
|
|
let containerSystemConfig: ContainerSystemConfig = try SystemRuntimeOptions.loadConfig(
|
|
configFile: SystemRuntimeOptions.configFileFromAppRoot(ApplicationRoot.url)
|
|
)
|
|
let commandName = ImagesHelper._commandName
|
|
let logPath = logRoot.map { $0.appending("\(commandName).log") }
|
|
let log = ServiceLogger.bootstrap(category: "ImagesHelper", debug: debug, logPath: logPath)
|
|
log.info("starting helper", metadata: ["name": "\(commandName)"])
|
|
defer {
|
|
log.info("stopping helper", metadata: ["name": "\(commandName)"])
|
|
}
|
|
|
|
do {
|
|
log.info("configuring XPC server")
|
|
var routes = [String: XPCServer.RouteHandler]()
|
|
try self.initializeContentService(root: appRoot, log: log, routes: &routes)
|
|
try self.initializeImagesService(root: appRoot, containerSystemConfig: containerSystemConfig, log: log, routes: &routes)
|
|
let xpc = XPCServer(
|
|
identifier: serviceIdentifier,
|
|
routes: routes,
|
|
log: log
|
|
)
|
|
log.info("starting XPC server")
|
|
try await xpc.listen()
|
|
} catch {
|
|
log.error(
|
|
"helper failed",
|
|
metadata: [
|
|
"name": "\(commandName)",
|
|
"error": "\(error)",
|
|
])
|
|
ImagesHelper.exit(withError: error)
|
|
}
|
|
}
|
|
|
|
private func initializeImagesService(root: URL, containerSystemConfig: ContainerSystemConfig, log: Logger, routes: inout [String: XPCServer.RouteHandler]) throws {
|
|
let contentStore = RemoteContentStoreClient()
|
|
let imageStore = try ImageStore(path: root, contentStore: contentStore)
|
|
let unpackStrategy = SnapshotStore.defaultUnpackStrategy(initImage: containerSystemConfig.vminit.image)
|
|
let snapshotStore = try SnapshotStore(path: root, unpackStrategy: unpackStrategy, log: log)
|
|
let service = try ImagesService(contentStore: contentStore, imageStore: imageStore, snapshotStore: snapshotStore, log: log)
|
|
let harness = ImagesServiceHarness(service: service, log: log)
|
|
|
|
routes[ImagesServiceXPCRoute.imagePull.rawValue] = harness.pull
|
|
routes[ImagesServiceXPCRoute.imageList.rawValue] = harness.list
|
|
routes[ImagesServiceXPCRoute.imageDelete.rawValue] = harness.delete
|
|
routes[ImagesServiceXPCRoute.imageTag.rawValue] = harness.tag
|
|
routes[ImagesServiceXPCRoute.imagePush.rawValue] = harness.push
|
|
routes[ImagesServiceXPCRoute.imageSave.rawValue] = harness.save
|
|
routes[ImagesServiceXPCRoute.imageLoad.rawValue] = harness.load
|
|
routes[ImagesServiceXPCRoute.imageUnpack.rawValue] = harness.unpack
|
|
routes[ImagesServiceXPCRoute.imageCleanupOrphanedBlobs.rawValue] = harness.cleanUpOrphanedBlobs
|
|
routes[ImagesServiceXPCRoute.imageDiskUsage.rawValue] = harness.calculateDiskUsage
|
|
routes[ImagesServiceXPCRoute.snapshotDelete.rawValue] = harness.deleteSnapshot
|
|
routes[ImagesServiceXPCRoute.snapshotGet.rawValue] = harness.getSnapshot
|
|
}
|
|
|
|
private func initializeContentService(root: URL, log: Logger, routes: inout [String: XPCServer.RouteHandler]) throws {
|
|
let service = try ContentStoreService(root: root, log: log)
|
|
let harness = ContentServiceHarness(service: service, log: log)
|
|
|
|
routes[ImagesServiceXPCRoute.contentClean.rawValue] = harness.clean
|
|
routes[ImagesServiceXPCRoute.contentGet.rawValue] = harness.get
|
|
routes[ImagesServiceXPCRoute.contentDelete.rawValue] = harness.delete
|
|
routes[ImagesServiceXPCRoute.contentIngestStart.rawValue] = harness.newIngestSession
|
|
routes[ImagesServiceXPCRoute.contentIngestCancel.rawValue] = harness.cancelIngestSession
|
|
routes[ImagesServiceXPCRoute.contentIngestComplete.rawValue] = harness.completeIngestSession
|
|
}
|
|
}
|
|
}
|