bugfix: run 'node translate.js extractall' only when DISABLE_TRANSLATE is not set
Simon Schön committed
Jun 9, 2022 at 21:25 UTC
cf553d1a0faa5cd938c21a08e7703913b7e92749
4 files changed
+39
-25
docker/Dockerfile
+21
-7
@@ -11,27 +11,41 @@ RUN apk add --no-cache bash
11
12
FROM base AS builder
13
14
-ARG DISABLE_TRANSLATE=""
14
ARG DISABLE_MINIFY=""
15
+ARG DISABLE_TRANSLATE=""
16
17
RUN mkdir /opt/meshcentral/meshcentral
18
COPY ./ /opt/meshcentral/meshcentral/
19
20
-# Extract all MeshCentral strings from web pages and generate the languages.json file. - first try throws Error: Cannot find module 'jsdom'
21
-RUN cd meshcentral/translate && node translate.js extractall; exit 0;
22
-RUN cd meshcentral/translate && node translate.js extractall
20
+RUN if ! [ -z "$DISABLE_MINIFY" ] && [ "$DISABLE_MINIFY" != "yes" ] && [ "$DISABLE_MINIFY" != "YES" ] \
21
+ && [ "$DISABLE_MINIFY" != "true" ] && [ "$DISABLE_MINIFY" != "TRUE" ]; then \
22
+ echo -e "\e[0;31;49mInvalid value for build argument DISABLE_MINIFY, possible values: yes/true\e[;0m"; exit 1; \
23
+ fi
24
+RUN if ! [ -z "$DISABLE_TRANSLATE" ] && [ "$DISABLE_TRANSLATE" != "yes" ] && [ "$DISABLE_TRANSLATE" != "YES" ] \
25
+ && [ "$DISABLE_TRANSLATE" != "true" ] && [ "$DISABLE_TRANSLATE" != "TRUE" ]; then \
26
+ echo -e "\e[0;31;49mInvalid value for build argument DISABLE_TRANSLATE, possible values: yes/true\e[;0m"; exit 1; \
27
+ fi
28
+
29
+# first try throws Error: Cannot find module 'jsdom'
30
+RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js extractall; exit 0; fi
31
32
# minify files
25
-RUN if [ "$DISABLE_MINIFY" != "yes" ] && [ "$DISABLE_MINIFY" != "YES" ]; then cd meshcentral/translate && node translate.js minifyall; fi
33
+RUN if [ -z "$DISABLE_MINIFY" ]; then cd meshcentral/translate && node translate.js minifyall; fi
34
35
# translate
28
-RUN if [ "$DISABLE_TRANSLATE" != "yes" ] && [ "$DISABLE_TRANSLATE" != "YES" ]; then cd meshcentral/translate && node translate.js translateall; fi
36
+RUN if [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js extractall; fi
37
+RUN if [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js translateall; fi
38
39
40
FROM base
41
42
ARG INCLUDE_MONGODBTOOLS=""
34
-RUN if [ "$INCLUDE_MONGODBTOOLS" == "yes" ] || [ "$INCLUDE_MONGODBTOOLS" == "YES" ]; then apk add --no-cache mongodb-tools; fi
43
+RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ] && [ "$INCLUDE_MONGODBTOOLS" != "yes" ] && [ "$INCLUDE_MONGODBTOOLS" != "YES" ] \
44
+ && [ "$INCLUDE_MONGODBTOOLS" != "true" ] && [ "$INCLUDE_MONGODBTOOLS" != "TRUE" ]; then \
45
+ echo -e "\e[0;31;49mInvalid value for build argument INCLUDE_MONGODBTOOLS, possible values: yes/true\e[;0m"; exit 1; \
46
+ fi
47
+
48
+RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then apk add --no-cache mongodb-tools; fi
49
50
# copy files from builder-image
51
COPY --from=builder /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral
docker/docker.build.sh
+16
-16
@@ -3,13 +3,16 @@
3
MSG="";
4
PRUNE="false";
5
6
+LOG_FILE=""
7
+#LOG_FILE="$(dirname -- "$( readlink -f -- "$0"; )")/build.log";
8
+
9
function appendOutput()
10
{
11
if [ -z "${MSG}" ]; then echo -e "\n" > /dev/tty; fi
12
13
ARGS=$@;
11
- LINE="${ARGS}\n"
12
- echo -e "${LINE}" > /dev/tty;
14
+ LINE="${ARGS}\n";
15
+ if [ -z "${LOG_FILE}" ]; then echo -e "${LINE}" > /dev/tty; else echo -e "${LINE}" &>> "${LOG_FILE}"; fi
16
17
MSG="${MSG}${LINE}";
18
}
@@ -24,7 +27,7 @@ function runDockerBuild()
27
BUILD_CMD="docker build -f docker/Dockerfile --force-rm --no-cache ${ARGS} -t meshcentral .";
28
appendOutput "Current build: ${BUILD_CMD}";
29
27
- ${BUILD_CMD};
30
+ if [ -z "${LOG_FILE}" ]; then ${BUILD_CMD}; else ${BUILD_CMD} &>> "${LOG_FILE}"; fi
31
if [ $? -ne 0 ]; then exit $?; fi
32
33
ENDTS=$(date +%s);
@@ -42,15 +45,12 @@ function runDockerBuild()
45
else appendOutput "\tBuild time: ${DIFSEC} sec"; fi
46
47
IMG_SIZE=$(docker image inspect meshcentral | grep -e "\"Size\"" | tr -d '",' | sed -E "s/\s*Size:\s*//");
45
- expr $IMG_SIZE + 0;
46
- appendOutput "\tImage size: ${IMG_SIZE} ($((${IMG_SIZE}/1024/1024))M)";
47
-
48
- appendOutput "\n";
48
+ expr $IMG_SIZE + 0 > /dev/null;
49
+ appendOutput "\tImage size: ${IMG_SIZE} ($((${IMG_SIZE}/1024/1024))M)\n";
50
51
return 0;
52
}
53
53
-
54
parent_path=$(dirname -- $(dirname -- "$( readlink -f -- "$0"; )"));
55
if [ "${parent_path}" != "$(pwd -P)" ]; then
56
echo -e "change working directory to: ${parent_path}" > /dev/tty;
@@ -59,17 +59,17 @@ fi
59
60
if ! [ -z $1 ] && [ "${1}" == "prune" ]; then PRUNE="true"; fi
61
62
-runDockerBuild;
63
-#runDockerBuild --build-arg DISABLE_MINIFY=yes;
64
-#runDockerBuild --build-arg DISABLE_TRANSLATE=yes;
62
#runDockerBuild --build-arg DISABLE_MINIFY=yes --build-arg DISABLE_TRANSLATE=yes;
63
+#runDockerBuild --build-arg DISABLE_TRANSLATE=yes;
64
+#runDockerBuild --build-arg DISABLE_MINIFY=yes;
65
+runDockerBuild;
66
67
-#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes;
68
-#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes --build-arg DISABLE_MINIFY=yes;
69
-#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes --build-arg DISABLE_TRANSLATE=yes;
70
-#runDockerBuild --build-arg INCLUDE_MONGOTOOLS=yes --build-arg DISABLE_MINIFY=yes --build-arg DISABLE_TRANSLATE=yes;
67
+#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes --build-arg DISABLE_MINIFY=yes --build-arg DISABLE_TRANSLATE=yes;
68
+#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes --build-arg DISABLE_TRANSLATE=yes;
69
+#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes --build-arg DISABLE_MINIFY=yes;
70
+#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes;
71
72
echo "";
73
-echo -e $MSG;
73
+echo -e "${MSG}";
74
75
exit 0;
docker/readme.md
+1
-1
@@ -24,7 +24,7 @@
24
### Optional build arguments
25
> | Argument | Description |
26
> | :--- | :--- |
27
-> | INCLUDE_MONGOTOOLS=yes | Includes mongodb-tools (mongodump, ...) in the image |
27
+> | INCLUDE_MONGODBTOOLS=yes | Includes mongodb-tools (mongodump, ...) in the image |
28
> | DISABLE_MINIFY=yes | Disables the minification of files |
29
> | DISABLE_TRANSLATE=yes | Disables the translation of files |
30
docker/startup.sh
+1
-1
@@ -17,7 +17,7 @@ if [ -f "meshcentral-data/config.json" ]
17
node meshcentral/meshcentral
18
else
19
cp config.json.template meshcentral-data/config.json
20
- if [ $USE_MONGODB == true ]; then
20
+ if ! [ -z "$USE_MONGODB" ] && [ "$USE_MONGODB" == "true" ]; then
21
sed -i "s/\"_mongoDb\": null/\"mongoDb\": \"mongodb:\/\/$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@mongodb:27017\"/" meshcentral-data/config.json
22
fi
23
sed -i "s/\"cert\": \"myserver.mydomain.com\"/\"cert\": \"$HOSTNAME\"/" meshcentral-data/config.json