Skip to content

CLI: use engine.Start directly - #4119

Merged
sipsma merged 3 commits into
dagger:mainfrom
sipsma:cli-engine-start
Dec 7, 2022
Merged

sipsma merged 3 commits into
dagger:mainfrom
sipsma:cli-engine-start

Conversation

@sipsma

@sipsma sipsma commented Dec 7, 2022 •

Copy link
Copy Markdown
Contributor

This is the first step of updating the session interface: #3830

We need to start by getting rid of the CLI's dependency on the Go SDK to cut that circular dependency. The follow ups after this will update the SDKs to download the CLI instead of using the engine-session binary. I'll be listing out the rest of the steps needed to get there in the other issue shortly.


This change was difficult to make completely on it's own, so there's a few other related changes bundled in as part of it:

  1. The CLI previously provisioned the remote engine used by the go sdk, but now it can't rely on that anymore.
    • Instead, the CLI now first tries to provision docker-image://ghcr.io/dagger/engine:v<VERSION>, where version is the git tag burned into the CLI by go releaser.
    • If there is no version burned into the CLI (it's a devel version), then it just uses :main.
    • This required the ability to use a plain tag w/out hardcoded image sha. I did this by having the provisioning logic resolve the tag->sha using the go-containerregistry library, which worked out well since it supports all the same auth mechanisms we already use as part of the session attachables.
  2. DAGGER_RUNNER_HOST is updated to its new name of _EXPERIMENTAL_DAGGER_RUNNER_HOST, since that was all being modified as part of this anyways
  3. I dropped the /query path from the router http server, now you just send gql queries direct to / again.
    • The main reason is that this results in the CLI being backwards compatible (it was serving / directly and proxying it to /query before, but now the router endpoint is being served directly).
    • In general, I think this is fine now though as IIRC the only reason we put it at /query was that it made the playground easier (which is no longer in the CLI). cc @aluzzardi in case I'm forgetting something here

@sipsma
sipsma marked this pull request as ready for review December 7, 2022 18:08

@aluzzardi aluzzardi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I was really looking forward to this

Left a few minor comments (all can be just dismissed, the only important one is /query)

Comment thread cmd/dagger/query.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General note: we should keep an eye on router.Do, it's been used only internally so far, I don't 100% know the error reporting etc are on par with regular requests

Comment thread router/router.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note for the future: This is probably better served as a http middleware rather than being in the handler itself. Typical patter of handlers doing handle-y stuff and http middlewares (through go chi or whatnot) handling auth, compression (note to self: we might want to enable gzip in the future, free latency boost), etc.

By doing so the entire auth stuff could live in cmd rather than being in core (and in the future, if we wanted and I'm not sure we will, we could have run --no-auth, --auth-basic <token>, etc without having to pollute the Router)

Comment thread router/router.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the switch from /query to /?

The goal of /query was for future proofing if we wanted to serve other endpoints (e.g. /ws/services/<id>/stdout). Still doable with / but slightly weird

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned in description: the main reason is that this results in the CLI being backwards compatible (it was serving / directly before and proxying it to /query, but now the router endpoint is being served directly).

If we leave this to be /query then we'll need to update the playground to use that instead, which is obviously totally possible but thought all else being equal that would be nice to avoid.

But sounds like all else is not equal (curious what weirdness is caused by having it be at /, that rings a bell but I forget) so I'm good with leaving /query instead. Will update

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a commit going back to /query (will squash it on merge).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gerhard gerhard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have eyeballed all changes and they look good to me. I appreciated the naming improvements - sessionToken in particular - and the removal of a few TODOs.

I'm all for merging this, and following up with other improvements in separate PRs. A few thoughts:

  • Does this change anything in our docs? If yes, I would probably make those changes part of this PR - we should take advantage of docs being in the same repository.
  • I would feel a lot more comfortable if we had one end-to-end CLI test which would exercise the happy path. That should catch any potential breakage that his PR might introduce (again, I just eyeballed it). Anymore than one end-to-end CLI test would be counter-productive at this point. FWIW, more than a few end-to-end integration tests in total would be counter-productive: 🎬 Integrated Tests Are A Scam

@sipsma

sipsma commented Dec 7, 2022

Copy link
Copy Markdown
Contributor Author

Thanks @gerhard

Does this change anything in our docs

No doc changes yet, the only backwards incompatible change will be to dagger listen. dagger run is unaffected by the change of endpoint because our docs tell users to just use DAGGER_SESSION_URL, which has been updated here.

I would feel a lot more comfortable if we had one end-to-end CLI test which would exercise the happy path.

Agreed, I added a e2e test in this other PR here: https://github.com/dagger/dagger/pull/4029/files#diff-743eff5a95cd3bba29eec3b8d54dfb365904b84d1aa3feec83ef7aa14d08af33

But yeah I'll see if I can backfill a little more coverage there too.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma merged commit 5219a37 into dagger:main Dec 7, 2022
@aluzzardi

Copy link
Copy Markdown
Contributor

Mentioned in description: the main reason is that this results in the CLI being backwards compatible (it was serving / directly before and proxying it to /query, but now the router endpoint is being served directly).

/cc @marcosnils

Wasn't aware the playground sent queries to / rather than /query

@marcosnils

Copy link
Copy Markdown
Contributor

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants