spin icon indicating copy to clipboard operation
spin copied to clipboard

Recognize `.env` for config in dev/testing

Open fibonacci1729 opened this issue 3 years ago • 7 comments

fibonacci1729 avatar Jul 25 '22 15:07 fibonacci1729

@fibonacci1729 — would you mind expanding a bit on the context for this issue?

Thanks!

radu-matei avatar Aug 16 '22 03:08 radu-matei

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());

fibonacci1729 avatar Aug 16 '22 15:08 fibonacci1729

Are these variables that you don't want to set in spin.toml (which might be in source control)?

radu-matei avatar Aug 16 '22 15:08 radu-matei

Yep, that is correct.

fibonacci1729 avatar Aug 16 '22 15:08 fibonacci1729

Unassigning myself for now as i'm not actively working on this just yet and don't want to issue squat.

fibonacci1729 avatar Aug 16 '22 16:08 fibonacci1729

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 avatar Aug 17 '22 15:08 FrankYang0529

@FrankYang0529 I think this can be as simple as:

If .env relative to spin.toml exists then source it

fibonacci1729 avatar Aug 17 '22 21:08 fibonacci1729

@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 avatar Aug 18 '22 00:08 fibonacci1729

@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?

FrankYang0529 avatar Aug 18 '22 02:08 FrankYang0529

Great question! We wouldn't want to allow getting the value if it's not defined in spin.toml.

fibonacci1729 avatar Aug 18 '22 02:08 fibonacci1729