-
Notifications
You must be signed in to change notification settings - Fork 1
Read VITE config from runtime env in Docker image #82
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
Merged
+163
−8
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6ef597c
docker env config
cleot 6d7f776
push test image
cleot 783861a
remove test trigger
cleot 7ecdc8b
add assertions
cleot 8c5199f
add export, lint warning
cleot 362de10
optimize config script
cleot 2771e1f
add test for env.ts
cleot e918e3d
minor fix
cleot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,13 @@ | ||||||||||||||||
| #!/usr/bin/env sh | ||||||||||||||||
| set -e | ||||||||||||||||
|
|
||||||||||||||||
| cat <<EOF > /usr/share/nginx/html/config.js | ||||||||||||||||
| window.__ENV__ = { | ||||||||||||||||
| VITE_API_BASE_URL: "${VITE_API_BASE_URL}", | ||||||||||||||||
| VITE_API_MOCKING_ENABLED: "${VITE_API_MOCKING_ENABLED}", | ||||||||||||||||
| VITE_KEYCLOAK_URL: "${VITE_KEYCLOAK_URL}", | ||||||||||||||||
| VITE_KEYCLOAK_REALM: "${VITE_KEYCLOAK_REALM}", | ||||||||||||||||
| VITE_KEYCLOAK_CLIENT_ID: "${VITE_KEYCLOAK_CLIENT_ID}", | ||||||||||||||||
| VITE_BITCR_DEV_INCLUDE_CROWDIN_IN_CONTEXT_TOOLING: "${VITE_BITCR_DEV_INCLUDE_CROWDIN_IN_CONTEXT_TOOLING}" | ||||||||||||||||
| } | ||||||||||||||||
cleot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||
| EOF | ||||||||||||||||
|
||||||||||||||||
| EOF | |
| EOF | |
| if [ ! -f /usr/share/nginx/html/config.js ]; then | |
| echo "Error: Failed to generate config.js" | |
| exit 1 | |
| fi |
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| window.__ENV__ = window.__ENV__ || {} |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import { env } from "@/lib/env" | ||
|
|
||
| export default { | ||
| devModeEnabled: import.meta.env.DEV, | ||
| apiBaseUrl: import.meta.env.VITE_API_BASE_URL as string, | ||
| apiMocksEnabled: import.meta.env.VITE_API_MOCKING_ENABLED === "true", | ||
| crowdinInContextToolingEnabled: import.meta.env.VITE_BITCR_DEV_INCLUDE_CROWDIN_IN_CONTEXT_TOOLING === "true", | ||
| devModeEnabled: env.devModeEnabled, | ||
| apiBaseUrl: env.apiBaseUrl, | ||
| apiMocksEnabled: env.apiMocksEnabled, | ||
| crowdinInContextToolingEnabled: env.crowdinInContextToolingEnabled, | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| type RuntimeEnv = Partial<{ | ||
| VITE_API_BASE_URL: string | ||
| VITE_API_MOCKING_ENABLED: string | ||
| VITE_KEYCLOAK_URL: string | ||
| VITE_KEYCLOAK_REALM: string | ||
| VITE_KEYCLOAK_CLIENT_ID: string | ||
| VITE_BITCR_DEV_INCLUDE_CROWDIN_IN_CONTEXT_TOOLING: string | ||
| }> | ||
|
|
||
| const runtimeEnv: RuntimeEnv = | ||
| typeof window !== "undefined" ? (window as { __ENV__?: RuntimeEnv }).__ENV__ ?? {} : {} | ||
|
|
||
| const fallbackEnv = import.meta.env as ImportMetaEnv & RuntimeEnv | ||
|
|
||
| const getEnvValue = <K extends keyof RuntimeEnv>(key: K): RuntimeEnv[K] | undefined => { | ||
| const value = runtimeEnv[key] | ||
|
|
||
| if (value !== undefined && value !== null && value !== "") { | ||
| return value | ||
| } | ||
|
|
||
| return fallbackEnv[key] | ||
| } | ||
|
|
||
| export const env = { | ||
| devModeEnabled: fallbackEnv.DEV, | ||
| apiBaseUrl: getEnvValue("VITE_API_BASE_URL") as string, | ||
| apiMocksEnabled: (getEnvValue("VITE_API_MOCKING_ENABLED") ?? "false") === "true", | ||
| keycloakUrl: getEnvValue("VITE_KEYCLOAK_URL") as string, | ||
| keycloakRealm: getEnvValue("VITE_KEYCLOAK_REALM") as string, | ||
| keycloakClientId: getEnvValue("VITE_KEYCLOAK_CLIENT_ID") as string, | ||
cleot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| crowdinInContextToolingEnabled: | ||
| (getEnvValue("VITE_BITCR_DEV_INCLUDE_CROWDIN_IN_CONTEXT_TOOLING") ?? "false") === "true", | ||
| } | ||
cleot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.