Repository navigation
SDK: expose module type definitions - #10584
Conversation
d4d86b4 to
943fd78
Compare
f7d341d to
df123e0
Compare
|
@eunomie Looked at the I think the fundamental problem is that we end up running codegen twice now in this new scheme. That's not ideal for performance besides the socket issue it introduces. I think splitting out the new I haven't parsed through the exact behavior changes |
|
Thanks @sipsma for the explanation.
The goal is to run codegen twice, and to decouple typedefs from runtime. A very simple example would be the following: func (m *MyModule) ContainerEcho(stringArg string) *dagger.Container {
return dag.Container().From("alpine:latest").WithExec([]string{"echo", stringArg})
}
func (m *MyModule) Echo(stringArg string) *dagger.Container {
return dag.MyModule().ContainerEcho(stringArg)
}The
All that means 2 codegen phases, one for typedefs, one for function calls. Right now it's the same with just a flag, that could be completely different, or use something like @jedevc is mentioning above, but my understanding is it will not really change a lot to this problem, no? So yes, for this very first phase it would be possible to avoid the different codegen and only use the existing |
|
Regarding performances, yes there's a cost here. But I don't see a lot of different ways to avoid it. Thinking again, maybe the idea of an intermediate json might help has there's not anymore this typedefs container. Maybe. |
Could you detail a bit more? I'm not sure to understand the link between the container cached and not evaluated and the SSH socket. |
Hah, okay, I chatted with @eunomie, lemme try and summarize and explain. So, this is part of the work to do self-calls. We need the separation into two phases for this. For the go sdk (as currently structured in Here's why:
But. In the scenario of self-calls the code won't be valid after generating all the types and methods - because we'll be missing the self-bindings (we only know what those types should be after step 3). So we can't build it, so we can't get the typedefs. We have this weird circular dependency. Thankfully, we can fix this. So, we need these two phases. To make sure that we fix the caching issue that @sipsma points out, we need to eagerly evaluate the However, as @sipsma points out, there's a little bit of a perf issue here (curious to see how this pans out though, it might not be terrible?). For every module load, we're now having to generate, build, and execute two binaries. Ideally, the solution to this is to improve |
|
This is not a solution at all, but I just confirmed that with this change, that works: diff --git a/core/sdk/go_sdk.go b/core/sdk/go_sdk.go
index 3d6fc8390..664aff2e9 100644
--- a/core/sdk/go_sdk.go
+++ b/core/sdk/go_sdk.go
@@ -523,13 +523,13 @@ func (sdk *goSDK) baseWithCodegen(
// cause failures if we also mount this in Runtime.
// Issue we run into is that when we try to run sdk checks
// using .dagger, it fails trying to find the socket
- sshAuthSelectors, err := sdk.getUnixSocketSelector(ctx)
- if err != nil {
- return ctr, err
- }
- if len(sshAuthSelectors) > 0 {
- selectors = append(selectors, sshAuthSelectors...)
- }
+ //sshAuthSelectors, err := sdk.getUnixSocketSelector(ctx)
+ //if err != nil {
+ // return ctr, err
+ //}
+ //if len(sshAuthSelectors) > 0 {
+ // selectors = append(selectors, sshAuthSelectors...)
+ //}
// now that we are done with gitconfig and injecting env
// variables, we can run the codegen command.(if there's no need for a private repo) My understanding is the first codegen part (the one generating the typedefs) shouldn't require the ssh socket, as it shouldn't need the dependencies if I'm right (functions can return a local type or a core type, but not a dependent type, right?) |
This comment was marked as resolved.
This comment was marked as resolved.
e3fe349 to
e0b2efc
Compare
moduleTypeDefs to module SDK, to register type definitionSigned-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
load runtime trace has been removed in dagger#10468 so removed it again, and remove the corresponding one for type defs Signed-off-by: Yves Brissaud <[email protected]>
…nv variable Signed-off-by: Tom Chauveau <[email protected]>
In case `moduleTypeDefs` exists in the SDK, use it to get the module's types. But if the self calls experimental flags, simply replace the previous moduleRuntime call, do not use the results as its own dependency. This allows to remove the previous duplication between TypeDefCode and TypeDef in go codegen for instance, and to benefit from the moduleTypeDefs work without the self calls that needs more work to be ready for all cases. Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
until we are able to fix them Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Bump typescript SDK Dagger version to ensure it's using
withEnumMember
without to fallback to
withEnumValue
because the version (0.16) was too old.
Signed-off-by: Yves Brissaud <[email protected]>
CoolSdk is used as a wrapper on top of the Go SDK. As the Go SDK now implements ModuleDefs, the CoolSdk needs to also do it to properly wrap the Go SDK. Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
This will allow to control how the WithExec call is made, especially this will allow to inject the module information during the call. But this needs to happen from the engine, not from the SDKs. To inject module data will allow to set the right engine version at a moment the module is still not yet loaded. Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
shared cool-sdk updated with new moduleDefs function Signed-off-by: Yves Brissaud <[email protected]>
Always codegen. This is the only way, with the actual implementation, to have access to the SDK for instance. The test is wrapping the Python SDK, in a module written in Python. The code is calling dag.PythonSDK. But this module exists only because it has been loaded, it's not part of the default core types. This shouldn't be an issue, except the way the Python SDK works is moduleDefs is using moduleRuntime container. The ultimate solution is to cut the link between moduleDefs and moduleRuntime, to have better performances, but in the meantime this can be a solution. Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
Currently performances are not good enough and those SDKs require a bit more work. In order to unblock the PR and allow to merge it, just remove the moduleTypes functions for those SDKs so that they are not affected and they will be added back in dedicated PRs. The moduleTypes function has been renamed to moduleTypesExp for both SDKs so it's still exposed and can be calles manually to help fix it, but the engine is not seeing it anymore. Signed-off-by: Yves Brissaud <[email protected]>
|
For performances reason and as a way to unblock this PR, the new |
grouville
left a comment
There was a problem hiding this comment.
LGTM ✅ Let's follow-up with all the neats + python and ts / sdk port to that new implementation
Note
This has been extracted and cleaned from #10475
This is a first step to #10336 and #8030
The main purpose of this PR is to allow SDKs to expose the module type definitions on a specific function.
This is a mandatory step to unlock the ability for modules to self invoke themselves. This pull request contains the ability to self call themselves, but it's experimental as it doesn't support all the cases.
Self Call Example
In this example
printfunction will callcontainer-echothrough the engine instead of directly.This also allows to use directives like
optionalanddefaultas you can see inprint-default. This is something not doable by calling the function directly.moduleDefsThe PR introduces a new
moduleDefsmethod SDK modules can implement.Without this PR, the container returned by
moduleRuntimeis called in two different ways:In a module using the Go SDK for instance, this is done in the generated
invokefunction you can find indagger.gen.gothat is used at the entrypoint of the module container runtime. Theinvokecode looks like:The idea of
moduleDefsis to split those two responsibilities.:moduleDefsthat ultimately returns adagger.Moduleobject (similar to what is performed inside the container when called with an empty function name)moduleRuntimewill be executedImplementation
The
moduleDefsfunction, exposed by the SDK, needs to be executed on behalf of the module we are loading. This allows to use the rightengineVersionfor instance.To do that, the
moduleDefsis constructed the same way than themoduleRuntimefunction:This function takes the module source, the introspection JSON as well as a file path to write the output.
And the function returns a Container with a defined entrypoint.
The entrypoint will be called by the engine, with a specific set of parameters to run it on behalf of the module (as the module is not yet loaded those internal parameters are required).
When the
moduleDefsis called, it must write, in JSON, the ID of the module representing the different types exposed by the module.A pseudo code version could be like:
The Engine will then read this
outputFilePathfile to load the module with the exposed types.Introspection JSON
Some SDKs might require to generate Dagger types before to be able to generate the types exposed by a module.
So it requires an introspection JSON to be available.
But then the module runtime needs a new introspection JSON extended with the exposed types.
The flow is the following when loading a module:
moduleDefswith this introspection JSONmoduleRuntimewith a new introspection JSON based on the extended typesmoduleRuntimewill besynced so the cache is resolved, even if the container will be called only later when invoking a functionIf a SDK has already access to the default types (the module and typedefs types) because of the generated files are already part of the SDK or because they are published in a library that can be used (that's not yet the case for Java) then the introspection JSON on
moduleTypeDefscan be safely ignored.Feature Flag / Compatibility
Self Calls are not enable by default. This means the SDKs must still work with the current way of doing, through runtime container. And in addition the new way with
moduleTypeDefsfor self calls.Note
For compatibility reasons, if the
moduleDefsfunction is not exposed by the module SDK, then themoduleRuntimewill be run and the container executed as before, and self calls will not be enabled.To enable self calls, you can edit manually the
dagger.jsonto add the experimental flag as follows:{ "sdk": { "experimental": { "SELF_CALLS_FEATURE": true } } }And it's also possible to use
dagger initanddagger developcommands:dagger init --with-self-callsto init a new module with self calls enableddagger develop --with-self-callsto enable it on an existing moduledagger develop --without-self-callsto disable it