Module Dependencies
Modules can call each other. To add a dependency to your module, you can use dagger install
, as in the following example:
dagger install github.com/shykes/daggerverse/hello@v0.3.0
This module will be added to your dagger.json
:
...
"dependencies": [
{
"name": "hello",
"source": "github.com/shykes/daggerverse/hello@54d86c6002d954167796e41886a47c47d95a626d"
}
]
You can also use local modules as dependencies. However, they must be stored in a sub-directory of your module. For example:
dagger install ./path/to/module
When you add a dependency to your module with dagger install
, the dependent module will be added to the code-generation routines and can be accessed from your own module's code.
The entrypoint to accessing dependent modules from your own module's code is dag
, the Dagger client, which is pre-initialized. It contains all the core types (like Container
, Directory
, etc.), as well as bindings to any dependencies your module has declared.
Here is an example of accessing the installed helloWorld
module from your own module's code:
- Go
- Python
- TypeScript
func (m *MyModule) Greeting(ctx context.Context) (string, error) {
return dag.HelloWorld().Message(ctx)
}
@function
async def greeting(self) -> str:
return await dag.hello_world().message()
@func()
async greeting(): Promise<string> {
return await dag.helloWorld().message()
}