Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Sources/ContainerCommands/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import ArgumentParser
import ContainerAPIClient
import ContainerLog
import ContainerPersistence
import ContainerPlugin
import ContainerVersion
import ContainerizationError
import ContainerizationOS
import Foundation
import Logging
import SystemPackage
import TerminalProgress

// This logger is only used until `asyncCommand.run()`.
Expand Down Expand Up @@ -180,6 +182,20 @@ public struct Application: AsyncLoggableCommand {
)
}

/// Load the system configuration using `appRoot` / `installRoot` reported by the
/// daemon. `container system start` MUST have previously been run to start the daemon.
public static func loadContainerSystemConfig() async throws -> ContainerSystemConfig {
let health = try await ClientHealthCheck.ping(timeout: .seconds(10))
let appRoot = FilePath(health.appRoot.path(percentEncoded: false))
let installRoot = FilePath(health.installRoot.path(percentEncoded: false))
return try await ConfigurationLoader.load(
configurationFiles: [
ConfigurationLoader.configurationFile(in: appRoot, of: .appRoot),
ConfigurationLoader.configurationFile(in: installRoot, of: .installRoot),
]
)
}

public func validate() throws {
// Not really a "validation", but a cheat to run this before
// any of the commands do their business.
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/BuildCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ extension Application {
var pull: Bool = false

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
do {
let timeout: Duration = .seconds(300)
let progressConfig = try ProgressConfig(
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Builder/BuilderStart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension Application {
public init() {}

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
let progressConfig = try ProgressConfig(
showTasks: true,
showItems: true,
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Container/ContainerCreate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension Application {
var arguments: [String] = []

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
let progressConfig = try ProgressConfig(
showTasks: true,
showItems: true,
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Container/ContainerRun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension Application {
var arguments: [String] = []

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
var exitCode: Int32 = 127
let id = Utility.createContainerID(name: self.managementFlags.name)

Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Image/ImageDelete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ extension Application {
}

public mutating func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
try await DeleteImageImplementation.removeImage(options: options, containerSystemConfig: containerSystemConfig, log: log)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Image/ImageInspect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension Application {
public init() {}

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
let uniqueNames = Set(images)
let result = try await ClientImage.get(
names: Array(uniqueNames), containerSystemConfig: containerSystemConfig
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Image/ImageList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extension Application {
public var logOptions: Flags.Logging

public mutating func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
try Self.validate(quiet: quiet, verbose: verbose)

var images = try await ClientImage.list().filter { img in
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Image/ImagePull.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extension Application {
}

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
let p = try DefaultPlatform.resolve(platform: platform, os: os, arch: arch, log: log)

let scheme = try RequestScheme(registry.scheme)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Image/ImagePush.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extension Application {
public init() {}

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
let p = try DefaultPlatform.resolve(platform: platform, os: os, arch: arch, log: log)

let scheme = try RequestScheme(registry.scheme)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Image/ImageSave.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension Application {
@Argument var references: [String]

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
let p = try DefaultPlatform.resolve(platform: platform, os: os, arch: arch, log: log)

let progressConfig = try ProgressConfig(
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Image/ImageTag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension Application {
public var logOptions: Flags.Logging

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
let existing = try await ClientImage.get(reference: source, containerSystemConfig: containerSystemConfig)
let targetReference = try ClientImage.normalizeReference(target, containerSystemConfig: containerSystemConfig)
try await existing.tag(new: targetReference)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/Registry/RegistryLogin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension Application {
var server: String

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
var username = self.username
var password = ""
if passwordStdin {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerCommands/System/Kernel/KernelSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension Application {
public init() {}

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
if recommended {
let url = containerSystemConfig.kernel.url
let path: String = containerSystemConfig.kernel.binaryPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension Application {
public init() {}

public func run() async throws {
let containerSystemConfig: ContainerSystemConfig = try await ConfigurationLoader.load()
let containerSystemConfig: ContainerSystemConfig = try await Application.loadContainerSystemConfig()
let output =
switch format {
case .json: try Output.renderJSON(containerSystemConfig)
Expand Down