-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3977: feat: allow setting arbitrary runtime env vars in the web container r=sprutton1 a=sprutton1 Vite forces you to use env vars for config and then also forces you to set them at build time. This is some hot, hot garbage. This library allows us to pull in arbitrary env vars. We also then do some string replacement when starting the container so we can have dynamic config in the different environments. <img src="https://media2.giphy.com/media/5MZcPvGU7HuvDbLCPg/giphy.gif"/> Co-authored-by: Scott Prutton <[email protected]>
- Loading branch information
Showing
7 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
type ProjectEnvVariablesType = Pick< | ||
ImportMetaEnv, | ||
"VITE_OTEL_EXPORTER_OTLP_ENDPOINT" | ||
>; | ||
|
||
// We must use `${}` so this variable gets replaced in the docker container | ||
const projectEnvVariables: ProjectEnvVariablesType = { | ||
VITE_OTEL_EXPORTER_OTLP_ENDPOINT: "${VITE_OTEL_EXPORTER_OTLP_ENDPOINT}", // eslint-disable-line no-template-curly-in-string | ||
}; | ||
|
||
// Returning the variable value from runtime or obtained as a result of the build | ||
export const getProjectEnvVariables = (): { | ||
envVariables: ProjectEnvVariablesType; | ||
} => { | ||
return { | ||
envVariables: { | ||
VITE_OTEL_EXPORTER_OTLP_ENDPOINT: | ||
!projectEnvVariables.VITE_OTEL_EXPORTER_OTLP_ENDPOINT.includes("VITE_") | ||
? projectEnvVariables.VITE_OTEL_EXPORTER_OTLP_ENDPOINT | ||
: import.meta.env.VITE_OTEL_EXPORTER_OTLP_ENDPOINT, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/// <reference types="vite/client" /> | ||
|
||
interface ImportMetaEnv { | ||
readonly VITE_OTEL_EXPORTER_OTLP_ENDPOINT: string; | ||
} | ||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters