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
14 changes: 0 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import CompilerPluginSupport
import Foundation
import PackageDescription

let gitCommit = ProcessInfo.processInfo.environment["GIT_COMMIT"] ?? "unspecified"
let gitTag = ProcessInfo.processInfo.environment["GIT_TAG"] ?? ""
let buildTime = ProcessInfo.processInfo.environment["BUILD_TIME"] ?? "unspecified"

let package = Package(
name: "containerization",
platforms: [.macOS("15.0")],
Expand Down Expand Up @@ -264,15 +260,6 @@ let package = Package(
.target(
name: "CShim"
),
.target(
name: "CVersion",
path: "vminitd/Sources/CVersion",
cSettings: [
.define("GIT_COMMIT", to: "\"\(gitCommit)\""),
.define("GIT_TAG", to: "\"\(gitTag)\""),
.define("BUILD_TIME", to: "\"\(buildTime)\""),
]
),
.target(
name: "LCShim",
path: "vminitd/Sources/LCShim"
Expand Down Expand Up @@ -303,7 +290,6 @@ let package = Package(
.product(name: "GRPCNIOTransportHTTP2", package: "grpc-swift-nio-transport"),
.product(name: "GRPCProtobuf", package: "grpc-swift-protobuf"),
"LCShim",
"CVersion",
"Cgroup",
],
path: "vminitd/Sources/VminitdCore"
Expand Down
14 changes: 14 additions & 0 deletions vminitd/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@

// The swift-tools-version declares the minimum version of Swift required to build this package.

import Foundation
import PackageDescription

let gitCommit = ProcessInfo.processInfo.environment["GIT_COMMIT"] ?? "unspecified"
let gitTag = ProcessInfo.processInfo.environment["GIT_TAG"] ?? ""
let buildTime = ProcessInfo.processInfo.environment["BUILD_TIME"] ?? "unspecified"

let package = Package(
name: "swift-vminitd",
platforms: [.macOS("15")],
Expand All @@ -33,13 +38,22 @@ let package = Package(
.package(name: "containerization", path: "../"),
],
targets: [
.target(
name: "CVersion",
cSettings: [
.define("GIT_COMMIT", to: "\"\(gitCommit)\""),
.define("GIT_TAG", to: "\"\(gitTag)\""),
.define("BUILD_TIME", to: "\"\(buildTime)\""),
]
),
.executableTarget(
name: "vminitd",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "ContainerizationOS", package: "containerization"),
.product(name: "Logging", package: "swift-log"),
.product(name: "VminitdCore", package: "containerization"),
"CVersion",
]
),
.executableTarget(
Expand Down
10 changes: 1 addition & 9 deletions vminitd/Sources/VminitdCore/AgentCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#if os(Linux)

import ArgumentParser
import CVersion
import Cgroup
import Containerization
import ContainerizationError
Expand Down Expand Up @@ -79,14 +78,7 @@ public struct AgentCommand: AsyncParsableCommand {

signal(SIGPIPE, SIG_IGN)

let gitCommit = String(cString: CZ_get_git_commit())
let gitTag = String(cString: CZ_get_git_tag())
let buildTime = String(cString: CZ_get_build_time())
var metadata: Logger.Metadata = ["commit": "\(gitCommit)", "built": "\(buildTime)"]
if !gitTag.isEmpty {
metadata["tag"] = "\(gitTag)"
}
log.info("vminitd booting", metadata: metadata)
log.info("vminitd booting", metadata: versionMetadata())

// Set of mounts necessary to be mounted prior to taking any RPCs.
// 1. /proc as the sysctl rpc wouldn't make sense if it wasn't there (NOTE: This is done before this method
Expand Down
10 changes: 10 additions & 0 deletions vminitd/Sources/VminitdCore/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public struct LogLevelOption: ParsableArguments {
}

private let _loggingBootstrapped = Mutex(false)
private let _versionMetadata = Mutex<Logger.Metadata>([:])

/// Set the version metadata logged on boot.
public func setVersionMetadata(_ metadata: Logger.Metadata) {
_versionMetadata.withLock { $0 = metadata }
}

func versionMetadata() -> Logger.Metadata {
_versionMetadata.withLock { $0 }
}

func makeLogger(label: String, level: Logger.Level) -> Logger {
_loggingBootstrapped.withLock { bootstrapped in
Expand Down
14 changes: 14 additions & 0 deletions vminitd/Sources/vminitd/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//===----------------------------------------------------------------------===//

import ArgumentParser
import CVersion
import ContainerizationOS
import Foundation
import Logging
Expand All @@ -35,6 +36,8 @@ struct Application: AsyncParsableCommand {
)

static func main() async throws {
setVersionMetadata(Self.versionMetadata())

// Busybox-style: if invoked as .cz-init, run init mode directly.
let invoked = CommandLine.arguments.first?.split(separator: "/").last.map(String.init) ?? ""
if invoked == ".cz-init" {
Expand All @@ -57,6 +60,17 @@ struct Application: AsyncParsableCommand {
}
}

private static func versionMetadata() -> Logger.Metadata {
let gitCommit = String(cString: CZ_get_git_commit())
let gitTag = String(cString: CZ_get_git_tag())
let buildTime = String(cString: CZ_get_build_time())
var metadata: Logger.Metadata = ["commit": "\(gitCommit)", "built": "\(buildTime)"]
if !gitTag.isEmpty {
metadata["tag"] = "\(gitTag)"
}
return metadata
}

private static func mountProc() throws {
if isProcMounted() {
return
Expand Down
Loading