-
Notifications
You must be signed in to change notification settings - Fork 583
Add unpack strategy to SnapshotStore #274
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
Merged
Merged
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
|
|
@@ -21,21 +21,41 @@ import ContainerizationExtras | |
| import ContainerizationOCI | ||
| import ContainerizationOS | ||
| import Foundation | ||
| import Logging | ||
| import TerminalProgress | ||
|
|
||
| public actor SnapshotStore { | ||
| private static let snapshotFileName = "snapshot" | ||
| private static let snapshotInfoFileName = "snapshot-info" | ||
| private static let ingestDirName = "ingest" | ||
|
|
||
| /// Return the Unpacker to use for a given image. | ||
| /// If the given platform for the image cannot be unpacked return `nil`. | ||
| public typealias UnpackStrategy = @Sendable (Containerization.Image, Platform) async throws -> Unpacker? | ||
|
|
||
| public static let defaultUnpackStrategy: UnpackStrategy = { image, platform in | ||
| guard platform.os == "linux" else { | ||
| return nil | ||
| } | ||
| var minBlockSize = 512.gib() | ||
| if image.reference == ClientDefaults.get(key: .defaultInitImage) { | ||
| minBlockSize = 512.mib() | ||
|
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. Let's see if we can move this to a UserDefault in a followup so that end users can customize this size. |
||
| } | ||
| return EXT4Unpacker(blockSizeInBytes: minBlockSize) | ||
| } | ||
|
|
||
| let path: URL | ||
| let fm = FileManager.default | ||
| let ingestDir: URL | ||
| let unpackStrategy: UnpackStrategy | ||
| let log: Logger? | ||
|
|
||
| public init(path: URL) throws { | ||
| public init(path: URL, unpackStrategy: @escaping UnpackStrategy, log: Logger?) throws { | ||
| let root = path.appendingPathComponent("snapshots") | ||
| self.path = root | ||
| self.ingestDir = self.path.appendingPathComponent(Self.ingestDirName) | ||
| self.unpackStrategy = unpackStrategy | ||
| self.log = log | ||
| try self.fm.createDirectory(at: root, withIntermediateDirectories: true) | ||
| try self.fm.createDirectory(at: self.ingestDir, withIntermediateDirectories: true) | ||
| } | ||
|
|
@@ -62,7 +82,8 @@ public actor SnapshotStore { | |
| guard let platform = desc.platform else { | ||
| throw ContainerizationError(.internalError, message: "Missing platform for descriptor \(desc.digest)") | ||
| } | ||
| guard Self.shouldUnpackPlatform(platform) else { | ||
| guard let unpacker = try await self.unpackStrategy(image, platform) else { | ||
| self.log?.warning("Skipping unpack for \(image.reference) for platform \(platform.description). No unpacker configured.") | ||
| continue | ||
| } | ||
| let currentSubTask = await taskManager.startTask() | ||
|
|
@@ -79,7 +100,8 @@ public actor SnapshotStore { | |
| let tempSnapshotPath = tempDir.appendingPathComponent(Self.snapshotFileName, isDirectory: false) | ||
| let infoPath = tempDir.appendingPathComponent(Self.snapshotInfoFileName, isDirectory: false) | ||
| do { | ||
| let mount = try await image.unpack(for: platform, at: tempSnapshotPath, progress: ContainerizationProgressAdapter.handler(from: taskUpdateProgress)) | ||
| let progress = ContainerizationProgressAdapter.handler(from: taskUpdateProgress) | ||
| let mount = try await unpacker.unpack(image, for: platform, at: tempSnapshotPath, progress: progress) | ||
| let fs = Filesystem.block( | ||
| format: mount.type, | ||
| source: self.snapshotPath(desc).absolutePath(), | ||
|
|
@@ -186,13 +208,6 @@ public actor SnapshotStore { | |
| try self.fm.createDirectory(at: uniqueDirectoryURL, withIntermediateDirectories: true, attributes: nil) | ||
| return uniqueDirectoryURL | ||
| } | ||
|
|
||
| private static func shouldUnpackPlatform(_ platform: Platform) -> Bool { | ||
| guard platform.os == "linux" else { | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| extension FileManager { | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Is this a disk/filesystem size, or a block size? Is the
blockSizeInBytesparameter to EXT4Unpacker a bit misleading?