diff --git a/docker/dockerfiles/frontend.Dockerfile b/docker/dockerfiles/frontend.Dockerfile index 0c3fdcc92a..cf3a14ee5a 100644 --- a/docker/dockerfiles/frontend.Dockerfile +++ b/docker/dockerfiles/frontend.Dockerfile @@ -72,6 +72,11 @@ RUN sed -i 's|| \n < COPY frontend/generate-runtime-config.sh /docker-entrypoint.d/40-env.sh RUN chmod +x /docker-entrypoint.d/40-env.sh +# Capture build version at the very end so it doesn't affect layer caching. +# Empty default: the UI hides the version field when none was provided. +ARG VERSION="" +ENV UNSTRACT_APPS_VERSION=${VERSION} + EXPOSE 80 USER nginx diff --git a/frontend/generate-runtime-config.sh b/frontend/generate-runtime-config.sh index d79fa3c002..f3990091cb 100755 --- a/frontend/generate-runtime-config.sh +++ b/frontend/generate-runtime-config.sh @@ -5,11 +5,20 @@ # Generate the runtime-config.js file with the current environment variables # Note: Using VITE_ prefix for Vite compatibility, fallback to REACT_APP_ for backward compatibility + +# Escape backslashes and double quotes so values stay valid inside JS strings +js_escape() { + printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' +} + +APP_VERSION=$(js_escape "${UNSTRACT_APPS_VERSION:-}") + cat > /usr/share/nginx/html/config/runtime-config.js << EOF // This file is auto-generated at runtime. Do not modify manually. window.RUNTIME_CONFIG = { faviconPath: "${VITE_FAVICON_PATH:-${REACT_APP_FAVICON_PATH}}", - logoUrl: "${VITE_CUSTOM_LOGO_URL:-${REACT_APP_CUSTOM_LOGO_URL}}" + logoUrl: "${VITE_CUSTOM_LOGO_URL:-${REACT_APP_CUSTOM_LOGO_URL}}", + version: "${APP_VERSION}" }; EOF diff --git a/frontend/src/components/profile/Profile.jsx b/frontend/src/components/profile/Profile.jsx index 899110c777..aedf755e44 100644 --- a/frontend/src/components/profile/Profile.jsx +++ b/frontend/src/components/profile/Profile.jsx @@ -11,6 +11,7 @@ import { useNavigate } from "react-router-dom"; import "./Profile.css"; import { OrganizationIcon } from "../../assets"; +import config from "../../config"; import { useAxiosPrivate } from "../../hooks/useAxiosPrivate"; import { useAlertStore } from "../../store/alert-store.js"; import { useSessionStore } from "../../store/session-store.js"; @@ -234,6 +235,18 @@ function Profile() { )} + {config.version && ( +