-
Notifications
You must be signed in to change notification settings - Fork 583
CLI: Handle stdin stream if it's a regular file #322
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
Conversation
|
@jglogan This hopefully should get piping a file in working, will test tomorrow. We'll need both this and bump of containerization that has the closing stdin work however. |
|
Can you check to see if terminal I/O works for you in this branch with: container run -it --rm alpine:latest sh |
|
@jglogan It doesn't, it's why it's in draft right now. |
7afeca1 to
1d7e6c3
Compare
|
@jglogan tty fixed, and I can confirm we close the relay on eof for regular files. What's the avenue for testing against containerization |
| } | ||
| } | ||
|
|
||
| struct OSFile: Sendable { |
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.
Note: I've just copied a smaller portion of this same type we have for vminitd here. I'll see if it makes sense to make that public over in CZ, and we can just use directly.
What's missing from the build documentation is that you need to set up the default init image as make all install
defaults write com.apple.container.defaults image.init vminit:latest
container system stop
container system start
container run -d --rm --name test python:slim python3 -m http.server --bind 0.0.0.0 8000
echo hello | container exec -t exec -i test cp /dev/stdin /tmp/hello.txtFWIW I'm seeing that this seems to suffice for the diff --git a/Sources/CLI/RunCommand.swift b/Sources/CLI/RunCommand.swift
index 9a7f0d7..1d3f0cc 100644
--- a/Sources/CLI/RunCommand.swift
+++ b/Sources/CLI/RunCommand.swift
@@ -218,6 +218,7 @@ struct ProcessIO {
let data = handle.availableData
if data.isEmpty {
pin.readabilityHandler = nil
+ try? stdin.fileHandleForWriting.close()
return
}
try! stdin.fileHandleForWriting.write(contentsOf: data)That we fetch the init filesystem in the client at https://github.com/apple/container/blob/main/Sources/ContainerClient/Utility.swift#L113, and then again when creating the container in the API server https://github.com/apple/container/blob/main/Sources/APIServer/Containers/ContainersService.swift#L165 is curious. |
jglogan
left a comment
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.
mainly readability nits
readabilityHandler is a bit crummy if it's a regular file. This just writes our own loop and exits and shuts down the write end of the pipe if we get to the end of the file.
ecdb44d to
a0518e6
Compare
readabilityHandler is a bit crummy if it's a regular file. This just writes our own loop and exits and shuts down the write end of the pipe if we get to the end of the file.