-
Notifications
You must be signed in to change notification settings - Fork 337
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
Cache env vars with slow exec function calls in templating #1261
Comments
I think me putting caching around templates is too difficult. I have no idea what sort of invalidation logic would work since I have no idea what people might be putting in their files. Perhaps what we could do though is expose caching inside the templates so you could read/write to the cache instead of performing expensive computations. |
Caching would be great, please have in mind that exec templates can be used to retrieve secrets so env vars shouldn't be cached/stored on disk unencrypted. i.e.
|
Oh just realized this use-case was the original motivation for this FR :) |
I believe the need for caching templates used in environment variables could be eliminated by leveraging the
[env]
_.source = "./.envrc"
export TEST_SOURCE=test
However, there seems to be an issue with the short circuiting logic as mentioned in #1617 (comment) Doing a bit of investigation, I've added the following traces in the code: diff --git a/src/config/env_directive.rs b/src/config/env_directive.rs
index dc995816..9c398a5c 100644
--- a/src/config/env_directive.rs
+++ b/src/config/env_directive.rs
@@ -155,11 +155,11 @@ impl EnvResults {
};
let mut paths: Vec<(PathEntry, PathBuf)> = Vec::new();
for (directive, source) in input.clone() {
- // trace!(
- // "resolve: directive: {:?}, source: {:?}",
- // &directive,
- // &source
- // );
+ trace!(
+ "resolve: directive: {:?}, source: {:?}",
+ &directive,
+ &source
+ );
let config_root = source
.parent()
.map(Path::to_path_buf)
diff --git a/src/hook_env.rs b/src/hook_env.rs
index 24ccba1e..c5830ad1 100644
--- a/src/hook_env.rs
+++ b/src/hook_env.rs
@@ -25,6 +25,7 @@ pub fn should_exit_early(watch_files: impl IntoIterator<Item = impl AsRef<Path>>
return false;
}
let watch_files = get_watch_files(watch_files);
+ trace!("watch_files: {watch_files:#?}");
match &*env::__MISE_WATCH {
Some(watches) => {
if have_config_files_been_modified(watches, watch_files) { This revealed that the
@jdx Shouldn't the script execution be deferred? |
@jdx is there a way to avoid mise re-running the I have: [env]
TF_VAR_secret = "{{exec(command='op read \"op://terraform/secret\"')}}" and was expecting mise to not re-execute the exec portion on every prompt. This issue is old, so I'm wondering if there's a way around this? Thanks |
❤️ |
This is working great, awesome! Thanks @jdx 🚀 |
Setting environment variables from commands that are slow affects all prompt executions, e.g. setting:
mise env-vars TEST_MISE="{{exec(command='sleep 1')}}"
which translates into:
will add a 1 second latency at each prompt.
It would be awesome to allow caching such commands.
Note: that's just an example, my actual use case is invoking gopass to set an environment variable with GPG operations depending on my yubikey.
The text was updated successfully, but these errors were encountered: