From a44cc73d6bb1150952083640195598b5d8946f18 Mon Sep 17 00:00:00 2001 From: Nicolas KOKLA Date: Fri, 4 Oct 2024 16:38:25 +0200 Subject: [PATCH] Fix: Update next config for support env-vars --- .env.default | 45 +++++++++++++++------------- .github/workflows/ci.yml | 5 ++++ .github/workflows/docker-publish.yml | 21 +++++++++++-- docker-compose.yml | 44 +++++++++++++++++---------- next.config.mjs | 17 +++++++++++ 5 files changed, 93 insertions(+), 39 deletions(-) diff --git a/.env.default b/.env.default index 2223d0f6a..e819363f1 100644 --- a/.env.default +++ b/.env.default @@ -1,13 +1,25 @@ NEXT_PUBLIC_ADRESSE_URL=http://localhost:3000 +NEXT_PUBLIC_API_BAN_URL=https://plateforme.adresse.data.gouv.fr + +# ----------------------------- +# Application configuration --- +# ----------------------------- + +# Defintion du port +PORT=3000 +# Fonctionnalité: Certificat d'addressage (Valeur 0 ou 1) +NEXT_PUBLIC_CERTIFICAT_NUMEROTATION_ENABLED=0 +# DEPRECATED : A voir pour supprimer cette variable qui utilise la lib helmet +ENABLE_HELMET=0 # ----------------------------------------------- # --- Parametres URL Externe autre projet BAN --- # ----------------------------------------------- + NEXT_PUBLIC_API_GEO_URL=https://geo.api.gouv.fr/2024 NEXT_PUBLIC_API_ETABLISSEMENTS_PUBLIC=https://api-lannuaire.service-public.fr/api/explore/v2.1 NEXT_PUBLIC_DATAGOUV_URL=https://www.data.gouv.fr/api/1 - -NEXT_PUBLIC_API_BAN_URL=https://plateforme.adresse.data.gouv.fr +# API search for Addok Geocodeur NEXT_PUBLIC_API_ADRESSE=https://api-adresse.data.gouv.fr NEXT_LAST_UPDATED_DATE_ADDOCK_URL='https://api-adresse.data.gouv.fr/info.txt' @@ -15,6 +27,7 @@ NEXT_LAST_UPDATED_DATE_ADDOCK_URL='https://api-adresse.data.gouv.fr/info.txt' # --- Utilisation appel externe Bal --- # ------------------------------------- +# API Depot NEXT_PUBLIC_API_DEPOT_URL=https://plateforme-bal.adresse.data.gouv.fr/api-depot API_DEPOT_TOKEN= SESSION_SECRET= @@ -22,10 +35,9 @@ SESSION_SECRET= # Params pour la partie Blog NEXT_PUBLIC_GHOST_URL=https://ghost.adresse.data.gouv.fr NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE=ghost.adresse.data.gouv.fr -NEXT_PUBLIC_GHOST_KEY=xxxx +NEXT_PUBLIC_GHOST_KEY=YOUR_GHOST_KEY_HERE # Definition URL pour accès aux sites BAL - NEXT_PUBLIC_BAL_ADMIN_API_URL=https://bal-admin.adresse.data.gouv.fr/api NEXT_PUBLIC_BAL_API_URL=https://api-bal.adresse.data.gouv.fr/v2 NEXT_PUBLIC_MOISSONNEUR_BAL_API_URL=https://plateforme-bal.adresse.data.gouv.fr/moissonneur @@ -34,37 +46,28 @@ NEXT_PUBLIC_BAL_WIDGET_URL=https://baseadressenationale.github.io/bal-widget NEXT_PUBLIC_CLIENT_GUICHET_ADRESSE= NEXT_PUBLIC_CLIENT_MES_ADRESSE= NEXT_PUBLIC_CLIENT_FORMULAIRE_PUBLICATION= -NEXT_PUBLIC_DATAGOUV_URL=https://www.data.gouv.fr/api/1 # ----------------------------------------- # --- Utilisation Matomo pour les stats --- # ----------------------------------------- + NEXT_PUBLIC_MATOMO_URL= NEXT_PUBLIC_MATOMO_SITE_ID= # The Matomo Token is actualy not required # MATOMO_TOKEN_AUTH= -# A voir pour supprimer cette variable qui utilise la lib helmet -ENABLE_HELMET=0 - -# Defintion du port -PORT=3000 - -# Valeur 0 ou 1 pour la demande de certification -NEXT_PUBLIC_CERTIFICAT_NUMEROTATION_ENABLED= - # -------------------------------------- # --- Connexion au S3 pour les datas --- # -------------------------------------- -S3_CONFIG_ACCESS_KEY_ID=xxxx -S3_CONFIG_SECRET_ACCESS_KEY=xxxx -S3_CONFIG_REGION=xxxx -S3_CONFIG_ENDPOINT=xxxx +S3_CONFIG_ACCESS_KEY_ID=YOUR_S3_ACCESS_KEY_ID_HERE +S3_CONFIG_SECRET_ACCESS_KEY=YOUR_S3_SECRET_ACCESS_KEY_HERE +S3_CONFIG_REGION=YOUR_S3_REGION_HERE +S3_CONFIG_ENDPOINT=YOUR_S3_ENDPOINT_HERE -# Connexion au Dossier Data local (en cas de rollback - TOGGLER_DATA_SOURCES=local sinon TOGGLER_DATA_SOURCES=S3) -NEXT_PUBLIC_TOGGLER_DATA_SOURCES=S3 -NEXT_PUBLIC_PATH_STATIC_FILE= +# DEPRECATED : Connexion au Dossier Data local (en cas de rollback - TOGGLER_DATA_SOURCES=local sinon TOGGLER_DATA_SOURCES=S3) +# NEXT_PUBLIC_TOGGLER_DATA_SOURCES=S3 +# NEXT_PUBLIC_PATH_STATIC_FILE= # ------------------------------- # --- URL des réseaux sociaux --- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81becb2ee..ae4a5ced8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,11 @@ env: NEXT_PUBLIC_API_DEPOT_URL: ${{ vars.NEXT_PUBLIC_API_DEPOT_URL }} NEXT_PUBLIC_API_ETABLISSEMENTS_PUBLIC: ${{ vars.NEXT_PUBLIC_API_ETABLISSEMENTS_PUBLIC }} NEXT_PUBLIC_BAL_API_URL: ${{ vars.NEXT_PUBLIC_BAL_API_URL }} + NEXT_PUBLIC_GHOST_URL: ${{ vars.NEXT_PUBLIC_GHOST_URL }} + NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE: ${{ vars.NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE }} + NEXT_PUBLIC_GHOST_KEY: ${{ vars.NEXT_PUBLIC_GHOST_KEY }} + + # S3 Configuration S3_CONFIG_ACCESS_KEY_ID: ${{ secrets.S3_CONFIG_ACCESS_KEY_ID }} S3_CONFIG_SECRET_ACCESS_KEY: ${{ secrets.S3_CONFIG_SECRET_ACCESS_KEY }} S3_CONFIG_REGION: ${{ secrets.S3_CONFIG_REGION }} diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 3b919150e..26cc64a32 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -2,13 +2,13 @@ name: Docker on: push: - branches: + branches: - "master" - "main" # Ajout de la branche main # Publish semver tags as releases. tags: [ 'v*.*.*' ] pull_request: - branches: + branches: - "master" - "main" # Ajout de la branche main @@ -17,6 +17,21 @@ env: REGISTRY: ghcr.io # github.repository as / IMAGE_NAME: ${{ github.repository }} + # App Configuration + NEXT_PUBLIC_ADRESSE_URL: ${{ vars.NEXT_PUBLIC_ADRESSE_URL }} + NEXT_PUBLIC_API_BAN_URL: ${{ vars.NEXT_PUBLIC_API_BAN_URL }} + # DataGouv & Beta.gouv API Configuration + NEXT_PUBLIC_DATAGOUV_URL: ${{ vars.NEXT_PUBLIC_DATAGOUV_URL }} + NEXT_PUBLIC_API_GEO_URL: ${{ vars.NEXT_PUBLIC_API_GEO_URL }} + NEXT_PUBLIC_API_ETABLISSEMENTS_PUBLIC: ${{ vars.NEXT_PUBLIC_API_ETABLISSEMENTS_PUBLIC }} + # Ghost Blog Configuration + NEXT_PUBLIC_GHOST_URL: ${{ vars.NEXT_PUBLIC_GHOST_URL }} + NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE: ${{ vars.NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE }} + NEXT_PUBLIC_GHOST_KEY: ${{ vars.NEXT_PUBLIC_GHOST_KEY }} + # BAL API Access Configuration + NEXT_PUBLIC_API_DEPOT_URL: ${{ vars.NEXT_PUBLIC_API_DEPOT_URL }} + NEXT_PUBLIC_BAL_ADMIN_API_URL: ${{ vars.NEXT_PUBLIC_BAL_ADMIN_API_URL }} + NEXT_PUBLIC_BAL_API_URL: ${{ vars.NEXT_PUBLIC_BAL_API_URL }} jobs: build: @@ -74,4 +89,4 @@ jobs: - name: Print Debug Info run: | echo "Registry: ${{ env.REGISTRY }}" - echo "Image Name: ${{ env.IMAGE_NAME }}" \ No newline at end of file + echo "Image Name: ${{ env.IMAGE_NAME }}" diff --git a/docker-compose.yml b/docker-compose.yml index 39fffcecc..a5f06cec5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '3.8' services: frontend: build: - dockerfile: "dockerfile.dev" + dockerfile: "dockerfile.dev" container_name: frontend-new-site volumes: - ./public:/app/public @@ -18,34 +18,48 @@ services: - ./.next:/app/.next - ./.storybook:/app/.storybook ports: - - "3000:3000" + - "3000:3000" environment: - NEXT_PUBLIC_ADRESSE_URL=${NEXT_PUBLIC_ADRESSE_URL} - - NEXT_PUBLIC_API_GEO_URL=${NEXT_PUBLIC_API_GEO_URL} - NEXT_PUBLIC_API_BAN_URL=${NEXT_PUBLIC_API_BAN_URL} - - NEXT_PUBLIC_API_ADRESSE=${NEXT_PUBLIC_API_ADRESSE} - - NEXT_PUBLIC_API_ETABLISSEMENTS_PUBLIC=${NEXT_PUBLIC_API_ETABLISSEMENTS_PUBLIC} - - NEXT_PUBLIC_MATOMO_URL=${NEXT_PUBLIC_MATOMO_URL} - - NEXT_PUBLIC_MATOMO_SITE_ID=${NEXT_PUBLIC_MATOMO_SITE_ID} - - MATOMO_TOKEN_AUTH=${MATOMO_TOKEN_AUTH} + # App Configuration + - NEXT_PUBLIC_CERTIFICAT_NUMEROTATION_ENABLED=${NEXT_PUBLIC_CERTIFICAT_NUMEROTATION_ENABLED} - ENABLE_HELMET=${ENABLE_HELMET} + # External URLs + - NEXT_PUBLIC_API_GEO_URL=${NEXT_PUBLIC_API_GEO_URL} + - NEXT_PUBLIC_API_ETABLISSEMENTS_PUBLIC=${NEXT_PUBLIC_API_ETABLISSEMENTS_PUBLIC} + - NEXT_PUBLIC_DATAGOUV_URL=${NEXT_PUBLIC_DATAGOUV_URL} + # API search for Addok Geocodeur + - NEXT_PUBLIC_API_ADRESSE=${NEXT_PUBLIC_API_ADRESSE} + - NEXT_LAST_UPDATED_DATE_ADDOCK_URL=${NEXT_LAST_UPDATED_DATE_ADDOCK_URL} + # BAL - API Depot Access Configuration - NEXT_PUBLIC_API_DEPOT_URL=${NEXT_PUBLIC_API_DEPOT_URL} - API_DEPOT_TOKEN=${API_DEPOT_TOKEN} - SESSION_SECRET=${SESSION_SECRET} - - NEXT_PUBLIC_CERTIFICAT_NUMEROTATION_ENABLED=${NEXT_PUBLIC_CERTIFICAT_NUMEROTATION_ENABLED} - - GHOST_KEY=${GHOST_KEY} + # Blog Configuration + - NEXT_PUBLIC_GHOST_KEY=${GHOST_KEY} - NEXT_PUBLIC_GHOST_URL=${NEXT_PUBLIC_GHOST_URL} - NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE=${NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE} + # BAL environements parameters - NEXT_PUBLIC_BAL_ADMIN_API_URL=${NEXT_PUBLIC_BAL_ADMIN_API_URL} - NEXT_PUBLIC_BAL_API_URL=${NEXT_PUBLIC_BAL_API_URL} - - NEXT_PUBLIC_BAL_WIDGET_URL=${NEXT_PUBLIC_BAL_WIDGET_URL} + - NEXT_PUBLIC_MOISSONNEUR_BAL_API_URL=${NEXT_PUBLIC_MOISSONNEUR_BAL_API_URL} - NEXT_PUBLIC_MES_ADRESSES=${NEXT_PUBLIC_MES_ADRESSES} - - NEXT_PUBLIC_TOGGLER_DATA_SOURCES=${NEXT_PUBLIC_TOGGLER_DATA_SOURCES} - - NEXT_PUBLIC_PATH_STATIC_FILE=${NEXT_PUBLIC_PATH_STATIC_FILE} + - NEXT_PUBLIC_BAL_WIDGET_URL=${NEXT_PUBLIC_BAL_WIDGET_URL} + - NEXT_PUBLIC_CLIENT_GUICHET_ADRESSE=${NEXT_PUBLIC_CLIENT_GUICHET_ADRESSE} + - NEXT_PUBLIC_CLIENT_MES_ADRESSE=${NEXT_PUBLIC_CLIENT_MES_ADRESSE} + - NEXT_PUBLIC_CLIENT_FORMULAIRE_PUBLICATION=${NEXT_PUBLIC_CLIENT_FORMULAIRE_PUBLICATION} + # Matomo Configuration + - NEXT_PUBLIC_MATOMO_URL=${NEXT_PUBLIC_MATOMO_URL} + - NEXT_PUBLIC_MATOMO_SITE_ID=${NEXT_PUBLIC_MATOMO_SITE_ID} + # S3 Configuration - S3_CONFIG_ACCESS_KEY_ID=${S3_CONFIG_ACCESS_KEY_ID} - S3_CONFIG_SECRET_ACCESS_KEY=${S3_CONFIG_SECRET_ACCESS_KEY} - S3_CONFIG_REGION=${S3_CONFIG_REGION} - S3_CONFIG_ENDPOINT=${S3_CONFIG_ENDPOINT} - - NEXT_LAST_UPDATED_DATE_ADDOCK_URL=${NEXT_LAST_UPDATED_DATE_ADDOCK_URL} - - NEXT_PUBLIC_DATAGOUV_URL=${NEXT_PUBLIC_DATAGOUV_URL} + # Social Networks + - NEXT_PUBLIC_SOCIAL_NETWORKS_URL_XCOM=${NEXT_PUBLIC_SOCIAL_NETWORKS_URL_XCOM} + - NEXT_PUBLIC_SOCIAL_NETWORKS_URL_FACEBOOK=${NEXT_PUBLIC_SOCIAL_NETWORKS_URL_FACEBOOK} + - NEXT_PUBLIC_SOCIAL_NETWORKS_URL_LINKEDIN=${NEXT_PUBLIC_SOCIAL_NETWORKS_URL_LINKEDIN} + - NEXT_PUBLIC_SOCIAL_NETWORKS_URL_GITHUB=${NEXT_PUBLIC_SOCIAL_NETWORKS_URL_GITHUB} diff --git a/next.config.mjs b/next.config.mjs index 24e3548fb..cd0191c2c 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,6 +1,19 @@ /** @type {import('next').NextConfig} */ +import fs from 'node:fs' import NextBundleAnalyzer from '@next/bundle-analyzer' +import dotenv from 'dotenv' + +const getNextEnv = envVars => Object.fromEntries( + Object + .entries(envVars) + .filter(([key]) => key.startsWith('NEXT_PUBLIC')) +) + +const defaultEnvVarFile = '.env.default' +const defaultEnvVarRaw = dotenv.parse(fs.readFileSync(defaultEnvVarFile)) +const defaultEnvVar = getNextEnv(defaultEnvVarRaw) +const envVar = getNextEnv(process.env) const NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE = process.env.NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE const imagesDomains = ['static.data.gouv.fr'] @@ -13,6 +26,10 @@ const withBundleAnalyzer = NextBundleAnalyzer({ }) const nextConfig = withBundleAnalyzer({ + env: { + ...defaultEnvVar, + ...envVar, + }, images: { remotePatterns: imagesDomains.map(domain => ({ protocol: 'https',