-
Notifications
You must be signed in to change notification settings - Fork 556
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
šļø Is it possible to access Host()
from a dagger function? (Go SDK)
#6955
Comments
Host()
from a dagger function? (Go SDK)
I just installed dagger 0.10.3 this morning and have the same issue with Python SDK. |
I'm in the 0.10.2 |
The approach to writing a Dagger module has changed since v10. If you need a directory from the host you can pass one in when invoking your function: package main
import (
"context"
)
type MyModule struct{}
func (m *MyModule) Test(ctx context.Context, dir *Directory) (string, error) {
return dir.File("my-file").Contents(ctx)
} Then you would call it by: dagger call test --dir /tmp/my-directory |
Thank you for your response. So if I want to do it through code instead of a param I have to use a "standard" dagger workflow instead of a module function, right? Greetings. |
@tonirvega That is my understanding of the difference between writing Dagger Modules and using a "standard" Dagger workflow. I am happy to be corrected by someone from the community š |
I'm having some issues with this, I ran |
@by-nelson, can you be more specific on what you mean? Some APIs are only accessible in modules, and others may be the opposite. That's the case with |
Ok, great! š I'm going to close as being answered.
|
I came here looking for the same information as the OP. If we have to accept a Directory as a path, we lose the ability to setup include/exclude rules. And based on all the documentation, it seems like modules and functions are the way to write dagger scripts now. If there is a normal Dagger workflow (as @purpleclay called it) where is this in the documentation? |
Not quite, we have a feature called views: Itās not yet documented because we need to polish the DX for managing it with the CLI: We use it in our CI: Lines 6 to 17 in e678cdd
And we call it like:
To be clear, this is only needed for files outside of the moduleās source directory ( dag.CurrentModule().Source() And thereās filters for limiting the files uploaded when loading a module. Example: dagger/sdk/python/dev/dagger.json Lines 5 to 23 in e678cdd
However, weāre discussing a change for how modules are loaded: So that in the common case of needing access to the parent directory, you wonāt need to pass it as an argument and set up views. Youāll be able to access it and filter from code: func (m *MyModule) Source() *Directory {
return dag.
Context().
Directory(ContextDirectoryOpts{Include: []string{"*.go"})
}
The term ānormalā here is only in the same sense of āusualā, but only for users that have used dagger for a while, before modules were released in We think that using Functions has many benefits over what came before but to clarify a few things:
|
Thanks for the information. This seems like a pretty fundamental thing that should have been ironed out before releasing these functions. Not to mention the DX for these "views" is awful. I need a single file added to a container, but with the views limited parameters, I can't figure out how. {
"name": "flagsmith-scripts",
"sdk": "typescript",
"source": "./dagger",
"engineVersion": "v0.11.2",
"views": [
{
"name": "npmrc",
"patterns": [
"!**/*",
"$HOME/.npmrc"
]
}
]
} My assumption is that the projects root acts as the "baseDir". But I need a file in the home directory, as you can see. So based on the implemtation of "views", it seems I want to exclude everything from the "baseDir" and then just include my 1 file, but as you can guess, Dagger doesn't like this |
If you only need a file you can have a But just for completeness, I'd have |
How can I get access to the host from a dagger function?
I miss the
Host()
, Is there any way to do this?The text was updated successfully, but these errors were encountered: