Repository navigation
Add strict layout loading under a chosen name and a create overload for external rootfs #1024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
realrajaryan
wants to merge
1
commit into
apple:main
Choose a base branch
from
realrajaryan:strict-layout-load
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,30 @@ extension ImageStore { | |
| try client.createOCILayoutStructure(directory: out, manifests: saved) | ||
| } | ||
|
|
||
| /// Imports the one image in an OCI Image Layout directory and stores it under `reference`. | ||
| /// | ||
| /// Unlike ``load(from:progress:)``, this ignores the layout's names and takes every blob from the | ||
| /// layout, never from the content store, so an untrusted layout cannot replace another image or | ||
| /// use another image's layers. An image already stored under `reference` is replaced. | ||
| /// | ||
| /// - Parameters: | ||
| /// - directory: A URL to a directory on disk that follows the OCI Image Layout structure. | ||
| /// - reference: The name to store the image under. | ||
| /// - platform: The platform to import. Defaults to `nil`, which imports every platform in the layout. | ||
| /// - progress: An optional handler over which progress update events about the load operation can be received. | ||
| /// - Returns: The loaded image. | ||
| /// - Throws: A `ContainerizationError` with code `.invalidArgument` if the layout does not hold exactly one image. | ||
| public func load(from directory: URL, as reference: String, platform: Platform? = nil, progress: ProgressHandler? = nil) async throws -> Image { | ||
| let client = try LocalOCILayoutClient(root: directory) | ||
| let manifests = try client.loadIndexFromOCILayout(directory: directory).manifests | ||
| guard manifests.count == 1, let root = manifests.first else { | ||
| throw ContainerizationError(.invalidArgument, message: "OCI layout at \(directory.path) holds \(manifests.count) images, not 1") | ||
| } | ||
| return try await self.load( | ||
| [(root, reference)], from: client, matcher: createPlatformMatcher(for: platform), reusesStoredContent: false, progress: progress | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add |
||
| )[0] | ||
| } | ||
|
|
||
| /// Imports one or more images and their associated layers from an OCI Image Layout directory. | ||
| /// | ||
| /// - Parameters: | ||
|
|
@@ -74,22 +98,35 @@ extension ImageStore { | |
| public func load(from directory: URL, progress: ProgressHandler? = nil) async throws -> [Image] { | ||
| let client = try LocalOCILayoutClient(root: directory) | ||
| let index = try client.loadIndexFromOCILayout(directory: directory) | ||
| let matcher = createPlatformMatcher(for: nil) | ||
| let roots = index.manifests.map { ($0, client.getImageReferencefromDescriptor(descriptor: $0)) } | ||
| let images = try await self.load(roots, from: client, matcher: createPlatformMatcher(for: nil), reusesStoredContent: true, progress: progress) | ||
| guard images.count > 0 else { | ||
| throw ContainerizationError(.internalError, message: "failed to import image") | ||
| } | ||
| return images | ||
| } | ||
|
|
||
| /// Imports each root into one ingest session, then stores each image under its reference. | ||
| private func load( | ||
| _ roots: [(descriptor: Descriptor, reference: String)], | ||
| from client: LocalOCILayoutClient, | ||
| matcher: @Sendable (Platform) -> Bool, | ||
| reusesStoredContent: Bool, | ||
| progress: ProgressHandler? | ||
| ) async throws -> [Image] { | ||
| var loaded: [Image.Description] = [] | ||
| let (id, tempDir) = try await self.contentStore.newIngestSession() | ||
| do { | ||
| for descriptor in index.manifests { | ||
| let reference = client.getImageReferencefromDescriptor(descriptor: descriptor) | ||
| let ref = try Reference.parse(reference) | ||
| let name = ref.path | ||
| let operation = ImportOperation(name: name, contentStore: self.contentStore, client: client, ingestDir: tempDir, progress: progress) | ||
| let indexDesc = try await operation.import(root: descriptor, matcher: matcher) | ||
| loaded.append(Image.Description(reference: reference, descriptor: indexDesc)) | ||
| for root in roots { | ||
| let name = try Reference.parse(root.reference).path | ||
| let operation = ImportOperation( | ||
| name: name, contentStore: self.contentStore, client: client, ingestDir: tempDir, progress: progress, reusesStoredContent: reusesStoredContent) | ||
| let indexDesc = try await operation.import(root: root.descriptor, matcher: matcher) | ||
| loaded.append(Image.Description(reference: root.reference, descriptor: indexDesc)) | ||
| } | ||
|
|
||
| let loadedImages = loaded | ||
| let importedImages = try await self.lock.withLock { lock in | ||
| return try await self.lock.withLock { lock in | ||
| var images: [Image] = [] | ||
| try await self.contentStore.completeIngestSession(id) | ||
| for description in loadedImages { | ||
|
|
@@ -98,10 +135,6 @@ extension ImageStore { | |
| } | ||
| return images | ||
| } | ||
| guard importedImages.count > 0 else { | ||
| throw ContainerizationError(.internalError, message: "failed to import image") | ||
| } | ||
| return importedImages | ||
| } catch { | ||
| try? await self.contentStore.cancelIngestSession(id) | ||
| throw error | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this? Should we keep the old behavior and throw? Does this mess up the progress counter?