fussybeaver / bollard

Docker daemon API in Rust
Apache License 2.0
863 stars 131 forks source link

Windows + buildkit "unresolved import `tokio::net::UnixStream`" #442

Closed paul-hansen closed 1 month ago

paul-hansen commented 1 month ago

Building the current (6d4c130) main branch of bollard fails on Windows if the buildkit feature is enabled. (I'm using main due to https://github.com/fussybeaver/bollard/pull/441) It fails on this line: https://github.com/fussybeaver/bollard/blob/master/src/grpc/mod.rs#L58 Which was added in this commit: https://github.com/fussybeaver/bollard/commit/11d6d1507994c02c4d39d11aea4bb8465941f605#diff-bc7174f05d071178c46395d5c4368d0b48642366ae51d1d7fb38032190f36293R59

Steps to reproduce:

git clone https://github.com/fussybeaver/bollard.git
cd bollard
cargo build --features buildkit

Creates this error message:

   Compiling bollard v0.17.0 (C:\Users\Paul\Projects\Rust\bollard)
error[E0432]: unresolved import `tokio::net::UnixStream`
  --> src\grpc\mod.rs:58:5
   |
58 | use tokio::net::UnixStream;
   |     ^^^^^^^^^^^^^^^^^^^^^^ no `UnixStream` in `net`
   |
note: found an item that was configured out
  --> C:\Users\Paul\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.39.2\src\net\mod.rs:57:27
   |
57 |     pub use unix::stream::UnixStream;
   |                           ^^^^^^^^^^

For more information about this error, try `rustc --explain E0432`.
error: could not compile `bollard` (lib) due to 1 previous error
fussybeaver commented 1 month ago

Yes, you're right, Bollard doesn't support using buildkit features with windows currently. I recently discovered that moby's Buildkit itself has added experimental support for Windows, so in theory it could be possible - but I haven't found time to try it. In principal it should just be a matter of replacing a few networking and file i/o primitives, so if you're interested in this, I'd be happy to see/review/accept a PR.

paul-hansen commented 1 month ago

Hmm, I just checked and using buildkit on Windows did work with bollard 0.16. I just use buildkit for the heredoc support so I tested by building a container using and image that contained a heredoc script.

I recently discovered that moby's Buildkit itself has added experimental support for Windows, so in theory it could be possible

Note that Windows docker hosts using buildkit are not experimental, only Windows containers using buildkit are. buildkit is the default build engine for docker desktop according to: https://docs.docker.com/build/buildkit/#overview.

Maybe as a quick fix we could just feature or target gate the new ssh implementation so the other buildkit features can still be used on Windows? I'll do some poking around and see if I can wrap my head around what the UnixStream was used for and see if I can come up with a replacement on Windows though.

fussybeaver commented 1 month ago

Hmm, I just checked and using buildkit on Windows did work with bollard 0.16. I just use buildkit for the heredoc support so I tested by building a container using and image that contained a heredoc script.

I recently discovered that moby's Buildkit itself has added experimental support for Windows, so in theory it could be possible

Note that Windows docker hosts using buildkit are not experimental, only Windows containers using buildkit are. buildkit is the default build engine for docker desktop according to: https://docs.docker.com/build/buildkit/#overview.

Maybe as a quick fix we could just feature or target gate the new ssh implementation so the other buildkit features can still be used on Windows? I'll do some poking around and see if I can wrap my head around what the UnixStream was used for and see if I can come up with a replacement on Windows though.

Interesting... I wasn't aware that windows users were using the buildkit feature. I guess as you say the best bet is to just disable some functionality for now and make a patch release.

paul-hansen commented 1 month ago

I wasn't aware that windows users were using the buildkit feature

Yeah it's not a big deal, I could just switch to using separate files for scripts in my docker images and I wouldn't need buildkit. It was just convenient to have the docker image be all in one file.

I'm building a website for managing game servers. Sometimes my brother helps me with it (usually writing email templates or html etc.) and he uses Windows so I have a github action that builds my site for Windows to make sure he can still work with it. So I could even just add a feature to our app to enable buildkit, but would be nice if it wasn't needed. Thanks for this library btw, it's been a huge win for us!

Looks like on Windows ssh-agent uses a named pipe instead of a unix socket. I might be able to get a PR to make it work yet. This thread has some good intel: https://github.com/PowerShell/Win32-OpenSSH/issues/1136

fussybeaver commented 1 month ago

The equivalent golang buildkit file to port would be this one: https://github.com/moby/buildkit/blob/44ebf9071db49821538cd37c2687dd925c7c3661/session/sshforward/sshprovider/agentprovider_windows.go#L1 if that helps you