Skip to content
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

Audit Web Environment Variables DX and Current Functionality #4503

Open
3 tasks
thedavidprice opened this issue Feb 16, 2022 · 6 comments
Open
3 tasks

Audit Web Environment Variables DX and Current Functionality #4503

thedavidprice opened this issue Feb 16, 2022 · 6 comments

Comments

@thedavidprice
Copy link
Contributor

Related to work on #4334 and #4461

cc @dac09

Discussion Topics

  • What is the DX we want for Web env var?
  • Should we consider .env.default for build (i.e. production deploy)

Deployment test

console.log(process.env.X) where X = ...:

  1. env var that isn’t defined anywhere
  2. env var that’s defined in hosting provider dashboard
  3. env var that’s defined in toml
  4. env var that has a prefix
  5. evn var that’s in env.default

Goals:

  • Define the optimal DX working with Web env vars across local and production contexts
  • Audit 1) current behavior of env var handling for deployment and 2) documentation for using Web env vars
  • Add CI (unit or functional?) to prevent regression

Deployed Test

NOTE:
As of now the only Env defined in the Netlify Dashboard is DOT_ENV

Need to add TOML_ARRAY and REDWOOD_ENV_PREFIX to Netlify deploy dashboard environment

Netlify Site

https://hardcore-mestorf-245ef2.netlify.app

GitHub Repo

https://github.com/redwoodjs/env-var-test

Home page:
https://github.com/redwoodjs/env-var-test/blob/main/web/src/pages/HomePage/HomePage.tsx

Local Test

yarn rw dev

Screen Shot 2022-02-16 at 11 55 28 AM

yarn rw serve (after building)

Screen Shot 2022-02-16 at 11 56 41 AM

@thedavidprice thedavidprice moved this to Todo in Release Feb 16, 2022
@thedavidprice thedavidprice moved this from Todo to In progress in Release Feb 16, 2022
@thedavidprice
Copy link
Contributor Author

@dac09 So far, it's all working in production according to docs.

However, I am confused as to why locally I can't access value when using .env.defaults — it was working, then I added a .env and then I could never get it working again even after git clean and deleting .env. Needs diagnosing.

I suspect once I add TOML_ARRAY and REDWOOD_ENV_PREFIX to Netlify dashboard they'll be working. But wanted to start here.

@Tobbe
Copy link
Member

Tobbe commented Feb 17, 2022

image

This is wrong, right? DOT_ENV should not exist, because it's neither in your toml nor prefixed with REDWOOD_ENV_

image

DOT_ENV is neither 1 nor 2, so should not be available to the web side (but it should be available to the api side)

That's how I'm interpreting the docs at least

@dac09
Copy link
Contributor

dac09 commented Feb 17, 2022

Precisely the problem I was pointing out @Tobbe - there's inconsistencies between how we're saying it should work, and how it actually does.

@thedavidprice
Copy link
Contributor Author

...in production...

The docs have always referred to production settings. Maybe not clearly enough.

Agree that the discrepancy is confusing.

@Tobbe
Copy link
Member

Tobbe commented Feb 17, 2022

Yes, in production. yarn rw serve is production, no? That's why I made a point of including your red "yarn rw serve" text when I used part of your screenshots.

For yarn rw dev I think your screenshot is correct.

Ohh, hmm, NODE_ENV set to production is the key here, right? I thought you used "yarn rw serve" to mean "deployed to my hosting provider". But you were running yarn rw serve locally too, right?

Deployed to Netlify it does look like it should

image

@virtuoushub
Copy link
Collaborator

virtuoushub commented Apr 20, 2022

To add some color here (I think this is the right place, if not apologies and will open a separate ticket), NODE_ENV being set to production can cause some undesirable behavior when building/deploying Storybook, specifically interaction testing (see: redwoodjs/example-storybook#32).

If I try and manually override this env var, bad things happen. Code such as that listed below makes it so Storybook builds only sometimes work in non production environments.

@jtoar jtoar added this to Main May 5, 2022
@jtoar jtoar moved this to Backlog in Main May 5, 2022
@jtoar jtoar removed this from Triage May 5, 2022
@jtoar jtoar moved this from Backlog to In Progress in Main May 5, 2022
@jtoar jtoar removed this from Release May 10, 2022
@jtoar jtoar moved this from In Progress to Backlog in Main May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

5 participants