From 5c8f8c611f47471581f968d4ab9ca0c7b3bcc484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 14:21:23 +0200 Subject: [PATCH 1/3] added build arguments to optionally disable minification/translation of files --- docker/Dockerfile | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 2fc10d69..f95bdf09 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,16 +11,21 @@ RUN apk add --no-cache bash FROM base AS builder +ARG DISABLE_TRANSLATE="" +ARG DISABLE_MINIFY="" + RUN mkdir /opt/meshcentral/meshcentral COPY ./ /opt/meshcentral/meshcentral/ -# minify files - first try throws Error: Cannot find module 'jsdom' -RUN cd meshcentral/translate && node translate.js minifyall; exit 0 -RUN cd meshcentral/translate && node translate.js minifyall +# Extract all MeshCentral strings from web pages and generate the languages.json file. - first try throws Error: Cannot find module 'jsdom' +RUN cd meshcentral/translate && node translate.js extractall; exit 0; +RUN cd meshcentral/translate && node translate.js extractall + +# minify files +RUN if [ "$DISABLE_MINIFY" != "yes" ] && [ "$DISABLE_MINIFY" != "YES" ]; then cd meshcentral/translate && node translate.js minifyall; fi # translate -RUN cd meshcentral/translate && node translate.js translateall -RUN cd meshcentral/translate && node translate.js extractall +RUN if [ "$DISABLE_TRANSLATE" != "yes" ] && [ "$DISABLE_TRANSLATE" != "YES" ]; then cd meshcentral/translate && node translate.js translateall; fi FROM base From 18d9e86352db80a64d0ed7a6ba17f9281a471d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 14:48:08 +0200 Subject: [PATCH 2/3] added optional build arguments to docker/readme.md --- docker/readme.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker/readme.md b/docker/readme.md index 07a8c466..ea0d09e9 100644 --- a/docker/readme.md +++ b/docker/readme.md @@ -21,6 +21,13 @@ > | --force-rm | Always remove intermediate containers | > | -t meshcentral | Name and optionally a tag in the 'name:tag' format | +### Optional build arguments +> | Argument | Description | +> | :--- | :--- | +> | INCLUDE_MONGOTOOLS=yes | Includes mongodb-tools (mongodump, ...) in the image | +> | DISABLE_MINIFY=yes | Disables the minification of files | +> | DISABLE_TRANSLATE=yes | Disables the translation of files | + # Create folder-structure and files ``` From 0ce81a3f549a3da3282e864c0293de4961c92ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6n?= Date: Wed, 8 Jun 2022 17:16:56 +0200 Subject: [PATCH 3/3] added docker build script --- docker/docker.build.sh | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 docker/docker.build.sh diff --git a/docker/docker.build.sh b/docker/docker.build.sh new file mode 100644 index 00000000..18eef84b --- /dev/null +++ b/docker/docker.build.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +MSG=""; +PRUNE="false"; + +function appendOutput() +{ + if [ -z "${MSG}" ]; then echo -e "\n" > /dev/tty; fi + + ARGS=$@; + LINE="${ARGS}\n" + echo -e "${LINE}" > /dev/tty; + + MSG="${MSG}${LINE}"; +} + +function runDockerBuild() +{ + if [ "${PRUNE}" == "true" ]; then docker system prune -a -f; fi + + STARTTS=$(date +%s); + ARGS=$@; + + BUILD_CMD="docker build -f docker/Dockerfile --force-rm --no-cache ${ARGS} -t meshcentral ."; + appendOutput "Current build: ${BUILD_CMD}"; + + ${BUILD_CMD}; + if [ $? -ne 0 ]; then exit $?; fi + + ENDTS=$(date +%s); + DIFSEC=$((${ENDTS}-${STARTTS})); + if [ ${DIFSEC} -ge 60 ]; then + TMPMIN=$((${DIFSEC}/60)); + TMPSEC=$((${DIFSEC}%60)); + + if [ ${TMPMIN} -ge 60 ]; then + TMPHOUR=$((${TMPMIN}/60)); + TMPMIN=$((${TMPMIN}%60)); + + appendOutput "\tBuild time: ${TMPHOUR} hr ${TMPMIN} min ${TMPSEC} sec"; + else appendOutput "\tBuild time: ${TMPMIN} min ${TMPSEC} sec"; fi + else appendOutput "\tBuild time: ${DIFSEC} sec"; fi + + IMG_SIZE=$(docker image inspect meshcentral | grep -e "\"Size\"" | tr -d '",' | sed -E "s/\s*Size:\s*//"); + expr $IMG_SIZE + 0; + appendOutput "\tImage size: ${IMG_SIZE} ($((${IMG_SIZE}/1024/1024))M)"; + + appendOutput "\n"; + + return 0; +} + + +parent_path=$(dirname -- $(dirname -- "$( readlink -f -- "$0"; )")); +if [ "${parent_path}" != "$(pwd -P)" ]; then + echo -e "change working directory to: ${parent_path}" > /dev/tty; + cd "${parent_path}"; +fi + +if ! [ -z $1 ] && [ "${1}" == "prune" ]; then PRUNE="true"; fi + +runDockerBuild; +#runDockerBuild --build-arg DISABLE_MINIFY=yes; +#runDockerBuild --build-arg DISABLE_TRANSLATE=yes; +#runDockerBuild --build-arg DISABLE_MINIFY=yes --build-arg DISABLE_TRANSLATE=yes; + +#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes; +#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes --build-arg DISABLE_MINIFY=yes; +#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes --build-arg DISABLE_TRANSLATE=yes; +#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes --build-arg DISABLE_MINIFY=yes --build-arg DISABLE_TRANSLATE=yes; + +echo ""; +echo -e $MSG; + +exit 0;