Repository navigation
Closed
Description
The current --input mechanism is very satisfying - flexible and powerful.
Although, injecting environment variables is a bit cumbersome and requires some serious shell gymnastic.
Typically, if I have a cue file like this:
myenv: {
foo: string | *"foo"
bar: string | *"bar"
baz: string | *"baz"
ble: string | *"ble"
lol: string | *"lol"
}
foo: dagger: #compute: {
// lalalala
}
And if I want to be able to override "myenv" with corresponding environment variables, I will have to write a shell script in the line of:
envs=()
while read -r line; do
if [ "${!line+x}" ]; then
# mind the step!
envs+=(--input "myenv: $line: \"$(printf "%s" "${!line}" | sed -E 's/"/\\"/')\"")
fi
done <<<"foo
bar
baz
ble
lol"
dagger compute gros_cue "${envs[@]}" "$@"
Sure, it's "doable", but:
- mere mortals will likely find it challenging to come up with the above (you have to: 1. check if the variable is defined or not, then 2. evaluate it, and 3. escape it properly, which is not that trivial)
- if you want something nice like here and maintainable, you have to basically duplicate the list of "vars" you are interested in, on the cue side, and inside a wrapper script (I'm certainly not going to type the above ^^^ on the command line every time I want to run my stuff)
So, would you be open considering some additional sugar to ease things up?
Maybe it could be something like:
dagger compute cue --bind-env 'myenv'
The behavior would be exactly the same I have above ^:
- for each property listed on the cue side under myenv, check if an environment variable by that name is defined or not
- if it's defined, escape it and inject it into cue land under myenv
This proposal seem to alleviate both:
- duplication / cost of maintenance
- newcomer bear trap
wdyt?
Metadata
Metadata
Assignees
Labels
No labels
Activity
dubo-dubon-duponey commentedon Jan 19, 2021
By the way, my wrapper script above will fail if none of the environment variables are defined (kind of proving my point that it is challenging to get it right, even for jedi-master-extraordinaire-shell-hackers like me :D :D :D)
dubo-dubon-duponey commentedon Jan 19, 2021
Note that none of the above works if "myenv" properties have default values (see #51 )
dubo-dubon-duponey commentedon Jan 19, 2021
Ok, this is the complete form of what you have to do right now to get environment nicely merged into a cue struct that has default values (accounting for #51)
Cue:
Script:
Now, you have what you want under "env: resolve:"
Not the friendliest thing ever :p
Alternatively, in the spirit of doing everything inside dagger, one could just
--input "env: \"$(env | base64)\""on the shell script side and do all the donkey dancing inside the cue file with an exec.UPDATE: actually, this does not seem to work - because input is handled too late, you cannot use any of
env.resolvein your script...shykes commentedon Jan 30, 2021
I think it’s reasonable for client scripts to have an easy way to pass a pre-existing key-value map without having to enumerate each key in the command-line args passed to dagger. Did I summarize the requirement correctly?
I think the cleanest way to do this would be with an env file. For example
dagger compute —input-envfile TARGET=PATHcould parse a standard envfile into a cue map.For example:
In this example, the resulting input would be:
The best part is you can source the env file straight from your shell script to avoid duplication.
I like this approach because it allows us to not deal with environment variables at all. In my experience once you make environment variables a part of your API and UI, the user experience is made worse by the inevitable appearance of side effects which are hard to detect, painful to reproduce, and impossible to prevent.
shykes commentedon Apr 29, 2021
Closing this since it’s not directly actionable. Happy to resume the conversation in a github discussion if needed.
feat: add musl ci (#51)