mirror of https://github.com/cirruslabs/tart.git
tart pull: experimental --json-digest option
This commit is contained in:
parent
f6c56ed8eb
commit
842052f5bd
|
|
@ -23,6 +23,9 @@ struct Pull: AsyncParsableCommand {
|
|||
@Option(help: "network concurrency to use when pulling a remote VM from the OCI-compatible registry")
|
||||
var concurrency: UInt = 4
|
||||
|
||||
@Flag(help: .hidden)
|
||||
var jsonDigest: Bool = false
|
||||
|
||||
func validate() throws {
|
||||
if concurrency < 1 {
|
||||
throw ValidationError("network concurrency cannot be less than 1")
|
||||
|
|
@ -30,10 +33,14 @@ struct Pull: AsyncParsableCommand {
|
|||
}
|
||||
|
||||
func run() async throws {
|
||||
if jsonDigest {
|
||||
jsonLogger = SimpleConsoleLogger()
|
||||
}
|
||||
|
||||
// Be more liberal when accepting local image as argument,
|
||||
// see https://github.com/cirruslabs/tart/issues/36
|
||||
if VMStorageLocal().exists(remoteName) {
|
||||
print("\"\(remoteName)\" is a local image, nothing to pull here!")
|
||||
defaultLogger.appendNewLine("\"\(remoteName)\" is a local image, nothing to pull here!")
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,16 +12,13 @@ var defaultLogger: Logger = {
|
|||
return InteractiveConsoleLogger()
|
||||
}
|
||||
}()
|
||||
var jsonLogger: Logger = NopLogger()
|
||||
|
||||
public class InteractiveConsoleLogger: Logger {
|
||||
private let eraseCursorDown = "\u{001B}[J" // clear entire line
|
||||
private let moveUp = "\u{001B}[1A" // move one line up
|
||||
private let moveBeginningOfLine = "\r" //
|
||||
|
||||
public init() {
|
||||
|
||||
}
|
||||
|
||||
public func appendNewLine(_ line: String) {
|
||||
print(line, terminator: "\n")
|
||||
}
|
||||
|
|
@ -32,10 +29,6 @@ public class InteractiveConsoleLogger: Logger {
|
|||
}
|
||||
|
||||
public class SimpleConsoleLogger: Logger {
|
||||
public init() {
|
||||
|
||||
}
|
||||
|
||||
public func appendNewLine(_ line: String) {
|
||||
print(line, terminator: "\n")
|
||||
}
|
||||
|
|
@ -44,3 +37,13 @@ public class SimpleConsoleLogger: Logger {
|
|||
print(line, terminator: "\n")
|
||||
}
|
||||
}
|
||||
|
||||
public class NopLogger: Logger {
|
||||
public func appendNewLine(_ line: String) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public func updateLastLine(_ line: String) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ class VMStorageOCI: PrunableStorage {
|
|||
if exists(name) && exists(digestName) && linked(from: name, to: digestName) {
|
||||
// optimistically check if we need to do anything at all before locking
|
||||
defaultLogger.appendNewLine("\(digestName) image is already cached and linked!")
|
||||
jsonLogger.appendNewLine("{\"digest\": \"\(digestName)\"}")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +160,7 @@ class VMStorageOCI: PrunableStorage {
|
|||
|
||||
let sucessfullyLocked = try lock.trylock()
|
||||
if !sucessfullyLocked {
|
||||
print("waiting for lock...")
|
||||
defaultLogger.appendNewLine("waiting for lock...")
|
||||
try lock.lock()
|
||||
}
|
||||
defer { try! lock.unlock() }
|
||||
|
|
@ -199,6 +200,8 @@ class VMStorageOCI: PrunableStorage {
|
|||
defaultLogger.appendNewLine("\(digestName) image is already cached! creating a symlink...")
|
||||
}
|
||||
|
||||
jsonLogger.appendNewLine("{\"digest\": \"\(digestName)\"}")
|
||||
|
||||
if name != digestName {
|
||||
// Create new or overwrite the old symbolic link
|
||||
try link(from: name, to: digestName)
|
||||
|
|
|
|||
Loading…
Reference in New Issue