Skip to content

Commit 5cca80f

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 402339e commit 5cca80f

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
-424
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 & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
// limitations under the License.
1515
//===----------------------------------------------------------------------===//
1616

17-
//
18-
1917
import ContainerizationError
2018
import ContainerizationExtras
2119
import ContainerizationOCI
@@ -40,7 +38,7 @@ extension ImageStore {
4038
}
4139

4240
/// 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 {
41+
internal func `import`(root: OCIDescriptor, matcher: (OCIPlatform) -> Bool) async throws -> OCIDescriptor {
4442
var toProcess = [root]
4543
while !toProcess.isEmpty {
4644
// Count the total number of blobs and their size
@@ -61,14 +59,14 @@ extension ImageStore {
6159
toProcess = filtered.uniqued { $0.digest }
6260
}
6361

64-
guard root.mediaType != MediaTypes.dockerManifestList && root.mediaType != MediaTypes.index else {
62+
guard root.mediaType != OCIMediaTypes.dockerManifestList && root.mediaType != OCIMediaTypes.index else {
6563
return root
6664
}
6765

6866
// Create an index for the root descriptor and write it to the content store
6967
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
68+
// In cases where the root descriptor pointed to `OCIMediaTypes.imageManifest`
69+
// Or `OCIMediaTypes.dockerManifest`, it is required that we check the supported platform
7270
// matches the platforms we were asked to pull. This can be done only after we created
7371
// the Index.
7472
let supportedPlatforms = index.manifests.compactMap { $0.platform }
@@ -77,13 +75,13 @@ extension ImageStore {
7775
}
7876
let writer = try ContentWriter(for: self.ingestDir)
7977
let result = try writer.create(from: index)
80-
return Descriptor(
81-
mediaType: MediaTypes.index,
78+
return OCIDescriptor(
79+
mediaType: OCIMediaTypes.index,
8280
digest: result.digest.digestString,
8381
size: Int64(result.size))
8482
}
8583

86-
private func getManifestContent<T: Sendable & Codable>(descriptor: Descriptor) async throws -> T {
84+
private func getManifestContent<T: Sendable & Codable>(descriptor: OCIDescriptor) async throws -> T {
8785
do {
8886
if let content = try await self.contentStore.get(digest: descriptor.digest.trimmingDigestPrefix) {
8987
return try content.decode()
@@ -97,16 +95,16 @@ extension ImageStore {
9795
}
9896
}
9997

100-
private func walk(_ descriptors: [Descriptor]) async throws -> [Descriptor] {
101-
var out: [Descriptor] = []
98+
private func walk(_ descriptors: [OCIDescriptor]) async throws -> [OCIDescriptor] {
99+
var out: [OCIDescriptor] = []
102100
for desc in descriptors {
103101
let mediaType = desc.mediaType
104102
switch mediaType {
105-
case MediaTypes.index, MediaTypes.dockerManifestList:
106-
let index: Index = try await self.getManifestContent(descriptor: desc)
103+
case OCIMediaTypes.index, OCIMediaTypes.dockerManifestList:
104+
let index: OCIIndex = try await self.getManifestContent(descriptor: desc)
107105
out.append(contentsOf: index.manifests)
108-
case MediaTypes.imageManifest, MediaTypes.dockerManifest:
109-
let manifest: Manifest = try await self.getManifestContent(descriptor: desc)
106+
case OCIMediaTypes.imageManifest, OCIMediaTypes.dockerManifest:
107+
let manifest: OCIManifest = try await self.getManifestContent(descriptor: desc)
110108
out.append(manifest.config)
111109
out.append(contentsOf: manifest.layers)
112110
default:
@@ -117,7 +115,7 @@ extension ImageStore {
117115
return out
118116
}
119117

120-
private func fetchAll(_ descriptors: [Descriptor]) async throws {
118+
private func fetchAll(_ descriptors: [OCIDescriptor]) async throws {
121119
try await withThrowingTaskGroup(of: Void.self) { group in
122120
var iterator = descriptors.makeIterator()
123121
for _ in 0..<8 {
@@ -137,7 +135,7 @@ extension ImageStore {
137135
}
138136
}
139137

140-
private func fetch(_ descriptor: Descriptor) async throws {
138+
private func fetch(_ descriptor: OCIDescriptor) async throws {
141139
if let found = try await self.contentStore.get(digest: descriptor.digest) {
142140
try FileManager.default.copyItem(at: found.path, to: ingestDir.appendingPathComponent(descriptor.digest.trimmingDigestPrefix))
143141
await progress?([
@@ -160,7 +158,7 @@ extension ImageStore {
160158
])
161159
}
162160

163-
private func fetchBlob(_ descriptor: Descriptor) async throws {
161+
private func fetchBlob(_ descriptor: OCIDescriptor) async throws {
164162
let id = UUID().uuidString
165163
let fm = FileManager.default
166164
let tempFile = ingestDir.appendingPathComponent(id)
@@ -179,7 +177,7 @@ extension ImageStore {
179177
}
180178

181179
@discardableResult
182-
private func fetchData(_ descriptor: Descriptor) async throws -> Data {
180+
private func fetchData(_ descriptor: OCIDescriptor) async throws -> Data {
183181
let data = try await client.fetchData(name: name, descriptor: descriptor)
184182
let writer = try ContentWriter(for: ingestDir)
185183
let result = try writer.write(data)
@@ -195,11 +193,11 @@ extension ImageStore {
195193
return data
196194
}
197195

198-
private func createIndex(for root: Descriptor) async throws -> Index {
196+
private func createIndex(for root: OCIDescriptor) async throws -> OCIIndex {
199197
switch root.mediaType {
200-
case MediaTypes.index, MediaTypes.dockerManifestList:
198+
case OCIMediaTypes.index, OCIMediaTypes.dockerManifestList:
201199
return try await self.getManifestContent(descriptor: root)
202-
case MediaTypes.imageManifest, MediaTypes.dockerManifest:
200+
case OCIMediaTypes.imageManifest, OCIMediaTypes.dockerManifest:
203201
let supportedPlatforms = try await getSupportedPlatforms(for: root)
204202
guard supportedPlatforms.count == 1 else {
205203
throw ContainerizationError(
@@ -211,7 +209,7 @@ extension ImageStore {
211209
let platform = supportedPlatforms.first!
212210
var root = root
213211
root.platform = platform
214-
let index = ContainerizationOCI.Index(
212+
let index = OCIIndex(
215213
schemaVersion: 2, manifests: [root],
216214
annotations: [
217215
// indicate that this is a synthesized index which is not directly user facing
@@ -223,8 +221,8 @@ extension ImageStore {
223221
}
224222
}
225223

226-
private func getSupportedPlatforms(for root: Descriptor) async throws -> [ContainerizationOCI.Platform] {
227-
var supportedPlatforms: [ContainerizationOCI.Platform] = []
224+
private func getSupportedPlatforms(for root: OCIDescriptor) async throws -> [OCIPlatform] {
225+
var supportedPlatforms: [OCIPlatform] = []
228226
var toProcess = [root]
229227
while !toProcess.isEmpty {
230228
let children = try await self.walk(toProcess)
@@ -234,9 +232,9 @@ extension ImageStore {
234232
continue
235233
}
236234
switch child.mediaType {
237-
case MediaTypes.imageConfig, MediaTypes.dockerImageConfig:
238-
let config: ContainerizationOCI.Image = try await self.getManifestContent(descriptor: child)
239-
let p = ContainerizationOCI.Platform(
235+
case OCIMediaTypes.imageConfig, OCIMediaTypes.dockerImageConfig:
236+
let config: OCIImage = try await self.getManifestContent(descriptor: child)
237+
let p = OCIPlatform(
240238
arch: config.architecture, os: config.os, osFeatures: config.osFeatures, variant: config.variant
241239
)
242240
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)