Comments (5)
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)
from dagger.
Note that none of the above works if "myenv" properties have default values (see #51 )
from dagger.
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:
env: {
inject: {
foo: string | *"default foo \"\n"
bar: string | *""
}
}
Script:
readonly root="$(cd "$(dirname "${BASH_SOURCE[0]:-$PWD}")" 2>/dev/null 1>&2 && pwd)"
readonly cuepack="$root"/dagger
# Prepare arguments
args=(compute "$cuepack")
# Extract properties from cue under the "env" struct, and iterate
readonly CUE_ENV_KEY="env"
while read -r key; do
# If there is a corresponding environment variable by that name that is defined
if [ "${!key+x}" ]; then
# Evaluate and escape it
args+=(--input "$(printf "%s" "$CUE_ENV_KEY" | tr "." ":"): resolve: $key: \"$(printf "%s" "${!key}" | sed -E 's/"/\\"/')\"")
else
# If not there, grab the resolved default from cue
override="$(cd "$cuepack"; cue eval --expression "env.inject.$key" --out json)"
args+=(--input "$(printf "%s" "$CUE_ENV_KEY" | tr "." ":"): resolve: $key: $override")
fi
done < <(cd "$cuepack"; cue eval --expression "${CUE_ENV_KEY}.inject" --out json | jq -rc 'keys | .[]')
# Add remaining command-line arguments
args+=("$@")
dagger "${args[@]}"
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.resolve
in your script...
from dagger.
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=PATH
could parse a standard envfile into a cue map.
For example:
$ cat prod.env
PROD=1
SSL=ENABLED
ANALYTICS_KEY=BLABLABLA
$ dagger compute . —input-envfile api.env=./prod.env —input-string api.env.USER=dubondubonney
In this example, the resulting input would be:
api: env: {
PROD: “1”
SSL: “ENABLED”
ANALYTICS_KEY: “BLABLABLA
USER: “dubondubonney”
}
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.
from dagger.
Closing this since it’s not directly actionable. Happy to resume the conversation in a github discussion if needed.
from dagger.
Related Issues (20)
- A config file for my modules HOT 1
- Fix module name conflicts with core types
- dagger mod init fails with confusing error message when there is already a go.mod HOT 4
- `.Export` partially transfers files and then gets stuck HOT 2
- CLI: support for `-o` flag HOT 1
- CLI: improve display of core API in `--help` and `dagger functions` output HOT 1
- CLI: update handling of various core types
- CLI: decide whether to support `id` or to continue hiding HOT 1
- CLI: enable `shell` and `up` functionality as chainable APIs
- engine: cannot enter cgroupv2 HOT 5
- Support core types implementing interfaces
- Go SDK: support objects from a user's module being passed as interface values
- Handle conflicts between user-defined fields and interface conversion `As* fields
- Document that changing secrets doesn't invalidate the cache HOT 5
- 🐞 Optional type in module field yields error HOT 1
- Update buildkit past ca71a44
- ✨ Allow pulling refs from a git repo HOT 2
- 🐞 Panic during cache export HOT 1
- 🐞 Zenith: Using secrets in SDKs results in error after re-run from cache
- 🐞 dagger export --output <mydir> doesn’t repect umask when creating <mydir> if it doesn’t already exist
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dagger.