From 37334ccdfc2c9beda8a2513cfce7bab7aca21aa0 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Fri, 2 Aug 2024 15:47:09 +0200 Subject: [PATCH] fix: add frontend dynamic env using nginx ssi --- packages/frontend-usagers/Dockerfile | 33 ++++++++++++---------------- packages/frontend-usagers/nginx.conf | 10 +++++++++ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/frontend-usagers/Dockerfile b/packages/frontend-usagers/Dockerfile index 314b9fb51..c73bd33d4 100644 --- a/packages/frontend-usagers/Dockerfile +++ b/packages/frontend-usagers/Dockerfile @@ -13,30 +13,25 @@ COPY packages/frontend-usagers/package.json packages/frontend-usagers/yarn.lock RUN yarn workspace @vao/frontend-usagers install --frozen-lockfile # these variables are needed at build time because we produce a *static* app -ARG NUXT_PUBLIC_APP_VERSION=development -ARG NUXT_PUBLIC_BACKEND_URL -ARG NUXT_PUBLIC_ENVIRONMENT -ARG NUXT_PUBLIC_MATOMO_ENABLED -ARG NUXT_PUBLIC_MATOMO_HOST -ARG NUXT_PUBLIC_MATOMO_SITE_ID -ARG NUXT_PUBLIC_SENTRY_DSN -ARG NUXT_PUBLIC_SENTRY_RELEASE -ARG NUXT_PUBLIC_SENTRY_ENABLED + ARG SENTRY_ORG ARG SENTRY_PROJECT ARG SENTRY_URL ARG SENTRY_AUTH_TOKEN -ENV NUXT_PUBLIC_APP_VERSION=$NUXT_PUBLIC_APP_VERSION -ENV NUXT_PUBLIC_BACKEND_URL=$NUXT_PUBLIC_BACKEND_URL -ENV NUXT_PUBLIC_ENVIRONMENT=$NUXT_PUBLIC_ENVIRONMENT -ENV NUXT_PUBLIC_MATOMO_ENABLED=$NUXT_PUBLIC_MATOMO_ENABLED -ENV NUXT_PUBLIC_MATOMO_HOST=$NUXT_PUBLIC_MATOMO_HOST -ENV NUXT_PUBLIC_MATOMO_SITE_ID=$NUXT_PUBLIC_MATOMO_SITE_ID -ENV NUXT_PUBLIC_SENTRY_DSN=$NUXT_PUBLIC_SENTRY_DSN -ENV NUXT_PUBLIC_SENTRY_RELEASE=$NUXT_PUBLIC_SENTRY_RELEASE -ENV NUXT_PUBLIC_SENTRY_ENABLED=$NUXT_PUBLIC_SENTRY_ENABLED -ENV SENTRY_RELEASE=$NUXT_PUBLIC_SENTRY_RELEASE +# Runtime env variables set by Nginx injection +ENV NUXT_PUBLIC_APP_VERSION=ENV_NUXT_PUBLIC_APP_VERSION +ENV NUXT_PUBLIC_BACKEND_URL=ENV_NUXT_PUBLIC_BACKEND_URL +ENV NUXT_PUBLIC_ENVIRONMENT=ENV_NUXT_PUBLIC_ENVIRONMENT +ENV NUXT_PUBLIC_MATOMO_ENABLED=ENV_NUXT_PUBLIC_MATOMO_ENABLED +ENV NUXT_PUBLIC_MATOMO_HOST=ENV_NUXT_PUBLIC_MATOMO_HOST +ENV NUXT_PUBLIC_MATOMO_SITE_ID=ENV_NUXT_PUBLIC_MATOMO_SITE_ID +ENV NUXT_PUBLIC_SENTRY_DSN=ENV_NUXT_PUBLIC_SENTRY_DSN +ENV NUXT_PUBLIC_SENTRY_ENABLED=ENV_NUXT_PUBLIC_SENTRY_ENABLED + +# Cannot be changed at runtime +ENV NUXT_PUBLIC_SENTRY_RELEASE=$SENTRY_RELEASE +ENV SENTRY_RELEASE=$SENTRY_RELEASE ENV SENTRY_ORG=$SENTRY_ORG ENV SENTRY_PROJECT=$SENTRY_PROJECT ENV SENTRY_URL=$SENTRY_URL diff --git a/packages/frontend-usagers/nginx.conf b/packages/frontend-usagers/nginx.conf index 61fe308ba..0d16bd6aa 100644 --- a/packages/frontend-usagers/nginx.conf +++ b/packages/frontend-usagers/nginx.conf @@ -48,6 +48,16 @@ http { location / { # this always fallback on /index.html, never 404 try_files $uri $uri.html $uri/index.html $uri/ /index.html; + + ssi on; + set $ENV_NUXT_PUBLIC_APP_VERSION "$ENV_NUXT_PUBLIC_APP_VERSION"; + set $ENV_NUXT_PUBLIC_BACKEND_URL "$ENV_NUXT_PUBLIC_BACKEND_URL"; + set $ENV_NUXT_PUBLIC_ENVIRONMENT "$ENV_NUXT_PUBLIC_ENVIRONMENT"; + set $ENV_NUXT_PUBLIC_MATOMO_ENABLED "$ENV_NUXT_PUBLIC_MATOMO_ENABLED"; + set $ENV_NUXT_PUBLIC_MATOMO_HOST "$ENV_NUXT_PUBLIC_MATOMO_HOST"; + set $ENV_NUXT_PUBLIC_MATOMO_SITE_ID "$ENV_NUXT_PUBLIC_MATOMO_SITE_ID"; + set $ENV_NUXT_PUBLIC_SENTRY_DSN "$ENV_NUXT_PUBLIC_SENTRY_DSN"; + set $ENV_NUXT_PUBLIC_SENTRY_ENABLED "$ENV_NUXT_PUBLIC_SENTRY_ENABLED"; } location /50x.html {