mise icon indicating copy to clipboard operation
mise copied to clipboard

Support multiple `env_file`

Open noirbizarre opened this issue 1 year ago • 6 comments

Hi 👋🏼

Would it be possible to support multiple env_file in .rtx.toml ? This is the only thing preventing me to switch from direnv + rtx to rtx only.

I have mostly 3 recurrent use cases:

  • personnal + team env file: project provide a team .env in the repository but you can add your own with .env.local or whatever name you want
  • split between common .env and encrypted credentials in a .env.secret
  • project .env plus an extra cli generated env file to source if present (ex: telepresence intercept generate a kubernetes cluster env file to source when connected)

The idea would be to support both single string and list of strings as env_file value in .rtx.toml to keep backward compatibily so this 2 syntaxes should be supported:

env_file = ".env"
env_file = [
  ".env",
  "secrets.env",
  "telepresence.env",
]

Env files should be applied in order (last file variables override previous ones)

Is this something acceptable ? Does someone want to do it or can I submit it as a contribution ?

noirbizarre avatar May 23 '23 10:05 noirbizarre

can you just use Config Environments?

jdx avatar May 23 '23 11:05 jdx

Not really. Config environments do cascade overrides on the rtx configuration so the env_file property is just overridden, but you still load only one file while I want to load them all together.

Given I already look at it, it reminds me a good point I forgot to tell: combining this feature request with config environments would also allow for:

  • local environment override from dotenv file
  • profile environment override from dotenv file

This is not possible for the moment because whatever rtx setup you are in, only the last overridden env_file is loaded.

To be perfect, I would love the env_file property to be failsafe, because it is currently failing and preventing rtx to load if the dotenv file is missing:

error reading config: /path/to/project/.rtx.toml
failed to parse dotenv file: /path/to/.env
No such file or directory (os error 2)

If this is OK for you, I would love to try contributing this (unless you prefer to).

noirbizarre avatar May 23 '23 13:05 noirbizarre

Not really. Config environments do cascade overrides on the rtx configuration so the env_file property is just overridden, but you still load only one file while I want to load them all together.

I do not think this is true, if it is then that is a bug.

jdx avatar May 23 '23 14:05 jdx

that said, I would accept a PR for making this an array

jdx avatar May 23 '23 14:05 jdx

Not really. Config environments do cascade overrides on the rtx configuration so the env_file property is just overridden, but you still load only one file while I want to load them all together.

I do not think this is true, if it is then that is a bug.

OMG, your are right ! It is actually in case of error only (only one of the missing env file is reported missing) but this work as soon as you have all the env file present 🎉

I will do a few testing and then submit a PR if I believe this is still required or bringing extra value (I think I will at least submit the failsafe part)

noirbizarre avatar May 23 '23 15:05 noirbizarre

it's possible error handling could be improved. I think what should happen is it should gather all of the errors of parsing all of the config files and print them out one by one but it is probably exiting when it encounters the first one

jdx avatar May 23 '23 17:05 jdx