Repository navigation
User defaults: persist any dagger function argument to .env - #11034
Conversation
264c67a to
9b7e6cd
Compare
|
Can't wait to try this! Does this still only support constructor args? Or is it expanded to support any arg? |
|
@nipuna-perera I'm making my way to "any args" :) |
d6f8ce2 to
3cdac2f
Compare
|
I added suppport for implicit module name. |
3cdac2f to
9002129
Compare
|
This is going to be a game changer for us! With this we can finally replace many makefiles/justfiles that wrap around dagger! Can't wait to try this out 👍 |
Awesome! Yes, removing the need for wrappers is the goal :)
Do you mean arguments to functions other than the constructor? Yeah I'm working on that right now :) @nipuna-perera also asked for that. May I ask, are you thinking of functions attached to the top-level object? Or even further, functions attached to potentially any object type in the module? |
|
I think args to the top-level object would be great. Our blueprints are "simple" enough that don't require many chainable objects (yet...?) |
I replied here too - https://discord.com/channels/707636530424053791/1413254056188579901/1417690771175243828 I think it should apply uniformly to any dagger addressable object functions. Otherwise it adds a layer of complexity. One may expect a chained function to have the same behavior of the main dagger object. It's probably a niche use case but for the sake of UX I don't see a drawback of it applying to everything. |
42d8829 to
3dded3e
Compare
|
Is this supports dagger.Secret as a string value or as a file? |
It supports all the same secret addresses as for CLI arguments:
I don't believe literal string values are supported |
f874c80 to
7d3d12e
Compare
|
This looks like a legitimate test failure... https://dagger.cloud/dagger/traces/3a0f35ffcb5847a40c5bae36330d3eda?span=a2ef985d225c652e
To repro locally: |
704fd08 to
87c6f5b
Compare
|
I'm mostly using .envrc files used by direnv. Maybe just relying on exported envars is sufficient and leaving the rest to tools like direnv. Or at least support both .env and .envrc |
Supporting Expanding into I'll think about the idea of also supporting straight system env variables. With the scaffolding in place, this could be done safely I think. I just need to think through the UX implications - for example there's an elevated risk of accidental false positives. (eg. your dagger module accepts an argument In the short term, we're going to merge I understand how you would prefer to do everything with your favorite environment config (in your case |
It seems like quite a few tests besides that one are failing. From ones I looked at it seems like they are failing during This chunk of code looks wrong: Lines 291 to 301 in e577d90 It unconditionally returns an error when |
Honestly I think
Working with dagger and other tools in our projects we solely rely on the shell exports for things to work the way we want. (direnv helps us loading and unloading the variables when switching directories) to not have side effects as you described above. I think for a better integration with other tooling and projects it would be a huge benefit if this was less opiniated and just treat these things as env vars. At the moment I therefore do Makefiles to dynamically compose the dagger commands based on shell exports being available or not. Which makes things very verbose and from a UX perspective massively long commands to pass in all the secret variables and such. Why not pickup all env vars with a convention like |
Sorry about that @sipsma ... This looks like residue from my trying to find an answer to this: #11034 (comment). |
The problem is there no such thing as "less opinionated". Your approach of relying on system variables + a tool to manage them is by no means a universally accepted method. The ecosystem is highly fragmented. For example if we only supported system env variables, someone would make the exact same argument as you, in reverse: "why not support
Once this PR is merged, you have another option, which is to write a
Yes we might do that, as I said before. I need to think about the implications. But, it won't be a universal solution either, because not everyone uses system env vars to configure their tools. |
I removed the offending error checking code... But still getting failed tests, investigating further. |
sipsma
left a comment
There was a problem hiding this comment.
this seems worth a quick fix: https://github.com/dagger/dagger/pull/11034/files#r2394004381
otherwise LGTM
319a427 to
a7c06f3
Compare
Not actually "dismissing", I believe all issues have been discussed & addressed already :)
Signed-off-by: Solomon Hykes <[email protected]>
This requires a build from main including this PR: dagger/dagger#11034
Overview
Local defaults: user can add default arguments to their modules, using a local .env file.
This avoids typing too many CLI arguments on every call.
How it works
tokenof the modulegithub.com/shykes/x/discord.envfile. This could be in the module directory, or in a parent directory on your filesystem, depending on when you want it to be loaded. See standard.envconventions..env. The variable name must be<module name>_<argument name>(case-insensitive). If your.envfile is within your module directory, you can also use the variable name<argument name>(the module name is implicit). You can combine both notations. Variables that don't match this convention will be ignored. The variable value should be the same value you passed explicitly on the CLI. For example if you calleddagger -m github.com/shykes/x/discord --token=op://foo/bar, your variable should beDISCORD_TOKEN=op://foo/bar.github.com/shykes/x/discord -c servers.Supported values
Variable values support the same format as command-line arguments:
Directory: local path or git addressFile: local path or git addressSocket: local pathContainer: container image addressSecret: url with schemesop://(1password),vault://(hashicorp vault),env://(environment variable),cmd://(command execution),file://(local file path),libsecret://(libsecret provider)GitRepository: git addressGitRef: git addressServicelocaltcp://urlExample
dagger -m github.com/shykes/x/discord -c servers--> This will list your discord servers, using the token in the
.envfile.TODO
dagger --env-fileto select an alternative filenamedagger --no-env-fileto disable local defaults entirelySee also