feat: add proxy utility (#288)

Signed-off-by: Harry Li <harrymingh@gmail.com>
Co-authored-by: Dmitry Kovba <dkovba@apple.com>
This commit is contained in:
Harry Li
2025-09-12 11:23:41 -07:00
committed by GitHub
co-authored by Dmitry Kovba
parent 31bfef4a8e
commit 5fbae0e590
10 changed files with 182 additions and 16 deletions
@@ -24,14 +24,14 @@ import Crypto
import Foundation
extension ImageStore {
public struct ExportOperation: Sendable {
internal struct ExportOperation {
let name: String
let tag: String
let contentStore: ContentStore
let client: ContentClient
let progress: ProgressHandler?
public init(name: String, tag: String, contentStore: ContentStore, client: ContentClient, progress: ProgressHandler? = nil) {
init(name: String, tag: String, contentStore: ContentStore, client: ContentClient, progress: ProgressHandler? = nil) {
self.contentStore = contentStore
self.client = client
self.progress = progress
@@ -40,7 +40,7 @@ extension ImageStore {
}
@discardableResult
public func export(index: Descriptor, platforms: (Platform) -> Bool) async throws -> Descriptor {
internal func export(index: Descriptor, platforms: (Platform) -> Bool) async throws -> Descriptor {
var pushQueue: [[Descriptor]] = []
var current: [Descriptor] = [index]
while !current.isEmpty {
@@ -22,7 +22,7 @@ import ContainerizationOCI
import Foundation
extension ImageStore {
public struct ImportOperation: Sendable {
internal struct ImportOperation {
static let decoder = JSONDecoder()
let client: ContentClient
@@ -31,7 +31,7 @@ extension ImageStore {
let progress: ProgressHandler?
let name: String
public init(name: String, contentStore: ContentStore, client: ContentClient, ingestDir: URL, progress: ProgressHandler? = nil) {
init(name: String, contentStore: ContentStore, client: ContentClient, ingestDir: URL, progress: ProgressHandler? = nil) {
self.client = client
self.ingestDir = ingestDir
self.contentStore = contentStore
@@ -40,7 +40,7 @@ extension ImageStore {
}
/// 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.
public func `import`(root: Descriptor, matcher: (ContainerizationOCI.Platform) -> Bool) async throws -> Descriptor {
internal func `import`(root: Descriptor, matcher: (ContainerizationOCI.Platform) -> Bool) async throws -> Descriptor {
var toProcess = [root]
while !toProcess.isEmpty {
// Count the total number of blobs and their size
@@ -123,14 +123,14 @@ extension ImageStore {
for _ in 0..<8 {
if let desc = iterator.next() {
group.addTask {
try await self.fetch(desc)
try await fetch(desc)
}
}
}
for try await _ in group {
if let desc = iterator.next() {
group.addTask {
try await self.fetch(desc)
try await fetch(desc)
}
}
}