From e7ed43a21a3cdfa7b7e69a5f96ef35a0fc5fc7b1 Mon Sep 17 00:00:00 2001 From: Christoph Hoffmann Date: Fri, 17 May 2024 12:40:07 +0200 Subject: [PATCH] fix: use correct naming convention for public runtime config (#14) Co-authored-by: stefanprobst --- components/imprint.vue | 2 +- layouts/default.vue | 11 ++++------- nuxt.config.ts | 10 +++++----- readme.md | 11 +++++++++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/components/imprint.vue b/components/imprint.vue index f9eeba7..955dce0 100644 --- a/components/imprint.vue +++ b/components/imprint.vue @@ -5,7 +5,7 @@ const env = useRuntimeConfig(); const locale = useLocale(); -const redmineId = env.public.NUXT_PUBLIC_REDMINE_ID; +const redmineId = env.public.redmineId; const imprint = await useFetch(String(createImprintUrl(locale.value, redmineId)), { responseType: "text", diff --git a/layouts/default.vue b/layouts/default.vue index ac19dea..609507f 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -45,7 +45,7 @@ useHead({ property: "og:image", content: String( createUrl({ - baseUrl: env.public.NUXT_PUBLIC_APP_BASE_URL, + baseUrl: env.public.appBaseUrl, pathname: "/opengraph-image.png", }), ), @@ -68,17 +68,14 @@ useHead({ { type: "application/ld+json", innerHTML: JSON.stringify(jsonLd, safeJsonLdReplacer) }, ]; - if ( - isNonEmptyString(env.public.NUXT_PUBLIC_MATOMO_BASE_URL) && - isNonEmptyString(env.public.NUXT_PUBLIC_MATOMO_ID) - ) { - const baseUrl = env.public.NUXT_PUBLIC_MATOMO_BASE_URL; + if (isNonEmptyString(env.public.matomoBaseUrl) && isNonEmptyString(env.public.matomoId)) { + const baseUrl = env.public.matomoBaseUrl; scripts.push({ type: "", innerHTML: createAnalyticsScript( baseUrl.endsWith("/") ? baseUrl : baseUrl + "/", - env.public.NUXT_PUBLIC_MATOMO_ID, + env.public.matomoId, ), }); } diff --git a/nuxt.config.ts b/nuxt.config.ts index f8cf634..a57f113 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -75,11 +75,11 @@ export default defineNuxtConfig({ runtimeConfig: { NODE_ENV: process.env.NODE_ENV, public: { - NUXT_PUBLIC_APP_BASE_URL: process.env.NUXT_PUBLIC_APP_BASE_URL, - NUXT_PUBLIC_BOTS: process.env.NUXT_PUBLIC_BOTS, - NUXT_PUBLIC_MATOMO_BASE_URL: process.env.NUXT_PUBLIC_MATOMO_BASE_URL, - NUXT_PUBLIC_MATOMO_ID: process.env.NUXT_PUBLIC_MATOMO_ID, - NUXT_PUBLIC_REDMINE_ID: process.env.NUXT_PUBLIC_REDMINE_ID, + appBaseUrl: process.env.NUXT_PUBLIC_APP_BASE_URL, + bots: process.env.NUXT_PUBLIC_BOTS, + matomoBaseUrl: process.env.NUXT_PUBLIC_MATOMO_BASE_URL, + matomoId: process.env.NUXT_PUBLIC_MATOMO_ID, + redmineId: process.env.NUXT_PUBLIC_REDMINE_ID, }, }, typescript: { diff --git a/readme.md b/readme.md index 5d2fc82..db77cd4 100644 --- a/readme.md +++ b/readme.md @@ -46,7 +46,7 @@ pnpm run dev and set the `SERVICE_ID` github variable to the issue number. this should match the `NUXT_PUBLIC_REDMINE_ID` variable in your `.env.local` file. - ensure required build args (prefixed with `NUXT_PUBLIC_`) are referenced in both the - [`Dockerfle`](./Dockerfile), as well as the [validation](./.github/workflows/validate.yml) as + [`Dockerfile`](./Dockerfile), as well as the [validation](./.github/workflows/validate.yml) and [deployment](./.github/workflows/build-deploy.yml) pipelines, and set as github variables. - ensure required runtime environment variables are referenced in the [validation](./.github/workflows/validate.yml) and @@ -54,7 +54,14 @@ pnpm run dev secrets need to be prefixed with `K8S_SECRET_` to be automatically copied to the runtime environment. in case you need secrets in the docker build context, you can [mount a secret in the Dockerfile](https://docs.docker.com/build/building/secrets/). -- ensure both the github repository, as well as the +- To enable runtime override of public `runtimeConfig` build values through runtime env vars note + the + [naming conventions](https://nuxt.com/docs/guide/going-further/runtime-config#environment-variables) + + > [!IMPORTANT] This is a feature exclusive to nuxt 3. For most deployment scenarios it is not + > needed, but it can be useful for deploying multiple instances from a single build. + +- ensure both the github repository, and the [package registry](https://github.com/orgs/acdh-oeaw/packages/container/my-app/settings) is set to public.