-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for additional env var files #9961
Conversation
Agree, with your copy changes 👍 Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
@jtoar highlighted to me that this PR currently only changes how the main CLI entry point loads the env files. We also need to change how this is handled when deploying a RW app. So need to look into our different deploy providers and also our Dockerfile support. |
I just now randomly found out there's some prior art on the flag naming with node's v20.6.0 release: https://nodejs.org/en/blog/release/v20.6.0
There are also some good discussions in the related PR nodejs/node#48890 |
So what we could do, to keep that same naming convention, and also get around the "how do we let people know that it's additive?" question. Plus make it really easy to not load Thoughts? Reactions? |
As I am reading thought the discussions from #9877 and the comments here, I definitely am longing for a docs section in CLI commands to help me understand a few things:
I glanced through the Pr and not sure I saw or not, but as will anything envier or config related, I as a developer would want to know with 100% confidence what my envars are. I would hate to think I was using one db connection and in fact using another and break production. So:
On a side note, during the roadmap discussion we considered having better secrets management and https://github.com/Infisical/infisical was mentioned as an OSS secrets manager. |
All valid concerns!
|
|
FWIW, when starting the NextJS dev server they print the list of loaded .env files (but not the actual env vars)
Our own baremetal deploy provider uses
Yes. True. But only if you start modifying what env files you want to load. By default (not passing any
I think @dthyresson's point was if you unknowingly included two files that both have |
I've asked @jtoar to take lead on moving this PR forward next week. I definitely want |
We definitely want to keep loading |
This reverts commit c7a19d3.
I'm not sure that it's the best call to name the flag the same thing as the runtime's flag when their behaviors aren't one-to-one. The way the functionality works now, it's additive, so without bikeshedding too much some variation on "include" seems fitting. I've updated it to A few more notes on some changes:
|
Fixes #9877 Adds a new middleware step to the CLI booting up, which looks for `--include-env` and includes `.env.[file]` to the list of files to look at. Also generally adds a .env var based on the `NODE_ENV` - I could take this or leave it, but I was in the space. ![image](https://github.com/redwoodjs/redwood/assets/49038/267c9f8d-0b4d-4c83-8607-712b837e3cfc) --------- Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com> Co-authored-by: Dominic Saadi <dominiceliassaadi@gmail.com>
…onsolidate-vite-settings-rsc-builds * 'feat/rsc-build' of github.com:dac09/redwood: (34 commits) Add support for additional env var files (redwoodjs#9961) Revert startsWith change Remove outdated todo comment. And other comment formatting no more 'as string', and startsWith instead of includes innerText Update studio.md (redwoodjs#10062) doc comment formatting node-loader should look in distRsc now, not distServer Remove `serve` from test fixture Code comment tweaks/fixes Update some more comments Remove duplicated file Lint Another rename of build functions Fix paths test with new paths Rename build functions Tobbe review changes Apply suggestions from code review chore(rename): Be consistent with 'for' prefix for babel plugin option (redwoodjs#10059) RSC: Remove commented code from worker (redwoodjs#10058) ...
Follow up to #9961. Got some feedback from @cannikin and @Josh-Walker-GM. There are still some things I need to clarify, but the changes here are improvements, and we'll keep iterating before this goes out next week (currently in the v7.1 RC): - the name was shortened from `--include-env-files` to `--add-env-files` - `.env` files that are loaded based on `NODE_ENV` override instead of add - the logic was moved up from middleware because env loading should be done as soon as possible, and the earliest is right after we set the cwd I'll bring up the override vs at the next meeting. Just to document what currently happens to completeness, env files are loaded in two steps... #### Layer 1 - `.env.defaults` - `.env` - `.env.${NODE_ENV}` These are loaded in an overriding manner, so that if there are conflicts, `.env.${NODE_ENV}` has the final say. This can't be disabled. #### Layer 2 If users want, they can add more via `--add-env-file`, like `--add-env-file stripe`. The env vars loaded from files specified this way are additive—they won't override anything already set in the first layer. I'll see about moving this functionality out of the CLI package and into CLI helpers so its shareable in another PR.
Follow up to #9961. Got some feedback from @cannikin and @Josh-Walker-GM. There are still some things I need to clarify, but the changes here are improvements, and we'll keep iterating before this goes out next week (currently in the v7.1 RC): - the name was shortened from `--include-env-files` to `--add-env-files` - `.env` files that are loaded based on `NODE_ENV` override instead of add - the logic was moved up from middleware because env loading should be done as soon as possible, and the earliest is right after we set the cwd I'll bring up the override vs at the next meeting. Just to document what currently happens to completeness, env files are loaded in two steps... #### Layer 1 - `.env.defaults` - `.env` - `.env.${NODE_ENV}` These are loaded in an overriding manner, so that if there are conflicts, `.env.${NODE_ENV}` has the final say. This can't be disabled. #### Layer 2 If users want, they can add more via `--add-env-file`, like `--add-env-file stripe`. The env vars loaded from files specified this way are additive—they won't override anything already set in the first layer. I'll see about moving this functionality out of the CLI package and into CLI helpers so its shareable in another PR.
Last change before releasing the minor. This wraps up the env files feature started in #9961. To recap on the naming decision a bit, we can't use just "--env-file" because Node.js seems to parse it no matter what, and since Redwood's flag operates on suffixes, Node throws a "not found" error. It also seems to parse "--env-files", with an "s", which seems like a bug. I opted for "--add-env-files" back when this flag only added additional env vars, which didn't override existing ones. This is no longer the case (they override), so I don't want to imply that they don't. "--load-env-files" seems like the best alternative, and there's a precedence in the work done in Node.js here which exposes a new `loadEnvFile` function: nodejs/node#51476.
Last change before releasing the minor. This wraps up the env files feature started in #9961. To recap on the naming decision a bit, we can't use just "--env-file" because Node.js seems to parse it no matter what, and since Redwood's flag operates on suffixes, Node throws a "not found" error. It also seems to parse "--env-files", with an "s", which seems like a bug. I opted for "--add-env-files" back when this flag only added additional env vars, which didn't override existing ones. This is no longer the case (they override), so I don't want to imply that they don't. "--load-env-files" seems like the best alternative, and there's a precedence in the work done in Node.js here which exposes a new `loadEnvFile` function: nodejs/node#51476.
Fixes #9877
Adds a new middleware step to the CLI booting up, which looks for
--include-env
and includes.env.[file]
to the list of files to look at.Also generally adds a .env var based on the
NODE_ENV
- I could take this or leave it, but I was in the space.