Skip to content

POC: load defaults from .env - #11000

Closed
shykes wants to merge 17 commits into
dagger:mainfrom
shykes:default-secrets-poc2
Closed

shykes wants to merge 17 commits into
dagger:mainfrom
shykes:default-secrets-poc2

Conversation

@shykes

@shykes shykes commented Sep 7, 2025

Copy link
Copy Markdown
Contributor

This is a POC for loading default configuration from .env, and injecting it into the dagger schema.

How it works

  • Dagger automatically searches for .env by findup.
  • Each time a module is loaded, the .env is searched for variables that match the module name. For example, a module named app will match all variables starting with app_ or APP_
  • Matching variables are matched to corresponding constructor argument names

Example

cat > .env <<.
DISCORD_TOKEN=op://myvault/mydiscordtoken/credential
.
dagger -m github.com/shykes/x/discord -c servers

--> This will list your discord servers, using the token in the .env file.

See also

shykes and others added 17 commits September 5, 2025 15:23
- type Directory: findup(), findupFile(), findupDirectory()
- type Host: findup(), findupFile(), findupDirectory()
- Host.directory(): allow escaping workdir

Signed-off-by: Solomon Hykes <[email protected]>
- honor secret cacheKey when using address api
- update TestParseGit unit tests to account for nil fragment

Authored-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
- cleaner implementation, support more object types
Signed-off-by: Solomon Hykes <[email protected]>
@shykes

shykes commented Sep 7, 2025

Copy link
Copy Markdown
Contributor Author

FYI @nipuna-perera @rawkode @nadirollo @vmaffet @ChrisChinchilla

This is closer to what @nipuna-perera suggested:

  • Use standard .env
  • Load it from the client's workdir, not the module
  • Applies to multiple modules: the module name must be used as a prefix to the variable

It still works with all object types, not just secrets. (thanks to #10770).

@shykes
shykes requested a review from TomChv September 7, 2025 03:10
@nipuna-perera

Copy link
Copy Markdown
Contributor

FYI @nipuna-perera @rawkode @nadirollo @vmaffet @ChrisChinchilla

This is closer to what @nipuna-perera suggested:

  • Use standard .env
  • Load it from the client's workdir, not the module
  • Applies to multiple modules: the module name must be used as a prefix to the variable

It still works with all object types, not just secrets. (thanks to #10770).

Love where this is headed. I think I can live with just the constructor args being handled but it would be really amazing if it was any function arg. For example, I may have a Java module that has a Maven struct that may take a user/pass that wouldn't necessarily be needed for the Java module. If only constructor args were supported, I'd potentially have to split that into multiple modules. Is there a technical limitation for this being only for constructor args?

@shykes

shykes commented Sep 7, 2025

Copy link
Copy Markdown
Contributor Author

No technical limitation, mostly UX: what would be the naming convention for all those different module and function arguments

@nipuna-perera

Copy link
Copy Markdown
Contributor

No technical limitation, mostly UX: what would be the naming convention for all those different module and function arguments

Typically the arg names don't collide. Even if they do, dagger can warn right? I'd say keep it simple and substitute any matching args.

@shykes

shykes commented Sep 16, 2025

Copy link
Copy Markdown
Contributor Author

Final PR: #11034

@shykes shykes closed this Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants