You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Investigate using filesync protocol/service with remote engine #3629
Now that we've hoisted the filesync implementation from Buildkit into our codebase, can we modify it to support dynamically syncing from remote filesync protocol streams?
The idea would be to give Buildkit a filesync session.Attachable for syncing local dirs into the graph, but have it accept a stream from a remote client rather than looking at directories local to the engine.
If that works, can we also implement the inverse for exporting to the client?
I mentioned at the outset doing this over WebSockets, but it doesn't seem like we even need to do this over HTTP; it could maybe just be a separate gRPC port.
The key thing is that it needs to be bidirectional. File syncing works by sending a bunch of file stats with IDs, and then the other side requests the IDs that need to be synced over.
WebSockets should support bidirectional, just raising this question to figure out the requirements and limitations of our options. For example if we wanted to do gRPC over HTTP a common option appears to be grpcweb, but it mentions "Bi-di and client streams are unsupported due to limitations in browser protocol support." - which sounds not good.
The main appeal of websockets is that we want to use the for services anyways and it's a good long-term goal to minimize the number of different transports/protocols we include in each of our SDKs. But in the shorter term, if grpc ends up being easier for whatever reason then I think it's worth considering.
If that works, can we also implement the inverse for exporting to the client?
Took a quick perusal of the fsutil code and yeah, it definitely seems like that code specifically would be much more difficult to port to SDKs. The sending side is not nearly as bad as I would have thought.
One thing to consider is that it might be okay if for a first iteration local exports were not as efficient in non-Go SDKs. I.e. maybe it would be easier to implement that part as just "send the tarball to the client, have it unpack it" to start out for nodejs/python. Then we can optimize in future iterations.
@sipsma Makes sense to try to stick to one protocol + port!
Just thinking out loud, this is still very open-ended:
There are quite a few scenarios where the engine might request things from the client dynamically:
syncing llb.Local sources (filesync - this issue)
secret env vars (Host().EnvVariable("FOO").Secret())
(future) arbitrary secrets via pluggable secret provider passed to dagger.Connect
registry auth creds (e.g. for pushing to private registry/repository)
The last point around auth is particularly sneaky - I had forgotten about it this whole time and it feels like a blocker for remote engine too. I don't think we can just do filesync. 😕
With all these server->client paths, gRPC starts to feel a bit more natural since the client can just register services on a single persistent connection just like Buildkit's client does with session.Attachable.
It's also tempting to use gRPC to run queries so we can stream progress for the query back to the client. But that's a whole other topic. 😄
Thankfully it doesn't really matter too much whether we go full gRPC or stick with HTTP since we can always do gRPC over HTTP/2 with Upgrade: h2c (apparently that means HTTP/2 over TCP, as opposed to h2 for HTTP/2 over TLS). I think that grpcweb thing I mentioned previously was a red herring.
I'm still chewing on ideas around simpler WebSockets endpoints, but I haven't found a scheme that maintains simplicity in the SDK yet. For example, one option is to send queries with host paths replaced by filesync UUIDs. The client establishes a WebSocket filesync connection for each UUID primed to send along the fsutil stream for its corresponding path, then it sends the query request. The engine's session.Attachable then streams the data just-in-time from the pre-established connection (locating the connection via some in-memory map keyed by UUID). But this implies a lot of extra logic in the SDK to translate host paths to UUIDs and establish those connections for each query. Granted there may be other ways to do this.
I found that it seems possible to forward an entire Buildkit session over a connection: buildx seems to do that under the hood here. But I'm not sure I fully understand how this works yet, and one downside is that's quite a lot of behavior to lift over to the SDK. We might even want to use a helper binary for the Go SDK at that point to avoid depending directly on github.com/moby/buildkit especially because of its replace rule.
The next thing I'm going to explore is to have dagger.Connect establish a gRPC-over-HTTP/2 connection that provides gRPC services for performing filesync, auth, etc. - but without having a hard dependency on github.com/moby/buildkit. This seems like a decent middle ground since there'd still be hope that SDKs could implement these things natively with their own gRPC services.
Activity
vito commentedon Nov 1, 2022
I mentioned at the outset doing this over WebSockets, but it doesn't seem like we even need to do this over HTTP; it could maybe just be a separate gRPC port.
The key thing is that it needs to be bidirectional. File syncing works by sending a bunch of file stats with IDs, and then the other side requests the IDs that need to be synced over.
WebSockets should support bidirectional, just raising this question to figure out the requirements and limitations of our options. For example if we wanted to do gRPC over HTTP a common option appears to be
grpcweb, but it mentions "Bi-di and client streams are unsupported due to limitations in browser protocol support." - which sounds not good.sipsma commentedon Nov 1, 2022
The main appeal of websockets is that we want to use the for services anyways and it's a good long-term goal to minimize the number of different transports/protocols we include in each of our SDKs. But in the shorter term, if grpc ends up being easier for whatever reason then I think it's worth considering.
Took a quick perusal of the
fsutilcode and yeah, it definitely seems like that code specifically would be much more difficult to port to SDKs. The sending side is not nearly as bad as I would have thought.One thing to consider is that it might be okay if for a first iteration local exports were not as efficient in non-Go SDKs. I.e. maybe it would be easier to implement that part as just "send the tarball to the client, have it unpack it" to start out for nodejs/python. Then we can optimize in future iterations.
vito commentedon Nov 2, 2022
@sipsma Makes sense to try to stick to one protocol + port!
Just thinking out loud, this is still very open-ended:
There are quite a few scenarios where the engine might request things from the client dynamically:
llb.Localsources (filesync - this issue)Host().EnvVariable("FOO").Secret())dagger.ConnectThe last point around auth is particularly sneaky - I had forgotten about it this whole time and it feels like a blocker for remote engine too. I don't think we can just do filesync. 😕
With all these server->client paths, gRPC starts to feel a bit more natural since the client can just register services on a single persistent connection just like Buildkit's client does with
session.Attachable.It's also tempting to use gRPC to run queries so we can stream progress for the query back to the client. But that's a whole other topic. 😄
Thankfully it doesn't really matter too much whether we go full gRPC or stick with HTTP since we can always do gRPC over HTTP/2 with
Upgrade: h2c(apparently that means HTTP/2 over TCP, as opposed toh2for HTTP/2 over TLS). I think thatgrpcwebthing I mentioned previously was a red herring.I'm still chewing on ideas around simpler WebSockets endpoints, but I haven't found a scheme that maintains simplicity in the SDK yet. For example, one option is to send queries with host paths replaced by filesync UUIDs. The client establishes a WebSocket filesync connection for each UUID primed to send along the
fsutilstream for its corresponding path, then it sends the query request. The engine'ssession.Attachablethen streams the data just-in-time from the pre-established connection (locating the connection via some in-memory map keyed by UUID). But this implies a lot of extra logic in the SDK to translate host paths to UUIDs and establish those connections for each query. Granted there may be other ways to do this.I found that it seems possible to forward an entire Buildkit session over a connection:
buildxseems to do that under the hood here. But I'm not sure I fully understand how this works yet, and one downside is that's quite a lot of behavior to lift over to the SDK. We might even want to use a helper binary for the Go SDK at that point to avoid depending directly ongithub.com/moby/buildkitespecially because of itsreplacerule.The next thing I'm going to explore is to have
dagger.Connectestablish a gRPC-over-HTTP/2 connection that provides gRPC services for performing filesync, auth, etc. - but without having a hard dependency ongithub.com/moby/buildkit. This seems like a decent middle ground since there'd still be hope that SDKs could implement these things natively with their own gRPC services.vito commentedon Dec 6, 2022
I think this has run its course. Since I apparently never linked the PR, the latest on this was in #3671