14
14
// limitations under the License.
15
15
//===----------------------------------------------------------------------===//
16
16
17
- //
18
-
19
17
import ContainerizationError
20
18
import ContainerizationExtras
21
19
import ContainerizationOCI
@@ -40,7 +38,7 @@ extension ImageStore {
40
38
}
41
39
42
40
/// 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 {
44
42
var toProcess = [ root]
45
43
while !toProcess. isEmpty {
46
44
// Count the total number of blobs and their size
@@ -61,14 +59,14 @@ extension ImageStore {
61
59
toProcess = filtered. uniqued { $0. digest }
62
60
}
63
61
64
- guard root. mediaType != MediaTypes . dockerManifestList && root. mediaType != MediaTypes . index else {
62
+ guard root. mediaType != OCIMediaTypes . dockerManifestList && root. mediaType != OCIMediaTypes . index else {
65
63
return root
66
64
}
67
65
68
66
// Create an index for the root descriptor and write it to the content store
69
67
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
72
70
// matches the platforms we were asked to pull. This can be done only after we created
73
71
// the Index.
74
72
let supportedPlatforms = index. manifests. compactMap { $0. platform }
@@ -77,13 +75,13 @@ extension ImageStore {
77
75
}
78
76
let writer = try ContentWriter ( for: self . ingestDir)
79
77
let result = try writer. create ( from: index)
80
- return Descriptor (
81
- mediaType: MediaTypes . index,
78
+ return OCIDescriptor (
79
+ mediaType: OCIMediaTypes . index,
82
80
digest: result. digest. digestString,
83
81
size: Int64 ( result. size) )
84
82
}
85
83
86
- private func getManifestContent< T: Sendable & Codable > ( descriptor: Descriptor ) async throws -> T {
84
+ private func getManifestContent< T: Sendable & Codable > ( descriptor: OCIDescriptor ) async throws -> T {
87
85
do {
88
86
if let content = try await self . contentStore. get ( digest: descriptor. digest. trimmingDigestPrefix) {
89
87
return try content. decode ( )
@@ -97,16 +95,16 @@ extension ImageStore {
97
95
}
98
96
}
99
97
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 ] = [ ]
102
100
for desc in descriptors {
103
101
let mediaType = desc. mediaType
104
102
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)
107
105
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)
110
108
out. append ( manifest. config)
111
109
out. append ( contentsOf: manifest. layers)
112
110
default :
@@ -117,7 +115,7 @@ extension ImageStore {
117
115
return out
118
116
}
119
117
120
- private func fetchAll( _ descriptors: [ Descriptor ] ) async throws {
118
+ private func fetchAll( _ descriptors: [ OCIDescriptor ] ) async throws {
121
119
try await withThrowingTaskGroup ( of: Void . self) { group in
122
120
var iterator = descriptors. makeIterator ( )
123
121
for _ in 0 ..< 8 {
@@ -137,7 +135,7 @@ extension ImageStore {
137
135
}
138
136
}
139
137
140
- private func fetch( _ descriptor: Descriptor ) async throws {
138
+ private func fetch( _ descriptor: OCIDescriptor ) async throws {
141
139
if let found = try await self . contentStore. get ( digest: descriptor. digest) {
142
140
try FileManager . default. copyItem ( at: found. path, to: ingestDir. appendingPathComponent ( descriptor. digest. trimmingDigestPrefix) )
143
141
await progress ? ( [
@@ -160,7 +158,7 @@ extension ImageStore {
160
158
] )
161
159
}
162
160
163
- private func fetchBlob( _ descriptor: Descriptor ) async throws {
161
+ private func fetchBlob( _ descriptor: OCIDescriptor ) async throws {
164
162
let id = UUID ( ) . uuidString
165
163
let fm = FileManager . default
166
164
let tempFile = ingestDir. appendingPathComponent ( id)
@@ -179,7 +177,7 @@ extension ImageStore {
179
177
}
180
178
181
179
@discardableResult
182
- private func fetchData( _ descriptor: Descriptor ) async throws -> Data {
180
+ private func fetchData( _ descriptor: OCIDescriptor ) async throws -> Data {
183
181
let data = try await client. fetchData ( name: name, descriptor: descriptor)
184
182
let writer = try ContentWriter ( for: ingestDir)
185
183
let result = try writer. write ( data)
@@ -195,11 +193,11 @@ extension ImageStore {
195
193
return data
196
194
}
197
195
198
- private func createIndex( for root: Descriptor ) async throws -> Index {
196
+ private func createIndex( for root: OCIDescriptor ) async throws -> OCIIndex {
199
197
switch root. mediaType {
200
- case MediaTypes . index, MediaTypes . dockerManifestList:
198
+ case OCIMediaTypes . index, OCIMediaTypes . dockerManifestList:
201
199
return try await self . getManifestContent ( descriptor: root)
202
- case MediaTypes . imageManifest, MediaTypes . dockerManifest:
200
+ case OCIMediaTypes . imageManifest, OCIMediaTypes . dockerManifest:
203
201
let supportedPlatforms = try await getSupportedPlatforms ( for: root)
204
202
guard supportedPlatforms. count == 1 else {
205
203
throw ContainerizationError (
@@ -211,7 +209,7 @@ extension ImageStore {
211
209
let platform = supportedPlatforms. first!
212
210
var root = root
213
211
root. platform = platform
214
- let index = ContainerizationOCI . Index (
212
+ let index = OCIIndex (
215
213
schemaVersion: 2 , manifests: [ root] ,
216
214
annotations: [
217
215
// indicate that this is a synthesized index which is not directly user facing
@@ -223,8 +221,8 @@ extension ImageStore {
223
221
}
224
222
}
225
223
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 ] = [ ]
228
226
var toProcess = [ root]
229
227
while !toProcess. isEmpty {
230
228
let children = try await self . walk ( toProcess)
@@ -234,9 +232,9 @@ extension ImageStore {
234
232
continue
235
233
}
236
234
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 (
240
238
arch: config. architecture, os: config. os, osFeatures: config. osFeatures, variant: config. variant
241
239
)
242
240
supportedPlatforms. append ( p)
0 commit comments