From df624631515e8c0161a50fbae4a4e303b0085574 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 17 Feb 2025 11:19:12 +0700 Subject: [PATCH] fix: frontend env --- Services/Dockerfile | 11 ++++++++++- Services/client/src/services/KeyCloakService.ts | 6 +++--- Services/entrypoint.sh | 10 ++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 Services/entrypoint.sh diff --git a/Services/Dockerfile b/Services/Dockerfile index 5969092..7f458eb 100644 --- a/Services/Dockerfile +++ b/Services/Dockerfile @@ -23,6 +23,11 @@ RUN pnpm run build FROM base AS client COPY ./client . ENV VITE_API_ENDPOINT="$API_ENDPOINT" + +ENV VITE_KC_REALM="VITE_KC_REALM" +ENV VITE_KC_URL="VITE_KC_URL" +ENV VITE_CLIENTID_KEYCLOAK="VITE_CLIENTID_KEYCLOAK" + RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile RUN pnpm run build @@ -32,4 +37,8 @@ COPY --from=build /app/dist /app/dist COPY --from=server /app/static /app/static COPY --from=client /app/dist /app/static -CMD ["node", "./dist/app.js"] +COPY ./entrypoint.sh ./entrypoint.sh + +RUN chmod u+x ./entrypoint.sh + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/Services/client/src/services/KeyCloakService.ts b/Services/client/src/services/KeyCloakService.ts index a635452..4d5a2fb 100644 --- a/Services/client/src/services/KeyCloakService.ts +++ b/Services/client/src/services/KeyCloakService.ts @@ -1,9 +1,9 @@ import Keycloak from 'keycloak-js' const keycloak = new Keycloak({ - realm: import.meta.env.KC_REALMS, - url: import.meta.env.KC_URL, - clientId: 'edm', + realm: import.meta.env.VITE_KC_REALM, + url: import.meta.env.VITE_KC_URL, + clientId: import.meta.env.VITE_CLIENTID_KEYCLOAK, }) let init = false diff --git a/Services/entrypoint.sh b/Services/entrypoint.sh new file mode 100644 index 0000000..a628afd --- /dev/null +++ b/Services/entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +for file in /app/static/assets/*.js +do + sed -i 's|VITE_KC_REALM|'${VITE_KC_REALM}'|g' $file + sed -i 's|VITE_KC_URL|'${VITE_KC_URL}'|g' $file + sed -i 's|VITE_CLIENTID_KEYCLOAK|'${VITE_CLIENTID_KEYCLOAK}'|g' $file +done + +node ./dist/app.js