From bbd4ed11ab693f72a8d411e7126495e921dddfeb Mon Sep 17 00:00:00 2001 From: FORESTIER Fabien <fabien.forestier@soprasteria.com> Date: Fri, 6 Dec 2019 14:20:08 +0100 Subject: [PATCH] Put fr app behind / instead of /fr + improve dockerfile to avoid the copy of unnecessary files --- Dockerfile | 23 +++++++++++---- angular.json | 18 +++++------- docker-compose.yml | 2 +- nginx.conf.template | 34 +++++++--------------- src/environments/environment.production.ts | 4 +-- src/environments/environment.ts | 4 +-- src/i18n/traductions.fr.ts | 2 +- src/i18n/traductions.ts | 2 +- src/index.html | 8 ++--- 9 files changed, 45 insertions(+), 52 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0debac44..9be822bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,23 @@ # Stage 0, based on Node.js, to build and compile Angular FROM node:8.10.0 as builder -# Copy the package.json file first in order to cache the modules -COPY ./package.json /app/package.json WORKDIR /app + +# Copy the package.json file first in order to cache the modules +COPY ./package.json . +COPY ./patch.js . + # Install npm dependencies RUN npm install -# Copy the project -COPY . /app # Launch postinstall script (to include crypto module) RUN npm run postinstall +# Copy the project +COPY ./angular.json . +COPY ./tsconfig.json . +COPY ./src ./src + ARG conf # Building the Angular app /dist i18n @@ -20,11 +26,16 @@ RUN npm run build-i18n:${conf} # Stage 1, based on Nginx, to have only the compiled app FROM nginx -COPY --from=builder /app/dist /usr/share/nginx/html - ## Install dependency to get lua module in .conf RUN apt-get update RUN apt-get --assume-yes install nginx-extras +RUN rm /etc/nginx/conf.d/* + +COPY --from=builder /app/dist/fr /usr/share/nginx/html +COPY --from=builder /app/dist/en /usr/share/nginx/html/en + +RUN ls -l /usr/share/nginx/html + diff --git a/angular.json b/angular.json index 8502a726..e84a5b3d 100644 --- a/angular.json +++ b/angular.json @@ -86,17 +86,14 @@ "extractLicenses": true, "vendorChunk": false, "buildOptimizer": false, - "fileReplacements": [ - { - "replace": "src/i18n/traductions.ts", - "with": "src/i18n/traductions.fr.ts" - } - ], + "fileReplacements": [{ + "replace": "src/i18n/traductions.ts", + "with": "src/i18n/traductions.fr.ts" + }], "outputPath": "dist/fr", "i18nFile": "src/i18n/messages.fr.xlf", "i18nFormat": "xlf", - "i18nLocale": "fr", - "baseHref": "/fr/" + "i18nLocale": "fr" }, "production-en": { "optimization": true, @@ -140,8 +137,7 @@ "outputPath": "dist/fr", "i18nFile": "src/i18n/messages.fr.xlf", "i18nFormat": "xlf", - "i18nLocale": "fr", - "baseHref": "/fr/" + "i18nLocale": "fr" } } }, @@ -236,4 +232,4 @@ "prefix": "app" } } -} +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 4b7dfe09..de78ee5a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: image: registry.alpha.grandlyon.com/refonte-data/portail-data:${TAG} volumes: - ./nginx.conf.template:/etc/nginx/nginx.conf.template - - ${CONFIG_FILE_PATH}:/usr/share/nginx/html/fr/assets/config/config.json + - ${CONFIG_FILE_PATH}:/usr/share/nginx/html/assets/config/config.json - ${CONFIG_FILE_PATH}:/usr/share/nginx/html/en/assets/config/config.json ports: - ${NGINX_PORT}:8080 diff --git a/nginx.conf.template b/nginx.conf.template index 8525ebb2..817b4220 100644 --- a/nginx.conf.template +++ b/nginx.conf.template @@ -21,40 +21,26 @@ server { })(); </script>"; - # rule redirecting to fr or en regarding the browser preferences + # rule serving the fr build location / { - rewrite_by_lua ' - for lang in (ngx.var.http_accept_language .. ","):gmatch("([^,]*),") do - if string.sub(lang, 0, 2) == "en" then - ngx.redirect("/en/") - end - if string.sub(lang, 0, 2) == "fr" then - ngx.redirect("/fr/") - end - end - ngx.redirect("/en/") - '; + try_files $uri$args /index.html; + sub_filter '</head>' '$matomo_script</head>'; + sub_filter '<html lang="en">' '<html lang="fr">'; } - # This is needed to allow reloading in the app when not on the base url as our app is an SPA + # Rule serving the en build location /en { try_files $uri$args /en/index.html; sub_filter '</head>' '$matomo_script</head>'; } - location /fr { - try_files $uri$args /fr/index.html; - sub_filter '</head>' '$matomo_script</head>'; - sub_filter '<html lang="en">' '<html lang="fr">'; + # redirecting the /fr url to the new location of the fr build + location ~ ^/fr(.*)$ { + return 301 $scheme://$http_host$1$is_args$args; } - # Allow to access the app without the /fr or /en and will by default redirect to /en/{path} - #location / { - # try_files $uri$args /en/index.html; + #location /robots.txt { + # rewrite ^ /fr/robots.txt; #} - location /robots.txt { - rewrite ^ /fr/robots.txt; - } - } diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index 9385ce6e..de3b8ec3 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -1,5 +1,5 @@ -import { AppRoutes } from '../app/routes'; import * as packageJson from '../../package.json'; +import { AppRoutes } from '../app/routes'; // The file contents for the current environment will overwrite these during build. // The build system defaults to the dev environment which uses `environment.ts` @@ -13,7 +13,7 @@ export const environment = { // Path to the built app in a particular language angularAppHost: { - fr: '/fr', + fr: '/', en: '/en', }, diff --git a/src/environments/environment.ts b/src/environments/environment.ts index c4976e4c..820095dd 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -1,5 +1,5 @@ -import { AppRoutes } from '../app/routes'; import * as packageJson from '../../package.json'; +import { AppRoutes } from '../app/routes'; // The file contents for the current environment will overwrite these during build. // The build system defaults to the dev environment which uses `environment.ts` @@ -13,7 +13,7 @@ export const environment = { // Path to the built app in a particular language angularAppHost: { - fr: '/fr', + fr: '/', en: '/en', }, diff --git a/src/i18n/traductions.fr.ts b/src/i18n/traductions.fr.ts index a4915a0b..6075377f 100644 --- a/src/i18n/traductions.fr.ts +++ b/src/i18n/traductions.fr.ts @@ -212,7 +212,7 @@ export const geosource = { }; export const metaDescription = { - home: 'Les données des acteurs du territoire de la Métropole de Lyon', + home: 'Données de la Métropole de Lyon', research: 'Explorer les jeux de données', }; diff --git a/src/i18n/traductions.ts b/src/i18n/traductions.ts index b9e0e164..5223babe 100644 --- a/src/i18n/traductions.ts +++ b/src/i18n/traductions.ts @@ -212,7 +212,7 @@ export const geosource = { }; export const metaDescription = { - home: 'The data of Lyon Metropolitan Area\'s actors', + home: 'Lyon Metropolitan Area\'s Data', research: 'Explore the datasets', }; diff --git a/src/index.html b/src/index.html index ff9faeb1..94f3c0ad 100644 --- a/src/index.html +++ b/src/index.html @@ -3,8 +3,8 @@ <head> <meta charset="utf-8"> - <title>Données métropolitaines de Grand Lyon</title> - <meta name="description" content="Données métropolitaines de Grand Lyon"> + <title>Données de la Métropole de Lyon</title> + <meta name="description" content="Les données des acteurs du territoire de la Métropole de Lyon"> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> @@ -23,8 +23,8 @@ <meta name="theme-color" content="#242b3f"> <meta property="og:type" content="website" /> - <meta property="og:title" content="Données métropolitaines du Grand Lyon" /> - <meta property="og:description" content="Données métropolitaines du Grand Lyon" /> + <meta property="og:title" content="Données de la Métropole de Lyon" /> + <meta property="og:description" content="Les données des acteurs du territoire de la Métropole de Lyon" /> <meta property="og:image" content="https://minio.data.beta.grandlyon.com/assets/prod-media-library/2019/12/b43e5989769237ff744a05aeed9209d7-data.grandlyon.jpg" /> -- GitLab