Repository navigation
sdk: go: dagger.Connect - #3349
Conversation
sipsma
left a comment
There was a problem hiding this comment.
Looks good overall!
Still, lots of other intricate dependencies (project config, etc). Unsure if we can get rid of them?
Assuming you're talking about the stuff in engine.Context
- Project config is good to remove afaict (was needed for older codegen, not needed right now).
- Localdirs can be removed (that was just a convenience to save an extra call to retrieve the name->id mapping
Planning to eventually have unixconn etc, use DAGGER_HOST or something to automatically select which conn to use (e.g. core could set DAGGER_HOST=unix:///cloak.sock and dagger.Connect() would work out of the box)
👍
Q However it might make sense to make dagger/client just dagger, and potentially move the serve part to a sub-package if needs be?
Yeah moving it like that would make more sense to me. Client is going to be imported more often than the server stuff (which honestly needs to be renamed anyways as part of fleshing out the code-first stuff). dagger.Connect has a nice ring to it.
There was a problem hiding this comment.
Once this PR is merged: #3342 (comment)
We should also update this func to wrap errors with that message I think.
Also, looking at this code now, we could consider just wrapping the error in Do instead of where I inserted it in that PR. Probably makes no functional difference, may just be cleaner.
0435cdb to
80be96c
Compare
|
/cc @kpenfound -- one of the last big breaking changes |
sipsma
left a comment
There was a problem hiding this comment.
Couple comments but nothing blocking, awesome to see extensions and other clients more unified! 🎉
There was a problem hiding this comment.
nit, not blocking, just if you agree
type ClienOpt interface {
SetClientOpt(cfg *engineconn.Config)
}
...
func (cfg *engineconn.Config) SetClientOpt(other *engineconn.Config) {
// set each other field from fields set in cfg
}Is nice as it addresses some people's concerns about optional pattern not being discoverable as you can just pass a struct instead. Can still have all the individual With* methods too for those who like those.
There was a problem hiding this comment.
Yes, I remember your suggestion and was planning to do that.
However I got a bit stuck. I don't want to expose engineconn to the user and originally intended for this to be dagger.Config{}, however got into a circular dependency problem (dagger -> engineconn -> dagger).
Do you see an easy way out of this?
(ps: I wish to move engineconn and whatever else is not part of the public API under internal/ so we're free to change without breaking anyone)
There was a problem hiding this comment.
I guess the generic fallback option w/ circular deps is to split out into a separate package, like:
- dagger -> engineconfig
- engineconn -> engineconfig
engineconfig is just a placeholder name, but it would just hold the common (public) interface/struct definitions needed to configure the engine. engineconn can remain internal too then I think.
I'd be fine with that. Intermediate option is to just change ClientOpt to be an interface rather than direct func so that we can retain the flexibility to do something like this in the future.
There was a problem hiding this comment.
I'd be fine with that. Intermediate option is to just change ClientOpt to be an interface rather than direct func so that we can retain the flexibility to do something like this in the future.
Done.
Might find a better way than a separate package at some point, just don't want to it in this PR for now
There was a problem hiding this comment.
I think we dropped the SkipInstall here unless I missed something. If we can keep it that would be preferable because the only thing that's needed here is to load project metadata; there's no need to actually compile the extension (and fail if it has an error).
The only other possibility would be to move loading of project out from engine, but that's the whole other can of worms we talked about before, not worth it yet probably.
This isn't blocking if it's time consuming, but worth an issue if not fixed here.
There was a problem hiding this comment.
Yep, I was actually puzzled by this.
If I understand correctly, setting SkipInstall would only load the project under ctx.Project, which is not exposed anymore anyway, correct?
So a similar behavior could be achieved with a WithConfigPath(""), or to make it more explicit a better name would be WithNoExtensions()?
I see this code is querying for its own loadExtension so it doesn't care that the engine is actually loading the extensions (and skipping install)
There was a problem hiding this comment.
Ah yeah, I forgot the code that I wrote several days ago already 😵💫😵💫😵💫 This file actually already is doing the project load itself (line 192), so the only thing needed is for the engine to not load anything, which will be the implicit behavior if you don't set ConfigPath, so actually the only change here should be to just not call WithConfigPath at all.
There was a problem hiding this comment.
I pushed a small update in a separate commit engine: remove redundant functionality -- helps clarify the load project stuff in engine (much smaller surface area).
How does that look? Can easily revert
There was a problem hiding this comment.
(also can add an explicit dagger.WithNoExtensions())
There was a problem hiding this comment.
That commit looks good overall, but I don't think you need NoExtensions even. AFAICT if you don't provide a ConfigPath, that should just be the same thing. I think that makes sense: no extension config, no extensions loaded.
Then special cases (like this project command) that need different extension loading logic (like skipping install) can just do the call themselves.
There was a problem hiding this comment.
Ah, actually we call NormalizePaths in engine.Start, so this doesn't quite work as is (it will see empty ConfigPath and then default it to $(pwd)/dagger.json). I actually think that in and of itself should be refactored, but that's getting way out of scope here.
How about we just leave NoExtensions for now (it's an obscure thing, only needed by this project command) and then we can refactor this a bit more in the future. I think I see a path for how to do it cleanly, I'll make an issue.
There was a problem hiding this comment.
Done in last commit
Actually, even client-gen needs this for now
There was a problem hiding this comment.
nit, not a blocker: maybe this could become QueryWithClientOpts(..., clientOpts ...dagger.ClientOpt)?
80be96c to
fd9560b
Compare
703a997 to
dfcdfd4
Compare
Signed-off-by: Andrea Luzzardi <[email protected]>
Signed-off-by: Andrea Luzzardi <[email protected]>
Signed-off-by: Andrea Luzzardi <[email protected]>
Signed-off-by: Andrea Luzzardi <[email protected]>
Signed-off-by: Andrea Luzzardi <[email protected]>
Signed-off-by: Andrea Luzzardi <[email protected]>
484e292 to
06053fe
Compare
dagger/clientsince there's a bunch of crap in there, didn't want to grow the dagger package unchecked (which also contains the server).dagger/clientjustdagger, and potentially move the serve part to a sub-package if needs be?daggerconnhelperconcept, half bakedengineconnto use the built-in engineunixconnetc, useDAGGER_HOSTor something to automatically select which conn to use (e.g. core could setDAGGER_HOST=unix:///cloak.sockanddagger.Connect()would work out of the box)enginepackagedagger.Connect(ctx, dagger.WithLocalDir(...), dagger.WithWorkdir(...))to maintain compat?github.com/Khan/genqlient/graphql.ClientawayInterface:
client.Do()--> send a graphql request (e.g. equivalent ofgraphql.Client.MakeRequest)client.Core()--> return the codegen'd API (e.g.c.Core().Container().From(...))client/apiapi.Query