- Notifications
You must be signed in to change notification settings - Fork 276
[devbox] run: skip re-computing Devbox State if in devbox shell #2144
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
Conversation
mikeland73 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will actually skip init hooks.
init hooks are baked into the scripts that are written to (.devbox/gen/scripts).
If you want to brainstorm a few approaches happy to chat
btw, currently init hooks are skipped if there is a script called inside an init hook. That's the if statement you will find in the generated sh file.
oh yeah, good point! |
| @mikeland73 PTAL. Made the update as discussed IRL. Notably, I chose to keep the |
| For some reason I still see the init hooks running twice. Maybe there's something weird with my setup, but this is what I see: Config: { "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.0.0-dev/.schema/devbox.schema.json", "packages": [], "shell": { "init_hook": "echo this is my init hook", "scripts": { "test": "echo this is my script" } } }Build Info: |
| If we don't recompute the state, does that mean changes to |
Can you double check which devbox binary you are running? Here's the output I see with your devbox.json: |
in this case, the output will be However, changes to the shell environment will not show up until the user executes the |
mikeland73 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notably, I chose to keep the init-hook-wrapper.tmpl unchanged. Reason: we need it to run for devbox shell scenario that calls . /path/to/projectDir/.devbox/gen/scripts/.hooks.sh (recall, init-hook-wrapper.tmpl generates .hooks.sh).
Can you elaborate on this?
Why does init-hook-wrapper.tmpl need to set export {{ .InitHookHash }}=true ?
My understanding would be:
If an init hook has a devbox run in it, by the time it runs d.IsEnvEnabled() returns true (since init hooks run after env is already set). This means that any devbox run inside init hooks would not run the hook again (thanks to the code in this PR).
A benefit is that removing the wrapper would simplify code. Basically:
No need to generate the wrapper, so hooks can be sourced directly.
We could also rename the env var to something more accurate, e.g. SkipInitHooks
🤔 I think I mis-diagnosed this...or mis-tested something yesterday. You are correct that I can comment out the env-var lines in |
| @mikeland73 PTAL |
mikeland73 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 👏 👏
Summary
This PR implements a change to the semantics of
devbox run.BEFORE:
devbox runwould always ensure that the Devbox State and Environment is up-to-date.AFTER:
devbox runwill only do so when outside a Devbox Environment (i.e.devbox shellor equivalent like direnv-enabled shell).The motivation is two fold:
devbox shellthat has already been set up appropriately.This was shared in the Discord channel for feedback: https://discord.com/channels/903306922852245526/1009933892385517619/1248724103750483978
Notably, the focus there was on skipping the init-hooks, but in this PR, we are going one-step beyond that to ensure the Devbox State itself is not re-computed. The reason is that rather than partially updating the Devbox State and Environment (partially, because init-hooks are part of setting up the environment) we'd rather eschew the step entirely. This feels more straightforward for users to reason about.
How was it tested?
Did a basic sanity test in two scenarios:
devbox shellor direnv-enabled environment does NOT recompute the Devbox state.