Repository navigation
Centralize GraphQL server in the Engine Runner - #5415
Conversation
|
Update on this: I realized that for Zenith I needed to flesh out the session proxying aspect of this earlier than I thought. I was under the impression buildkit did something that it apparently doesn't (the session ID param provided to the llb bridge solve is ignored when you provide an llb definition), so I wasn't able to save this chunk of work for later. This has gone well but resulted in some annoying import loops in our code, so I've been in depths of refactoring hell the last two days. It's actually starting to look nice and can see light at the end of the tunnel, but has delayed things a bit. |
cbf0b90 to
2c6b27d
Compare
|
Okay, got this branch to a point where I can consistently pass all the existing project tests, which are crucial since they involve passing local dirs back and forth between caller's host and nested execs. Now gonna pivot back once again to rebasing zenith on this branch as is so I can unblock our further efforts there. After that, will return here and finish the remaining missing features (secrets, sockets, auth, and non-local exports are the main ones) and do cleanup. |
This is causing container hostnames to change on every run, causing caches to bust. We tried changing Container.WithExec to only set a hostname if the container exposes ports, but that breaks two use cases: 1. Calling WithExec before WithExposedPort. 1. Using a container as a service without explicitly exposed ports. We could stomach temporarily breaking the latter case, but the former case is probably pretty common, since that's what our docs show. The impact of this change on the other hand should be pretty minor, only breaking the unannounced `dagger do` command, which is already being completely rearchitected such that we can probably approach the intended fix here in a different manner. (dagger#5415) Signed-off-by: Alex Suraci <[email protected]>
|
Another general update, getting very close now, all the major features have been re-added, with just a few scattered test failures to make fixes for left. After that the plan is:
I want to reach at least step 6 by this Friday, with a stretch goal of 7, but worst case 7 may not happen until early next week. |
511f75c to
e349836
Compare
|
Another update, the final few test failures/flakes have been real doozies to debug, but squashed a lot of them, including a bunch related to services that were fixed by @vito backporting bits and pieces of services v2 to here (thank you again!). The final remaining known failure is a flake (1/2 runs in CI, super rare locally) where it seems that random service container is somehow becoming associated w/ unrelated jobs and never exiting, which causes the jobs to not be able to exit either and just stall. Pretty hard to repro locally, and very hard to debug in CI, so taking a while but have a few workarounds in mind to try if we end up not fully root causing today. EDIT: I was completely misinterpreting the stack traces, the problems were actually that some nested containers couldn't close their connections due to some circular dependencies between trying to close their connection and us enforcing that connections can't close until everything in the buildkit job has exited. |
|
Tests just passed 5 times in a row after a few more fixes to various connection lifecycle management issues 🎉 So gonna call that good (🤞) and move onto some renaming and docs for everything |
d3f285e to
6b8896a
Compare
|
|
||
| secretFileContent, err := os.ReadFile(absPath) | ||
| func (s *hostSchema) setSecretFile(ctx *core.Context, _ any, args setSecretFileArgs) (*core.Secret, error) { | ||
| secretFileContent, err := s.bk.ReadCallerHostFile(ctx, args.Path) |
There was a problem hiding this comment.
@grouville @helderco Just FYI was able to re-integrate support for this API. Ended being able to add this ReadCallerHostFile util that lets the engine server read files from the client caller directly into memory, so preserves all the same security properties as before.
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
This was just an experiment with `dagger do` which was nice while it lasted, but it currently can't work due to catch-22 dependency issues which will only be fixed w/ full project/environment support. So just removing it for now. Signed-off-by: Erik Sipsma <[email protected]>
currently these are just computed by JSON encoding the values, which is pretty wack, and lets any little thing lead to a cache bust. we put all that work into stableDigest, so let's use it here too! Signed-off-by: Alex Suraci <[email protected]>
Along the way, change the import tests to use an image built with `apko` so we're not triple-testing Export and Host APIs. I was getting different image digests on every run before; by using the result of a cached container command, they're stable across test runs, allowing me to buildctl prune out-of-band. In the future it'd be nice if we had a prune API we could use in tests. Signed-off-by: Alex Suraci <[email protected]>
I truly don't think any of these cases matter. It's arguably strange before that Hostname wasn't affected by certain config changes. And no one should be using services from Dockerfiles. Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
c5fe3e4 to
5c7aa4d
Compare
|
As far as I can tell the sdks doesn't really have to change after this update? We don't have an internal graphql server, as we rely entirely on download and starting the clis, which is what we communicate with. I am not super familiar with the entrypoints and environments, so I can't speak on that front. That is if I haven't missed something, if we instead could rely on always being started with Anyways, just wanted to give my 2 cents. Edit: missed that you'd just removed dagger/sdk-rust :) |
@kjuulh oh yeah sorry, I just had to regenerate the SDK to pick up a new API but apparently that automatically requests a review from Rust SDK team, nothing to review :-) |
Signed-off-by: Erik Sipsma <[email protected]>
5c7aa4d to
30bc3b8
Compare
The engine sent a host import's include, exclude and follow-path
patterns twice: inside the single encoded options value, and again as
one gRPC header value per pattern. Since Go 1.27, an HTTP/2 server
accepts at most 500 header values per request by default, and when a
request over that limit spans several frames it closes the whole
connection. The CLI serves the session's attachables over that
connection, so reading a host directory with more than about 500
patterns ended the session ("http2: server connection error ...
PROTOCOL_ERROR", then "failed to sync").
Every CLI since #5415 reads the encoded value first, so the per-pattern
copies are dropped. Receiving them still works, for requests that come
straight from BuildKit.
Signed-off-by: Erik Sipsma <[email protected]>
The engine sent a host import's include, exclude and follow-path
patterns twice: inside the single encoded options value, and again as
one gRPC header value per pattern. Since Go 1.27, an HTTP/2 server
accepts at most 500 header values per request by default, and when a
request over that limit spans several frames it closes the whole
connection. The CLI serves the session's attachables over that
connection, so reading a host directory with more than about 500
patterns ended the session ("http2: server connection error ...
PROTOCOL_ERROR", then "failed to sync").
Every CLI since #5415 reads the encoded value first, so the per-pattern
copies are dropped. Receiving them still works, for requests that come
straight from BuildKit.
Signed-off-by: Erik Sipsma <[email protected]>
The engine sent a host import's include, exclude and follow-path
patterns twice: inside the single encoded options value, and again as
one gRPC header value per pattern. Since Go 1.27, an HTTP/2 server
accepts at most 500 header values per request by default, and when a
request over that limit spans several frames it closes the whole
connection. The CLI serves the session's attachables over that
connection, so reading a host directory with more than about 500
patterns ended the session ("http2: server connection error ...
PROTOCOL_ERROR", then "failed to sync").
Every CLI since #5415 reads the encoded value first, so the per-pattern
copies are dropped. Receiving them still works, for requests that come
straight from BuildKit.
Signed-off-by: Erik Sipsma <[email protected]>
The engine sent a host import's include, exclude and follow-path
patterns twice: inside the single encoded options value, and again as
one gRPC header value per pattern. Since Go 1.27, an HTTP/2 server
accepts at most 500 header values per request by default, and when a
request over that limit spans several frames it closes the whole
connection. The CLI serves the session's attachables over that
connection, so reading a host directory with more than about 500
patterns ended the session ("http2: server connection error ...
PROTOCOL_ERROR", then "failed to sync").
Every CLI since #5415 reads the encoded value first, so the per-pattern
copies are dropped. Receiving them still works, for requests that come
straight from BuildKit.
Signed-off-by: Erik Sipsma <[email protected]>
The engine sent a host import's include, exclude and follow-path
patterns twice: inside the single encoded options value, and again as
one gRPC header value per pattern. Since Go 1.27, an HTTP/2 server
accepts at most 500 header values per request by default, and when a
request over that limit spans several frames it closes the whole
connection. The CLI serves the session's attachables over that
connection, so reading a host directory with more than about 500
patterns ended the session ("http2: server connection error ...
PROTOCOL_ERROR", then "failed to sync").
Every CLI since #5415 reads the encoded value first, so the per-pattern
copies are dropped. Receiving them still works, for requests that come
straight from BuildKit.
Signed-off-by: Erik Sipsma <[email protected]>
Previously, every Dagger client had its own graphql server and buildkit session, all running in the CLI.
This rearchitects the server to no longer be in the CLI but instead be in the engine runner (i.e. the container/pod/etc. running the buildkitd wrapper).
Docs
Motivation
The most immediate motivation is to make Zenith possible. Zenith environments are nested dagger clients, which means that they are clients running in an exec that connect back to the engine API to make more Dagger API calls.
The big wrench our old architecture threw into this was that dagger clients and environments often need to selectively share certain state, including local directories, secrets, and dynamically loaded graphql schemas/resolvers. In the previous model, every client, including nested clients, all got their own fully isolated graphql server and buildkit session/job. This has some good security properties but is unnecessarily restricting:
The new architecture fixes this by creating a centralized Dagger Server in the runner for every client and its environments (i.e. nested clients). Rather than trying to implement hacks for coordinating distributed graphql servers + sessions + buildkit jobs, we coordinate everything in one central server, which makes all the previous problems much easier, and at times totally trivial.
To be clear, there is still a single engine runner (the container process) but there is not one single Dagger Server handling all clients now; when a client connects to the runner it starts its own Dagger Server instance in the runner. That Dagger Server instance is only shared with nested clients created by that client.
Additionally, the idea is not that all resources managed by a single Dagger Server instance are inherently shared, it's that they can be selectively shared, with enforcement on who can access what to be enforced by the server. For example, a
dagger dohost client could choose to pass one of its local dirs to an environment nested client, but a nested client can't just load arbitrary dirs from the host client.More Benefits
Zenith is why we prioritized this immediately, but there's a surprisingly long list of other benefits we are picking up as a side effect of this change. This is thanks to the fact that:
In this PR already
A few non-Zenith benefits were picked up inherently as part of the change:
New Possibilities
There's a lot of things outside the scope of this PR that will now be possible:
ContainerID,DirectoryID, etc.) with short hashes, thanks to the fact that we can now persist id<->hash mappings in a safe way (alongside the existing persisted caches in the engine container)Caveats (and paths to improving)
The biggest downside to this change is that it means adding a new API to our schema will require users to upgrade both their SDKs and their long-running engine, whereas previously it usually only meant they had to upgrade the SDK and the CLI, which is often easier.
However, by taking this 1 step back we are setting ourselves up to take several steps forward by making the change described here.
This PR in combination with that change should result in SDKs that can always start an engine compatible with their version without needing to rely on the "CLI magic auto-download" feature in SDKs. The only source of backwards-incompatible changes would be from "internal protocol" changes to how SDKs, the CLI and the engine talk to each other, which are much rarer and usually easier to avoid entirely.
Architecture
Before
After
(minor) Breaking Changes
This change is almost entirely internal-only and backwards compatible, with minor exceptions:
container.Build, but that's no longer possible. We were sort of surprised this ever worked at all (to the extent it did previously) and was a highly obscure use case anyways.