Skip to content

Conversation

saehejkang
Copy link

@saehejkang saehejkang commented Oct 7, 2025

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Closes #559

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

Example Commands with Outputs

container image save
Pathname for the saved image: test-path/test.yaml
⠦ Saving image(s) [3s]
container image load
Pathname to the image tar archive:  test-path/test.yaml
Files does not exist

@saehejkang saehejkang force-pushed the image-save-load-support-stdin-stdout branch from 0ac3b6b to 3029055 Compare October 7, 2025 06:36
@saehejkang saehejkang force-pushed the image-save-load-support-stdin-stdout branch from 3029055 to b0de0e0 Compare October 7, 2025 06:37
}
}

/// `ImageCommand` errors.
Copy link
Contributor

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?
Copy link
Contributor

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 = ""
Copy link
Contributor

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

Copy link
Author

@saehejkang saehejkang Oct 9, 2025

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?
Copy link
Contributor

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 {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request]: image save and image load should support stdin.

2 participants