-
Notifications
You must be signed in to change notification settings - Fork 191
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
Simple change to support shell hooks #45
Conversation
@venkytv Thanks for sending. Could you help me understand the use-case a tiny bit more? An example On the multi-line strings: I've considered letting people pick the format of the config file (i.e. if instead of having a |
@loreto Sure. Essentially, a dev environment for us also includes setting a few environment-specific parameters, typically environment variables. A sample
So, a $ devbox shell
$ echo $MYPARAM
something (Just noticed #42 which is requesting something similar to this.) I could use direnv for this of course, but having it in And yes, YAML especially would be perfect for this as it has multiple ways to represent multiline strings! By the way, I noticed that I have corrupted the PR with some additional commits I pushed into my fork after I submitted this. Do let me know if you want to include this, and I will clean up the commits and re-submit it. Thanks again for this very useful tool! |
Thanks @venkytv! One thing we should be aware of (and somewhat related to #15) is that devbox currently runs two shells:
If we implement something like this, we'd probably want to run the hooks inside the 2nd shell (which should be possible after I finish the work in #15) or limit it to exported env vars to avoid confusion. |
@venkytv One more question for you. I open to the hook idea – I think it can be useful for some advanced use cases. That said, for setting env variables, I was also thinking that, if there's a |
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 personally really like this idea since I need it too myself, and this is a great way to get some quick ENV, iterm display, aws credentials, etc config setup. Bravo! I'm also open to the .env
idea, but I find that a bit restricting. Curious to hear your thoughts.
I wonder if for multi-lines shell hook, we recommend developers to put them in a script such as shell.sh
and reference the script that way? So devbox.json may look like this
{
"packages": [
"python3"
],
"shell-hook": "./shell.sh"
}
@@ -91,7 +91,8 @@ func (d *Devbox) Build(opts ...docker.BuildOptions) error { | |||
// environment. | |||
func (d *Devbox) Plan() *planner.BuildPlan { | |||
basePlan := &planner.BuildPlan{ | |||
Packages: d.cfg.Packages, | |||
Packages: d.cfg.Packages, | |||
ShellHook: d.cfg.ShellHook, |
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'm assuming ShellHook
is only applicable on devbox shell
command, and not devbox build
?
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.
@LucilleH Plan
is currently called by both devbox shell
and devbox build
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.
@loreto sorry to clarify, will/should the shell hook be called in the Dockerfile as well? (I lean more towards .env in this case)
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.
It won't run because there's nothing that executes it. This behaves as you want. I'm just saying the same struct that includes the hook is passed to both shell and build.
@loreto That would work too, but I prefer the idea of having one file that contains everything the environment needs. The instructions to use it would be as simple as "download this devbox.yaml file and run The same goes for including a separate file and calling that from the |
Awesome! Thank you. |
Summary
A simple change to support custom shell hooks. This is something I often need and currently use direnv for, but I find it convenient to have the configuration within
devbox.json
.Fully understand if you decide not to pull this in. :) This is just a very quick hack, and in general, JSON is not that great a fit for storing multi-line strings. But I find devbox very useful, and this feature makes it a bit more useful for me.
How was it tested?
go build
go test
devbox init
devbox shell