Skip to content

Commit 018844e

Browse files
committed
ContainerizationOCI: Add OCI prefix to types
A large majority of the types in this package were extremely generically named making it common to have to reference the types as ContainerizationOCI.TheType. This change prefixes all of the core runtime spec, and image spec types with OCI, and then adjusts our code to reference these new names so we still build :) This is a breaking change, but I'd rather pull the bandaid now.
1 parent f254f48 commit 018844e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+423
-423
lines changed

Sources/Containerization/Agent/Vminitd.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extension Vminitd: VirtualMachineAgent {
5555

5656
try await setenv(key: "PATH", value: Self.defaultPath)
5757

58-
let mounts: [ContainerizationOCI.Mount] = [
58+
let mounts: [OCIMount] = [
5959
.init(type: "sysfs", source: "sysfs", destination: "/sys"),
6060
.init(type: "tmpfs", source: "tmpfs", destination: "/tmp"),
6161
.init(type: "devpts", source: "devpts", destination: "/dev/pts", options: ["gid=5", "mode=620", "ptmxmode=666"]),
@@ -67,7 +67,7 @@ extension Vminitd: VirtualMachineAgent {
6767
}
6868

6969
/// Mount a filesystem in the sandbox's environment.
70-
public func mount(_ mount: ContainerizationOCI.Mount) async throws {
70+
public func mount(_ mount: OCIMount) async throws {
7171
_ = try await client.mount(
7272
.with {
7373
$0.type = mount.type
@@ -102,7 +102,7 @@ extension Vminitd: VirtualMachineAgent {
102102
stdinPort: UInt32?,
103103
stdoutPort: UInt32?,
104104
stderrPort: UInt32?,
105-
configuration: ContainerizationOCI.Spec,
105+
configuration: OCISpec,
106106
options: Data?
107107
) async throws {
108108
let enc = JSONEncoder()

Sources/Containerization/Image/Image.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ public struct Image: Sendable {
3030
/// The string reference of the image.
3131
public let reference: String
3232
/// The descriptor identifying the image.
33-
public let descriptor: Descriptor
33+
public let descriptor: OCIDescriptor
3434
/// The digest for the image.
3535
public var digest: String { descriptor.digest }
3636
/// The media type of the image.
3737
public var mediaType: String { descriptor.mediaType }
3838

39-
public init(reference: String, descriptor: Descriptor) {
39+
public init(reference: String, descriptor: OCIDescriptor) {
4040
self.reference = reference
4141
self.descriptor = descriptor
4242
}
4343
}
4444

4545
/// The descriptor for the image.
46-
public var descriptor: Descriptor { description.descriptor }
46+
public var descriptor: OCIDescriptor { description.descriptor }
4747
/// The digest of the image.
4848
public var digest: String { description.digest }
4949
/// The media type of the image.
@@ -57,15 +57,15 @@ public struct Image: Sendable {
5757
}
5858

5959
/// Returns the underlying OCI index for the image.
60-
public func index() async throws -> Index {
60+
public func index() async throws -> OCIIndex {
6161
guard let content: Content = try await contentStore.get(digest: digest) else {
6262
throw ContainerizationError(.notFound, message: "Content with digest \(digest)")
6363
}
6464
return try content.decode()
6565
}
6666

6767
/// Returns the manifest for the specified platform.
68-
public func manifest(for platform: Platform) async throws -> Manifest {
68+
public func manifest(for platform: OCIPlatform) async throws -> OCIManifest {
6969
let index = try await self.index()
7070
let desc = index.manifests.first { desc in
7171
desc.platform == platform
@@ -81,7 +81,7 @@ public struct Image: Sendable {
8181

8282
/// Returns the descriptor for the given platform. If it does not exist
8383
/// will throw a ContainerizationError with the code set to .invalidArgument.
84-
public func descriptor(for platform: Platform) async throws -> Descriptor {
84+
public func descriptor(for platform: OCIPlatform) async throws -> OCIDescriptor {
8585
let index = try await self.index()
8686
let desc = index.manifests.first { $0.platform == platform }
8787
guard let desc else {
@@ -91,7 +91,7 @@ public struct Image: Sendable {
9191
}
9292

9393
/// Returns the OCI config for the specified platform.
94-
public func config(for platform: Platform) async throws -> ContainerizationOCI.Image {
94+
public func config(for platform: OCIPlatform) async throws -> OCIImage {
9595
let manifest = try await self.manifest(for: platform)
9696
let desc = manifest.config
9797
guard let content: Content = try await contentStore.get(digest: desc.digest) else {
@@ -106,7 +106,7 @@ public struct Image: Sendable {
106106
let index = try await self.index()
107107
for manifest in index.manifests {
108108
referenced.append(manifest.digest.trimmingDigestPrefix)
109-
guard let m: Manifest = try? await contentStore.get(digest: manifest.digest) else {
109+
guard let m: OCIManifest = try? await contentStore.get(digest: manifest.digest) else {
110110
// If the requested digest does not exist or is not a manifest. Skip.
111111
// Its safe to skip processing this digest as it wont have any child layers.
112112
continue

Sources/Containerization/Image/ImageStore/ImageStore+Export.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ extension ImageStore {
4040
}
4141

4242
@discardableResult
43-
internal func export(index: Descriptor, platforms: (Platform) -> Bool) async throws -> Descriptor {
44-
var pushQueue: [[Descriptor]] = []
45-
var current: [Descriptor] = [index]
43+
internal func export(index: OCIDescriptor, platforms: (OCIPlatform) -> Bool) async throws -> OCIDescriptor {
44+
var pushQueue: [[OCIDescriptor]] = []
45+
var current: [OCIDescriptor] = [index]
4646
while !current.isEmpty {
4747
let children = try await self.getChildren(descs: current)
4848
let matches = try filterPlatforms(matcher: platforms, children).uniqued { $0.digest }
@@ -78,16 +78,16 @@ extension ImageStore {
7878
// Lastly, we need to construct and push a new index, since we may
7979
// have pushed content only for specific platforms.
8080
let digest = SHA256.hash(data: localIndexData)
81-
let descriptor = Descriptor(
82-
mediaType: MediaTypes.index,
81+
let descriptor = OCIDescriptor(
82+
mediaType: OCIMediaTypes.index,
8383
digest: digest.digestString,
8484
size: Int64(localIndexData.count))
8585
let stream = ReadStream(data: localIndexData)
8686
try await self.pushContent(descriptor: descriptor, stream: stream)
8787
return descriptor
8888
}
8989

90-
private func updatePushProgress(pushQueue: [[Descriptor]], localIndexData: Data) async {
90+
private func updatePushProgress(pushQueue: [[OCIDescriptor]], localIndexData: Data) async {
9191
for layerGroup in pushQueue {
9292
for desc in layerGroup {
9393
await progress?([
@@ -102,13 +102,13 @@ extension ImageStore {
102102
])
103103
}
104104

105-
private func createIndex(from index: Descriptor, matching: (Platform) -> Bool) async throws -> Data {
105+
private func createIndex(from index: OCIDescriptor, matching: (OCIPlatform) -> Bool) async throws -> Data {
106106
guard let content = try await self.contentStore.get(digest: index.digest) else {
107107
throw ContainerizationError(.notFound, message: "Content with digest \(index.digest)")
108108
}
109-
var idx: Index = try content.decode()
109+
var idx: OCIIndex = try content.decode()
110110
let manifests = idx.manifests
111-
var matchedManifests: [Descriptor] = []
111+
var matchedManifests: [OCIDescriptor] = []
112112
var skippedPlatforms = false
113113
for manifest in manifests {
114114
guard let p = manifest.platform else {
@@ -127,7 +127,7 @@ extension ImageStore {
127127
return try JSONEncoder().encode(idx)
128128
}
129129

130-
private func pushContent(descriptor: Descriptor, stream: ReadStream) async throws {
130+
private func pushContent(descriptor: OCIDescriptor, stream: ReadStream) async throws {
131131
do {
132132
let generator = {
133133
try stream.reset()
@@ -151,19 +151,19 @@ extension ImageStore {
151151
}
152152
}
153153

154-
private func getChildren(descs: [Descriptor]) async throws -> [Descriptor] {
155-
var out: [Descriptor] = []
154+
private func getChildren(descs: [OCIDescriptor]) async throws -> [OCIDescriptor] {
155+
var out: [OCIDescriptor] = []
156156
for desc in descs {
157157
let mediaType = desc.mediaType
158158
guard let content = try await self.contentStore.get(digest: desc.digest) else {
159159
throw ContainerizationError(.notFound, message: "Content with digest \(desc.digest)")
160160
}
161161
switch mediaType {
162-
case MediaTypes.index, MediaTypes.dockerManifestList:
163-
let index: Index = try content.decode()
162+
case OCIMediaTypes.index, OCIMediaTypes.dockerManifestList:
163+
let index: OCIIndex = try content.decode()
164164
out.append(contentsOf: index.manifests)
165-
case MediaTypes.imageManifest, MediaTypes.dockerManifest:
166-
let manifest: Manifest = try content.decode()
165+
case OCIMediaTypes.imageManifest, OCIMediaTypes.dockerManifest:
166+
let manifest: OCIManifest = try content.decode()
167167
out.append(manifest.config)
168168
out.append(contentsOf: manifest.layers)
169169
default:

Sources/Containerization/Image/ImageStore/ImageStore+Import.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension ImageStore {
4040
}
4141

4242
/// Pull the required image layers for the provided descriptor and platform(s) into the given directory using the provided client. Returns a descriptor to the Index manifest.
43-
internal func `import`(root: Descriptor, matcher: (ContainerizationOCI.Platform) -> Bool) async throws -> Descriptor {
43+
internal func `import`(root: OCIDescriptor, matcher: (OCIPlatform) -> Bool) async throws -> OCIDescriptor {
4444
var toProcess = [root]
4545
while !toProcess.isEmpty {
4646
// Count the total number of blobs and their size
@@ -61,14 +61,14 @@ extension ImageStore {
6161
toProcess = filtered.uniqued { $0.digest }
6262
}
6363

64-
guard root.mediaType != MediaTypes.dockerManifestList && root.mediaType != MediaTypes.index else {
64+
guard root.mediaType != OCIMediaTypes.dockerManifestList && root.mediaType != OCIMediaTypes.index else {
6565
return root
6666
}
6767

6868
// Create an index for the root descriptor and write it to the content store
6969
let index = try await self.createIndex(for: root)
70-
// In cases where the root descriptor pointed to `MediaTypes.imageManifest`
71-
// Or `MediaTypes.dockerManifest`, it is required that we check the supported platform
70+
// In cases where the root descriptor pointed to `OCIMediaTypes.imageManifest`
71+
// Or `OCIMediaTypes.dockerManifest`, it is required that we check the supported platform
7272
// matches the platforms we were asked to pull. This can be done only after we created
7373
// the Index.
7474
let supportedPlatforms = index.manifests.compactMap { $0.platform }
@@ -77,13 +77,13 @@ extension ImageStore {
7777
}
7878
let writer = try ContentWriter(for: self.ingestDir)
7979
let result = try writer.create(from: index)
80-
return Descriptor(
81-
mediaType: MediaTypes.index,
80+
return OCIDescriptor(
81+
mediaType: OCIMediaTypes.index,
8282
digest: result.digest.digestString,
8383
size: Int64(result.size))
8484
}
8585

86-
private func getManifestContent<T: Sendable & Codable>(descriptor: Descriptor) async throws -> T {
86+
private func getManifestContent<T: Sendable & Codable>(descriptor: OCIDescriptor) async throws -> T {
8787
do {
8888
if let content = try await self.contentStore.get(digest: descriptor.digest.trimmingDigestPrefix) {
8989
return try content.decode()
@@ -97,16 +97,16 @@ extension ImageStore {
9797
}
9898
}
9999

100-
private func walk(_ descriptors: [Descriptor]) async throws -> [Descriptor] {
101-
var out: [Descriptor] = []
100+
private func walk(_ descriptors: [OCIDescriptor]) async throws -> [OCIDescriptor] {
101+
var out: [OCIDescriptor] = []
102102
for desc in descriptors {
103103
let mediaType = desc.mediaType
104104
switch mediaType {
105-
case MediaTypes.index, MediaTypes.dockerManifestList:
106-
let index: Index = try await self.getManifestContent(descriptor: desc)
105+
case OCIMediaTypes.index, OCIMediaTypes.dockerManifestList:
106+
let index: OCIIndex = try await self.getManifestContent(descriptor: desc)
107107
out.append(contentsOf: index.manifests)
108-
case MediaTypes.imageManifest, MediaTypes.dockerManifest:
109-
let manifest: Manifest = try await self.getManifestContent(descriptor: desc)
108+
case OCIMediaTypes.imageManifest, OCIMediaTypes.dockerManifest:
109+
let manifest: OCIManifest = try await self.getManifestContent(descriptor: desc)
110110
out.append(manifest.config)
111111
out.append(contentsOf: manifest.layers)
112112
default:
@@ -117,7 +117,7 @@ extension ImageStore {
117117
return out
118118
}
119119

120-
private func fetchAll(_ descriptors: [Descriptor]) async throws {
120+
private func fetchAll(_ descriptors: [OCIDescriptor]) async throws {
121121
try await withThrowingTaskGroup(of: Void.self) { group in
122122
var iterator = descriptors.makeIterator()
123123
for _ in 0..<8 {
@@ -137,7 +137,7 @@ extension ImageStore {
137137
}
138138
}
139139

140-
private func fetch(_ descriptor: Descriptor) async throws {
140+
private func fetch(_ descriptor: OCIDescriptor) async throws {
141141
if let found = try await self.contentStore.get(digest: descriptor.digest) {
142142
try FileManager.default.copyItem(at: found.path, to: ingestDir.appendingPathComponent(descriptor.digest.trimmingDigestPrefix))
143143
await progress?([
@@ -160,7 +160,7 @@ extension ImageStore {
160160
])
161161
}
162162

163-
private func fetchBlob(_ descriptor: Descriptor) async throws {
163+
private func fetchBlob(_ descriptor: OCIDescriptor) async throws {
164164
let id = UUID().uuidString
165165
let fm = FileManager.default
166166
let tempFile = ingestDir.appendingPathComponent(id)
@@ -179,7 +179,7 @@ extension ImageStore {
179179
}
180180

181181
@discardableResult
182-
private func fetchData(_ descriptor: Descriptor) async throws -> Data {
182+
private func fetchData(_ descriptor: OCIDescriptor) async throws -> Data {
183183
let data = try await client.fetchData(name: name, descriptor: descriptor)
184184
let writer = try ContentWriter(for: ingestDir)
185185
let result = try writer.write(data)
@@ -195,11 +195,11 @@ extension ImageStore {
195195
return data
196196
}
197197

198-
private func createIndex(for root: Descriptor) async throws -> Index {
198+
private func createIndex(for root: OCIDescriptor) async throws -> OCIIndex {
199199
switch root.mediaType {
200-
case MediaTypes.index, MediaTypes.dockerManifestList:
200+
case OCIMediaTypes.index, OCIMediaTypes.dockerManifestList:
201201
return try await self.getManifestContent(descriptor: root)
202-
case MediaTypes.imageManifest, MediaTypes.dockerManifest:
202+
case OCIMediaTypes.imageManifest, OCIMediaTypes.dockerManifest:
203203
let supportedPlatforms = try await getSupportedPlatforms(for: root)
204204
guard supportedPlatforms.count == 1 else {
205205
throw ContainerizationError(
@@ -211,15 +211,15 @@ extension ImageStore {
211211
let platform = supportedPlatforms.first!
212212
var root = root
213213
root.platform = platform
214-
let index = ContainerizationOCI.Index(schemaVersion: 2, manifests: [root])
214+
let index = OCIIndex(schemaVersion: 2, manifests: [root])
215215
return index
216216
default:
217217
throw ContainerizationError(.internalError, message: "Failed to create index for descriptor \(root.digest), media type \(root.mediaType)")
218218
}
219219
}
220220

221-
private func getSupportedPlatforms(for root: Descriptor) async throws -> [ContainerizationOCI.Platform] {
222-
var supportedPlatforms: [ContainerizationOCI.Platform] = []
221+
private func getSupportedPlatforms(for root: OCIDescriptor) async throws -> [OCIPlatform] {
222+
var supportedPlatforms: [OCIPlatform] = []
223223
var toProcess = [root]
224224
while !toProcess.isEmpty {
225225
let children = try await self.walk(toProcess)
@@ -229,9 +229,9 @@ extension ImageStore {
229229
continue
230230
}
231231
switch child.mediaType {
232-
case MediaTypes.imageConfig, MediaTypes.dockerImageConfig:
233-
let config: ContainerizationOCI.Image = try await self.getManifestContent(descriptor: child)
234-
let p = ContainerizationOCI.Platform(
232+
case OCIMediaTypes.imageConfig, OCIMediaTypes.dockerImageConfig:
233+
let config: OCIImage = try await self.getManifestContent(descriptor: child)
234+
let p = OCIPlatform(
235235
arch: config.architecture, os: config.os, osFeatures: config.osFeatures, variant: config.variant
236236
)
237237
supportedPlatforms.append(p)

Sources/Containerization/Image/ImageStore/ImageStore+OCILayout.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension ImageStore {
3030
/// - platform: An optional parameter to indicate the platform to be saved for the images.
3131
/// Defaults to `nil` signifying that layers for all supported platforms by the images will be saved.
3232
///
33-
public func save(references: [String], out: URL, platform: Platform? = nil) async throws {
33+
public func save(references: [String], out: URL, platform: OCIPlatform? = nil) async throws {
3434
let matcher = createPlatformMatcher(for: platform)
3535
let fileManager = FileManager.default
3636
let tempDir = fileManager.uniqueTemporaryDirectory()
@@ -41,14 +41,14 @@ extension ImageStore {
4141
var toSave: [Image] = []
4242
for reference in references {
4343
let image = try await self.get(reference: reference)
44-
let allowedMediaTypes = [MediaTypes.dockerManifestList, MediaTypes.index]
44+
let allowedMediaTypes = [OCIMediaTypes.dockerManifestList, OCIMediaTypes.index]
4545
guard allowedMediaTypes.contains(image.mediaType) else {
4646
throw ContainerizationError(.internalError, message: "Cannot save image \(image.reference) with Index media type \(image.mediaType)")
4747
}
4848
toSave.append(image)
4949
}
5050
let client = try LocalOCILayoutClient(root: out)
51-
var saved: [Descriptor] = []
51+
var saved: [OCIDescriptor] = []
5252

5353
for image in toSave {
5454
let ref = try Reference.parse(image.reference)

Sources/Containerization/Image/ImageStore/ImageStore+ReferenceManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension ImageStore {
2424
internal actor ReferenceManager: Sendable {
2525
private let path: URL
2626

27-
private typealias State = [String: Descriptor]
27+
private typealias State = [String: OCIDescriptor]
2828
private var images: State
2929

3030
public init(path: URL) throws {

0 commit comments

Comments
 (0)