-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/context directory #7744
base: main
Are you sure you want to change the base?
Feat/context directory #7744
Conversation
c08bbea
to
e3064b6
Compare
(continuing a conversation from discord) For now, I think the way to general way to approach this feature should be to leave the current module context loading as is since it's used by the SDKs to build modules and then add this support for user arg context dirs as separate context loading calls. There's likely ways of unifying and optimizing this but better to start simple for now. There's different ways of approaching this, I'm just gonna outline the first reasonable possibility that comes to mind. Not set in stone at all though so happy to hear other opinions and happy to help out more if reality of implementing it doesn't align with theory.
|
I understand this but this directory will not have the full repo if it's not part included in |
You would need to add a new method that does the actual load of files from the original context directory (i.e. loads from the user's local dirs or loads from the git repo). That's what I was referring to under "The way that you implement loading the context depends on whether it's coming from a remote git repo or a local git repo." in my previous comment |
To do such thing, we need to know the file where the module func comes from, I'm not sure we got this information in the current API. |
Sorry I forgot to update that line after further discussion. It should be relative to the module root, not the file (that would be too difficult to find out). |
Ohh then yeah it's much easier haha |
Another question @helderco @jedevc @shykes, should the API returns an error during registration if the typedef has both a default value and a contextual one? Example of notation: @func()
async test(@context("/") dir: Directory = dag.directory()): Promise<string[]> |
b920242
to
426440b
Compare
I thought we were using default values? I might have missed (or forgotten) the last round of bikeshedding on that topic. |
No it's a specific field in the API, see the change of spec in the description |
@TomChv could you add example snippets of what that feature would look like, in the 3 main languages please? It would make it easier to discuss the DX tradeoffs |
I updated my view in #7647 (comment):
We need to bikeshed on the In Python, this would have to be done using metadata annotation on the type: def build(
self,
backend: Annotated[
dagger.Directory,
DefaultFromContext("../backend/app/src"),
Ignore(...),
]
) -> dagger.Directory:
... |
I think it should look like this: Go func (app *App) Build(
// +default="./frontend/src"
frontend *Directory,
// +default="./backend/app/src"
backend *Directory,
// +default="/tools/builder.conf"
buildConfig *File,
) *Directory {} Typescript @func()
build(
@context("./frontend/src") frontend: Directory,
@context("./backend/app/src") backend: Directory,
@context("./tools/builder.conf") buildConfig: File,
): Directory {} Python Done by Helder above
|
In Go, rather than |
@TomChv could you add an example of how regular default values work in each case? |
Example on https://docs.dagger.io/manuals/developer/functions#default-values Go I'm not sure you can default to a directory value in Go so I don't know?? But for primitive type, you set a pragma like Typescript @func()
build(
frontend: Directory = dag.directory(),
backend: Directory = dag.directory(),
buildConfig: File = dag.directory().WithNewFile("xxx", "xxx").File("xxx"),
): Directory {} Python I'm not sure about the syntax but probably: def build(
self,
backend: Annotated[
dagger.Directory,
] = dag.directory()
) -> dagger.Directory:
... |
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
cb2de90
to
770d17c
Compare
API changes
This PR updates the
Function
andFunctionArg
from our engine API to supportdefaultPathFromContext
Engine changes
Call
to load contextual values and insert it as input.loadContextualArg
function that take the typedef and retrieve its contextual default value.loadContext
to load fromgit
orlocal
source the contextual path.This implements the spec designed in Context directory #7647
For git: we load it from the context directory since it includes the whole repo.
For local: we load it from
importLocal
with the specific directory specified so we never load the full repo expect for/
Current progress
*Directory
toID
: I found a workaround withBlob
but it's not okay forFile
, I will check if I can use select instead.Select
actually works!Spec Reminder
SDKs support
Go using pragmas directive on
Directory
orFile
type ⌛Typescript using
@context("path")
✅Example
Fixes #7647