From 6fdc4b422e47b69a14ef9c57b37f158e004cfd61 Mon Sep 17 00:00:00 2001 From: Mohamed Hamou Date: Mon, 9 Sep 2024 13:32:17 +0200 Subject: [PATCH 1/7] Add a new image of arlas-wui that doesn't embark analytics --- angular.json | 43 ++++++++++++++ docker/Dockerfile-production | 48 ++++++++++++++++ docker/Dockerfile-production-no-analytics | 48 ++++++++++++++++ release.sh | 7 ++- src/index-without-analytics.html | 69 +++++++++++++++++++++++ 5 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 docker/Dockerfile-production create mode 100644 docker/Dockerfile-production-no-analytics create mode 100644 src/index-without-analytics.html diff --git a/angular.json b/angular.json index bd0e07e8..8c24bbe6 100644 --- a/angular.json +++ b/angular.json @@ -98,6 +98,46 @@ "output": "/assets/rotate/" } ] + }, + "production-no-analytics": { + "optimization": true, + "outputHashing": "all", + "sourceMap": false, + "namedChunks": false, + "aot": true, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": true, + "index": { + "input": "src/index-without-analytics", + "output": "index.html" + }, + "fileReplacements": [ + { + "src": "src/environments/environment.ts", + "replaceWith": "src/environments/environment.prod.ts" + } + ], + "assets": [ + { + "input": "src/environments/prod/", + "output": "/", + "glob": "*.yaml" + }, + "src/assets", + "src/silent-refresh.html", + "src/favicon.ico", + { + "glob": "**/*", + "input": "./node_modules/arlas-web-components/assets/resize", + "output": "/assets/resize/" + }, + { + "glob": "**/*", + "input": "./node_modules/arlas-web-components/assets/rotate", + "output": "/assets/rotate/" + } + ] } } }, @@ -112,6 +152,9 @@ }, "production": { "browserTarget": "arlas-wui:build:production" + }, + "production-no-analytics": { + "browserTarget": "arlas-wui:build:production-no-analytics" } }, "defaultConfiguration": "development" diff --git a/docker/Dockerfile-production b/docker/Dockerfile-production new file mode 100644 index 00000000..a694a2e4 --- /dev/null +++ b/docker/Dockerfile-production @@ -0,0 +1,48 @@ +### STAGE 1: Build ### + +# We label our stage as 'builder' +FROM node:16.19.0 as builder + +COPY ./package.json ./ +COPY ./package-lock.json ./ + +RUN npm set progress=false && npm config set depth 0 && npm cache clean --force + +## Storing node modules on a separate layer will prevent unnecessary npm installs at each build +RUN export NODE_OPTIONS=--max_old_space_size=8192 && npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app + +COPY ./scripts/start.sh ./ng-app +COPY ./scripts/fetch-conf-by-http.sh ./ng-app + +WORKDIR /ng-app + +COPY . . + +## Build the angular app in production mode and store the artifacts in dist folder +RUN export NODE_OPTIONS=--max_old_space_size=8192 && $(npm bin)/ng build --configuration production --aot --base-href='$ARLAS_WUI_BASE_HREF/' + +### STAGE 2: Setup ### + +FROM nginx:1.25.3-alpine3.18-slim +ARG version="latest" + +LABEL io.arlas.wui.version=${version} +LABEL vendor="Gisaïa" +LABEL description="This container build and serve the ARLAS-wui app" + +RUN apk add --update bash jq netcat-openbsd curl && rm -rf /var/cache/apk/* + +## Copy our default nginx config +COPY nginx/default.conf /etc/nginx/conf.d/ + +## Remove default nginx website +RUN rm -rf /usr/share/nginx/html/* + +## From 'builder' stage copy over the artifacts in dist folder to default nginx public folder +COPY --from=builder /ng-app/dist /usr/share/nginx/html +COPY --from=builder /ng-app/start.sh /usr/share/nginx/ +COPY --from=builder /ng-app/fetch-conf-by-http.sh /usr/share/nginx/ + +HEALTHCHECK CMD curl --fail http://localhost:80/ || exit 1 + +CMD /usr/share/nginx/start.sh diff --git a/docker/Dockerfile-production-no-analytics b/docker/Dockerfile-production-no-analytics new file mode 100644 index 00000000..b8636232 --- /dev/null +++ b/docker/Dockerfile-production-no-analytics @@ -0,0 +1,48 @@ +### STAGE 1: Build ### + +# We label our stage as 'builder' +FROM node:16.19.0 as builder + +COPY ./package.json ./ +COPY ./package-lock.json ./ + +RUN npm set progress=false && npm config set depth 0 && npm cache clean --force + +## Storing node modules on a separate layer will prevent unnecessary npm installs at each build +RUN export NODE_OPTIONS=--max_old_space_size=8192 && npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app + +COPY ./scripts/start.sh ./ng-app +COPY ./scripts/fetch-conf-by-http.sh ./ng-app + +WORKDIR /ng-app + +COPY . . + +## Build the angular app in production mode and store the artifacts in dist folder +RUN export NODE_OPTIONS=--max_old_space_size=8192 && $(npm bin)/ng build --configuration production-no-analytics --aot --base-href='$ARLAS_WUI_BASE_HREF/' + +### STAGE 2: Setup ### + +FROM nginx:1.25.3-alpine3.18-slim +ARG version="latest" + +LABEL io.arlas.wui.version=${version} +LABEL vendor="Gisaïa" +LABEL description="This container build and serve the ARLAS-wui app" + +RUN apk add --update bash jq netcat-openbsd curl && rm -rf /var/cache/apk/* + +## Copy our default nginx config +COPY nginx/default.conf /etc/nginx/conf.d/ + +## Remove default nginx website +RUN rm -rf /usr/share/nginx/html/* + +## From 'builder' stage copy over the artifacts in dist folder to default nginx public folder +COPY --from=builder /ng-app/dist /usr/share/nginx/html +COPY --from=builder /ng-app/start.sh /usr/share/nginx/ +COPY --from=builder /ng-app/fetch-conf-by-http.sh /usr/share/nginx/ + +HEALTHCHECK CMD curl --fail http://localhost:80/ || exit 1 + +CMD /usr/share/nginx/start.sh diff --git a/release.sh b/release.sh index b6038e66..1dfcc611 100755 --- a/release.sh +++ b/release.sh @@ -171,13 +171,18 @@ npm cache clean --force rm -rf node_modules/ echo "==> Docker" -docker build --no-cache --build-arg version=${VERSION} --tag gisaia/arlas-wui:${VERSION} . +docker build -f docker/Dockerfile-production --no-cache --build-arg version=${VERSION} --tag gisaia/arlas-wui:${VERSION} . +docker build -f docker/Dockerfile-production-no-analytics --no-cache --build-arg version=${VERSION} --tag gisaia/arlas-wui-no-analytics:${VERSION} . docker push gisaia/arlas-wui:${VERSION} +docker push gisaia/arlas-wui-no-analytics:${VERSION} if [ "${STAGE}" == "stable" ] && [ "${IS_LATEST_VERSION}" == "YES" ]; then docker tag gisaia/arlas-wui:${VERSION} gisaia/arlas-wui:latest docker push gisaia/arlas-wui:latest + + docker tag gisaia/arlas-wui-no-analytics:${VERSION} gisaia/arlas-wui-no-analytics:latest + docker push gisaia/arlas-wui-no-analytics:latest fi echo "==> Build arlas-wui library" diff --git a/src/index-without-analytics.html b/src/index-without-analytics.html new file mode 100644 index 00000000..2731281d --- /dev/null +++ b/src/index-without-analytics.html @@ -0,0 +1,69 @@ + + + + + + + ARLAS + + + + + + + + + From a276008d145de664487c6d271fe2295047d42438 Mon Sep 17 00:00:00 2001 From: Mohamed Hamou Date: Mon, 9 Sep 2024 13:34:23 +0200 Subject: [PATCH 2/7] Ignore docker files from licence adding --- license-check-and-add.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/license-check-and-add.json b/license-check-and-add.json index 3c97a772..da4b4ea5 100644 --- a/license-check-and-add.json +++ b/license-check-and-add.json @@ -1,5 +1,5 @@ { - "ignore": [".github/**", ".git/**", "e2e/**", "*", "**/*.sh", "*.yml", "**/*.yaml", "**/*.conf", "**/*.md", "**/*.svg", "**/*.spec.ts", "**/*.html", "**/*.woff2", "src/test.ts", "**/.DS_Store", "**/.gitkeep", "patches/*", "**/*.xml", "**/*.csv"], + "ignore": [".github/**", ".git/**", "e2e/**", "*", "**/*.sh", "*.yml", "**/*.yaml", "**/*.conf", "**/*.md", "**/*.svg", "**/*.spec.ts", "**/*.html", "**/*.woff2", "src/test.ts", "**/.DS_Store", "**/.gitkeep", "patches/*", "**/*.xml", "**/*.csv", "docker/*"], "license": "LICENSE", "trailingWhitespace": "TRIM", "licenseFormats": { From b7044a9d20cf8c95dbd72774801725da466723bc Mon Sep 17 00:00:00 2001 From: Mohamed Hamou Date: Mon, 9 Sep 2024 13:47:30 +0200 Subject: [PATCH 3/7] Add nonce for browser compatibility script --- src/index-without-analytics.html | 2 +- src/index.html | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index-without-analytics.html b/src/index-without-analytics.html index 2731281d..c85455ea 100644 --- a/src/index-without-analytics.html +++ b/src/index-without-analytics.html @@ -1,7 +1,7 @@ - - - +