From ad566faa23d6f7df14c1052dd3745fca95f77d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Wed, 12 Jul 2023 01:02:38 +0200 Subject: [PATCH] Add OCI annotation with upload time (#551) --- Sources/tart/OCI/Manifest.swift | 15 +++++++++++---- Sources/tart/VMDirectory+OCI.swift | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Sources/tart/OCI/Manifest.swift b/Sources/tart/OCI/Manifest.swift index a392412..283d160 100644 --- a/Sources/tart/OCI/Manifest.swift +++ b/Sources/tart/OCI/Manifest.swift @@ -5,6 +5,7 @@ let ociConfigMediaType = "application/vnd.oci.image.config.v1+json" // Annotations let uncompressedDiskSizeAnnotation = "org.cirruslabs.tart.uncompressed-disk-size" +let uploadTimeAnnotation = "org.cirruslabs.tart.upload-time" struct OCIManifest: Codable, Equatable { var schemaVersion: Int = 2 @@ -13,15 +14,21 @@ struct OCIManifest: Codable, Equatable { var layers: [OCIManifestLayer] = Array() var annotations: Dictionary? - init(config: OCIManifestConfig, layers: [OCIManifestLayer], uncompressedDiskSize: UInt64? = nil) { + init(config: OCIManifestConfig, layers: [OCIManifestLayer], uncompressedDiskSize: UInt64? = nil, uploadDate: Date? = nil) { self.config = config self.layers = layers + var annotations: [String: String] = [:] + if let uncompressedDiskSize = uncompressedDiskSize { - annotations = [ - uncompressedDiskSizeAnnotation: String(uncompressedDiskSize) - ] + annotations[uncompressedDiskSizeAnnotation] = String(uncompressedDiskSize) } + + if let uploadDate = uploadDate { + annotations[uploadTimeAnnotation] = uploadDate.toISO() + } + + self.annotations = annotations } init(fromJSON: Data) throws { diff --git a/Sources/tart/VMDirectory+OCI.swift b/Sources/tart/VMDirectory+OCI.swift index de6fe3e..fb60625 100644 --- a/Sources/tart/VMDirectory+OCI.swift +++ b/Sources/tart/VMDirectory+OCI.swift @@ -148,7 +148,8 @@ extension VMDirectory { let manifest = OCIManifest( config: OCIManifestConfig(size: ociConfigJSON.count, digest: ociConfigDigest), layers: layers, - uncompressedDiskSize: UInt64(mappedDiskReadOffset) + uncompressedDiskSize: UInt64(mappedDiskReadOffset), + uploadDate: Date() ) // Manifest