-
Notifications
You must be signed in to change notification settings - Fork 264
[bin wrappers] add --omit-wrappers-from-path to shellenv to prevent a binary from invoking a wrapped-binary. #1151
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
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
gah, I have a lot of local changes that didn't get added to the commit here. Updating! |
96d423b
to
70589b0
Compare
… binary from invoking a wrapped-binary.
70589b0
to
b3b8636
Compare
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.
no blocking comments
*/ -}} | ||
|
||
if [[ "${{ .ShellEnvHashKey }}" != "{{ .ShellEnvHash }}" ]] && [[ -z "${{ .ShellEnvHashKey }}_GUARD" ]]; then | ||
if [[ -z "${{ .ShellEnvHashKey }}_GUARD" ]]; then |
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 think the guard can be removed (the guard is in place to avoid infinite wrapper loop but since we're removing it from path it can't happen.
This is hard to test so we may be better off leaving as is for now. Maybe add 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.
yeah, I'll leave a comment. Would rather be super conservative with these changes.
internal/boxcli/shellenv.go
Outdated
} | ||
|
||
envStr, err := box.PrintEnv(cmd.Context(), flags.runInitHook) | ||
envStr, err := box.PrintEnv(cmd.Context(), flags.runInitHook, flags.omitWrappersFromPath) |
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.
When adding a second boolean is a good time to switch to a struct :P
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.
ah, I knew you'd say this :p
My personal threshold was three args, but sure 👍🏾
…d in wrapper template
…revent a binary from invoking a wrapped-binary. (#1151)" (#1159) ## Summary Reverting due to regression: Within a devbox script if any environment variable has been exported, and if a devbox-plugin also sets that env-var, then the devbox-plugin env-var will be set for the wrapped-binary. Specifically, in the `lapp-stack/devbox.json`, we have: ``` "run_test": [ "mkdir -p /tmp/devbox/lapp", "export PGHOST=/tmp/devbox/lapp", "initdb", ``` but the PGHOST that `initdb` sees is a different value i.e. the one set by the devbox plugin. In the code being reverted, the wrapped-bin's bash script would always invoke `eval $(devbox shellenv --omit-wrappers-from-path=true)` in order to omit wrappers from PATH. A side-effect is that the PGHOST would also get overridden. ## How was it tested? no testing done. straight revert, tests should pass.
…ers (#1160) ## Summary This is an alternate to #1151 (see explanation in #1159) In this approach, the wrapped-binary always calls: `eval $(devbox shellenv only-path-without-wrappers)` to ensure that the PATH is set without the `wrappers/bin` directory. In contrast to #1151, we do not always set any other environment variables Fixes #1142 ## How was it tested? issue from #1142 is fixed: ``` > devbox run -- iex -S mix * creating .nix-mix/archives/hex-2.0.6 * creating .nix-mix/elixir/1-14/rebar3 Resolving Hex dependencies... Resolution completed in 0.016s Unchanged: cowboy 2.9.0 cowlib 2.11.0 ranch 1.8.0 All dependencies are up to date Erlang/OTP 25 [erts-13.2.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] Hello World! Interactive Elixir (1.14.4) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> Goodbye World 17:18:09.349 [notice] Application elixir_hello exited: shutdown BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution ``` - [ ] testscripts should pass
Summary
Motivation
In elixir projects,
iex -S mix <script>
has theiex
interpreter invoking themix
build tool. However, themix
build tool has been wrapped by devbox in a bash script.And this leads to a failure as
iex
is unable to interpret a bash script.Fix
Binaries should be able to directly invoke other installed binaries.
We implemented the binary-wrappers so that the shell-environment is correctly
configured prior to the installed binary being invoked. In this case, the
iex
binary wrapper will run thereby correctly configuring the environment. Any subsequent
binary invoked in the same sub-shell will inherit this up-to-date environment. So,
the other binaries can be directly invoked (instead of the binary-wrapper scripts).
Implementation
In this PR, we change the
PATH
that is set within a binary-wrapper.Specifically, the
PATH
has the form:Within the binary-wrapper, we now omit the
.wrappers/bin
directory from PATHby using a new hidden flag
--omit-wrappers-from-path
ondevbox shellenv
.perf analysis
I expect the perf impact to be minimal.
Speed up: Binaries invoking other binaries will be a bit faster since they no longer first execute the binary-wrapper.
Slowdown: we remove one layer of caching. Previously, we'd check the shellenv-hash in the binary wrapper, and skip invoking
devbox shellenv
if the hash was up-to-date. Now, on every invocation of a binary-wrapper we'll calldevbox shellenv
. This should still be fast due to the internal caching we do withindevbox shellenv
.Fixes #1142
How was it tested?
BEFORE: doing
devbox run -- iex -S mix
would result in the error in the linked issue.AFTER:
Also - did test plan of #1093 to verify
devbox update
continues working. A sanity check since we dropped ShellEnvHash from the wrappers and I wanted to ensure this works as expected.