Inject config into app #4747
Replies: 4 comments 3 replies
-
Secrets / env vars in CI / PRODAnother way to get the environment variables in CI / PROD would be to use nest-secrets in our infrastructure, which does decouple it nicely. It does get all the values, so it might be worth thinking about what values we want from Parameter store. |
Beta Was this translation helpful? Give feedback.
-
Working locallyAs much as creating the
|
Beta Was this translation helpful? Give feedback.
-
This has been implemented here with an ADR explaining what was done. Fabulous. |
Beta Was this translation helpful? Give feedback.
-
We implemented dotenv, but then moved to allowing certain values to certain properties through to the image resizing service. |
Beta Was this translation helpful? Give feedback.
-
Motivation
Proof of concept PR
Currently we receive a set of images from the
frontend
API with a list of fixed sizes. This is OK, but doesn't give us the freedom to truly optimise how we serve images to readers.To serve images from DCR directly, we would need to embed config into the app. The current recommendation is to use AWS Parameter store. We have a recommended way of using these in Scala, but not Node.
There are a number of ways to do this, these are outlines below.
We should choose a way to move forward with. Any learning can be shared upwards and possibly added to the recommendations.
Options
Use
.env
We could use a script, similar to something similar to what we already have to fetch AWS parameters, and create a
.env
file from this.Dev flow:
.env
file.env
file.env
into app (probably via webpack)✅ - requires AWS creds once on generation
✅ - supports multiple environments
✅ - easily inject via dotenv, or webpack-dotenv
❓- Is this something we should use in CI and prod as it creates a plain text file with secrets in?
❓- If ☝️ isn't recommended, would we have to have this, and CI, and prod implementations to support?
❓- is this what
.env
is for, normally it's for having values that are different between environments?Fetch values, and inject on
start
On
start
, we could fetch the values with something similar to what we already have to fetch AWS parameters, and add them to the app from memory, probably via webpack.❌ - requires AWS creds every start
✅ - supports multiple environments
✅ - doesn't require us to create a file exposing values
Combo of
.env
locally andfetch
on prod/CIWe could use the
.env
solution locally to avoid having to have creds all the time, and use the fetch into memory for CI prod for security. We currently split on how we do DEV and other environments for DevX reason, so that's not unconventional.✅ - requires AWS creds once on generation locally
✅ - supports multiple environments
✅ - doesn't require us to create a file exposing values
❌ - might slow down start time (it's AWS though, which is fast)
Fallback
We would want to support running the project without
.env
. We should fallback to something that would prtect us from someone spamming the image optimizer, but allow for the page to render acceptably in DEV.Beta Was this translation helpful? Give feedback.
All reactions