spin
spin copied to clipboard
Recognize `.env` for config in dev/testing
@fibonacci1729 — would you mind expanding a bit on the context for this issue?
Thanks!
When developing / running a Spin application, it would be convenient to source a .env file to construct the environment constants that will be made available to the application through the environment configuration provider.
For example, in the directory containing a Spin application:
some-app/
...
.env
spin.toml
Where some-app/.env contains:
FOO="BAR"
FOO will made available to the application through the SDK, e.g.
let val = spin_sdk::config::get("FOO")?;
assert_eq!(val, "BAR".to_string());
Are these variables that you don't want to set in spin.toml (which might be in source control)?
Yep, that is correct.
Unassigning myself for now as i'm not actively working on this just yet and don't want to issue squat.
Hi @fibonacci1729 , for this feature, is it about adding a dotenv provider? Or any config from .env can take priority over providers so that we can check it in get_config function before calling self.resolver.resolve?
@FrankYang0529 I think this can be as simple as:
If .env relative to spin.toml exists then source it
@FrankYang0529 would you be interested in #661 instead? It's slightly more involved (you get to implement a config provider) but still reasonably simple.
@fibonacci1729 actually, I would like to take these two. If it's okay, feel free to assign them to me. 😆
I have another question for .env. If there is a variable in .env but not defined in spin.toml, do we allow users to get the value?
Great question! We wouldn't want to allow getting the value if it's not defined in spin.toml.