-
Notifications
You must be signed in to change notification settings - Fork 480
[image-save-load]: support stdin for filepath #734
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
base: main
Are you sure you want to change the base?
[image-save-load]: support stdin for filepath #734
Conversation
0ac3b6b
to
3029055
Compare
3029055
to
b0de0e0
Compare
} | ||
} | ||
|
||
/// `ImageCommand` errors. |
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.
For now, just use ContainerizationError
instead of creating new error types. We do have a tech debt issue #268 for improving our error handling.
URL(fileURLWithPath: str, relativeTo: .currentDirectory()).absoluteURL.path(percentEncoded: false) | ||
}) | ||
var input: String | ||
var input: String? |
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.
This is fine but what you'll want to do is change L35 to something like this so input = nil
is transformed properly:
str.map { URL(fileURLWithPath: $0, relativeTo: .currentDirectory()).absoluteURL.path(percentEncoded: false) }
public func run() async throws { | ||
guard FileManager.default.fileExists(atPath: input) else { | ||
print("File does not exist \(input)") | ||
var filePath = "" |
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.
This isn't quite what #559 is asking for. If input == nil
we don't want to prompt the user for a pathname. What image load
needs to do in this case is:
- Create a temporary file, using
defer {}
to delete the file once we're done using it. - Read binary data from the standard input, writing it to the temp file.
- Use the path to the temporary file as the path to load.
This allows us to do things like moving images between Docker and container
without having to mess with intermediate files explicitly:
docker save foo:latest bar:latest | container image load
container save baz:latest qux:latest | docker image load
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.
Ahhh, I was unsure why the issue was talking about stdout
.
How is the binary data coming from the standard input? Are we prompting anything from the user (would it be the path to the temporary file or the path from the file to read the binary data from)?
URL(fileURLWithPath: str, relativeTo: .currentDirectory()).absoluteURL.path(percentEncoded: false) | ||
}) | ||
var output: String | ||
var output: String? |
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.
Same as above, map String?
to get the absolute path.
|
||
public func run() async throws { | ||
var filePath = "" | ||
if output == nil { |
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.
Here if output is nil we create a temporary file, defer the delete, do ClientImage.save to that file, and then copy the binary data in the file to the standard output
Type of Change
Motivation and Context
Closes #559
Testing
Example Commands with Outputs