Skip to content

[wip] support remote client sessions - #3671

Closed
vito wants to merge 34 commits into
dagger:mainfrom
vito:client-session
Closed

vito wants to merge 34 commits into
dagger:mainfrom
vito:client-session

Conversation

@vito

@vito vito commented Nov 4, 2022 •

Copy link
Copy Markdown
Contributor

This is nowhere near ready but I wanted to put a PR up early.

  • Adds an endpoint for initializing a client session.
  • dagger.Connect now initializes a session and keeps it open for the duration of the client.
  • The client session endpoint hijacks the connection and uses it to serve gRPC services from the client.
  • Subsequent queries are associated to the session via /query?session=<id>.
  • Schema endpoints look up the session's gateway by ID (lazily instantiated for now; implementation detail).
  • Gateways are initialized with a session.Attachable that proxies back to the client's session.
  • Removes the global gateway session; everything uses the client session instead.

The end result is that it's possible to run the Engine in a Docker container and sync files from the client's host. No API changes necessary. 🎉

To try it out:

docker buildx build . -t cloak
docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 cloak dev
go run ./cmd/remotesync

TODO:

  • Figure out how to integrate Use Empty rather than Any for message processing mwitkow/grpc-proxy#62 to support the auth service
  • Decouple SDK from github.com/moby/buildkit dependency
    • this probably means vendoring + cutting down github.com/moby/session/* implementations, which we've already almost done for filesync
    • alternatively we can just put this all in a binary and have the Go SDK use the binary in the same way the other SDKs would
  • Figure out what to do with the secret attachable
  • Support forwarding Docker auth
  • Support forwarding export calls
  • Try more things
  • Remove cmd/remotesync (it's just a testing crutch)
  • Preserve attribution for code yoinked from Buildkit
  • Make sure --disable-host-rw is still respected
  • Fix Yarn example (JS SDK needs to implement session)

@aluzzardi

Copy link
Copy Markdown
Contributor

🎉 🎉 🎉

wow, this is incredibly amazing. I thought we were months away from having this.

I only skimmed through the code, need to spend more time on this, but ... so many questions :)

alternatively we can just put this all in a binary and have the Go SDK use the binary in the same way the other SDKs would

Yep, good point. I'm wondering what the binary size would be. @sipsma this might re-open up the topic of how we distribute the binaries long term?

  • We might not have docker locally (since the engine can now be wherever)
  • The binary MIGHT be small enough to have an acceptable size to be packaged in the SDK directly

@vito vito mentioned this pull request Nov 4, 2022
@vito

vito commented Nov 4, 2022

Copy link
Copy Markdown
Contributor Author

I only skimmed through the code, need to spend more time on this, but ... so many questions :)

A lot of it is yoinked from Buildkit and stripped for parts. The hard part was figuring out how exactly to glue it together. 😅 Lots of confusion around whether something is client-side or server-side, and lots of things that looked promising but were dead ends.

Some key parts:

Need to preserve proper attribution for all this.

@vito

vito commented Nov 4, 2022

Copy link
Copy Markdown
Contributor Author

So, we're not totally out of the woods yet. This lets us get files in to Dagger but it doesn't help us get them out.

As @sipsma pointed out in #3421 (comment), exporting currently requires establishing a new gateway session. There's an upstream issue to add exporting to the gateway interface: moby/buildkit#1914.

Unless I'm missing something, this seems like a decent chunk of work to implement. Currently exporting works by registering a single FileSend (vs FileSync) gRPC service which is pre-configured with the destination for the data it receives. To support exporting via the gateway API we'd probably need a way to dynamically configure destinations per-export instead, and it'd need to support mixed export types (OCI vs Tar vs Local).

The sad thing is even with that implemented we wouldn't really get remote exporting "for free" because we currently have to deal both OCI and Local export types in engine, and I don't think we'd want to bubble that complexity up to each SDK. I think we might just want to come up with our own gRPC service interface for exporting to paths. The engine can then internally do whichever export type is appropriate and then translate it to a direct gRPC client call using the session's underlying *grpc.ClientConn.

The silver lining is that we could do this without actually being blocked on upstream changes by re-using the underlying *grpc.ClientConn across multiple gateway sessions. That way SDK implementations stays simple (just one client session). The disadvantage is that it won't fix underlying reproducibility issues, but it's nice to decouple these things, since we're already tracking that in #3613.

vito added 10 commits November 6, 2022 16:04
Signed-off-by: Alex Suraci <[email protected]>
not REALLY decoupled yet but cuts out some unnecessary plumbing

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
the SDK client now implements a service for receiving and optionally
unpacking tar streams to arbitrary locations.

the engine now exports using this service.

Signed-off-by: Alex Suraci <[email protected]>
vito added 6 commits November 7, 2022 01:24
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* per-session host fixes SDK workdir example
* update SDK workdir example to be self-contained
* removes Workdir/ConfigPath from engine config, no longer needed
* removes more dead code
* fixes receiver naming lints
* silences http.ClientConn lint

Signed-off-by: Alex Suraci <[email protected]>
and remove bkClient/solveOpts/solveCh from base schema now that nothing
uses it

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented Nov 7, 2022 •

Copy link
Copy Markdown
Contributor Author

Updates:

  • Exporting files to the host has been implemented. The engine no longer uses ExporterLocal, instead it uses ExporterTar and sends a tar stream to the SDK which unpacks it as it streams.
  • Exporting a container sends a tar stream with unpack: false so it gets written to a single .tar file client-side as before.
  • The global *core.Host instance has been removed. Instead host APIs use a dynamic *core.Host from the client session. This paves the way for supporting host { envVariable } etc.
  • The engine is no longer configured with Workdir/ConfigPath/NoExtensions. Instead the SDK client installs extensions as part of setup when they are configured. This eliminates the sanity checks from the Unix/TCP connectors that had to be disabled in support dagger in dagger #3674 and moves the extension installation logic to the client.
  • Go SDK tests now are passing with Dagger-in-Dagger, including the Workdir test which was problematic before.
  • All core integration tests are passing.
  • All but one extension test is passing. The remaining failure is TestExtensionYarn which needs the NodeJS SDK to be able to establish sessions. Fixing this will either mean a native NodeJS implementation of the required gRPC services (hard) or shelling out to a helper binary (easier).

vito added 4 commits November 7, 2022 19:39
Signed-off-by: Alex Suraci <[email protected]>
replaced by http

Signed-off-by: Alex Suraci <[email protected]>
+ update mage setup

Signed-off-by: Alex Suraci <[email protected]>
vito added 4 commits November 10, 2022 12:44
otherwise Dockerfile was hitting skipped errors

Signed-off-by: Alex Suraci <[email protected]>
* track bootstrap SDK version in separate Go module
* move mage code under magefiles/ so it can be optionally run with its
  own go.mod/go.sum without clashing with the root go.mod
* run mage boot:run TARGET to run a target using bootstrap SDK version
* run mage boot:dev engine:test to run engine:test target against
  dev engine built using bootstrap SDK version

Signed-off-by: Alex Suraci <[email protected]>
@dolanor

dolanor commented Nov 10, 2022

Copy link
Copy Markdown
Contributor

Go SDK tests now are passing with Dagger-in-Dagger, including the Workdir test which was problematic before.
This is amazing!

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@vito

vito commented Nov 28, 2022

Copy link
Copy Markdown
Contributor Author

Closing now that we know that we can, but have decided that we shouldn't (for now). Most of the time was spent figuring out how to do this; now that we know how it'll be easier to just redo it on main when we want to rather than try to rebase or maintain a branch.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants