refac(docker): half the Docker image size due to deferment of compilation (#7227)
* Merge into master (#11) * Made the workflow build multiple images for simplicity * New method * Trying workflow * Finalize * Reset package files to upstream/master * Edit workflow according to @si458 * Whoops accidentally removed these. Back again. --------- Co-authored-by: Daan Selen <dselen@systemec.nl> * Integrate the syslog compiler * Changed logging accordingly. * Looks to be a working prototype * chore(docker): bump alpine version * feat: make simon less anxious :P --------- Co-authored-by: Daan Selen <dselen@systemec.nl>
DaanSelen committed
Sep 16, 2025 at 20:22 UTC
ea341774e5168d1868b802d48ba41371343469a6
4 files changed
+29
-8
.github/workflows/docker.yml
+1
-1
@@ -43,7 +43,7 @@ jobs:
43
include_postgresql: false
44
include_mysql: true
45
tag_suffix: "-mysql"
46
-
46
+
47
steps:
48
- name: Checkout repository
49
uses: actions/checkout@v4
docker/Dockerfile
+23
-5
@@ -40,11 +40,24 @@ RUN if [ -n "$DISABLE_MINIFY" ] || [ -n "$DISABLE_TRANSLATE" ]; then \
40
RUN rm -rf /opt/meshcentral/meshcentral/docker
41
RUN rm -rf /opt/meshcentral/meshcentral/node_modules
42
43
-### STAGE 2 BUILDING.
43
+### STAGE 2 PRECOMPILE SYSLOG MODULE
44
45
-FROM alpine:3.22
45
+FROM alpine:3.22 AS syslog-compiler
46
47
-# copy files from builder-image
47
+RUN apk update && \
48
+ echo -e "----------\nINSTALLING ALPINE PACKAGES...\n----------"; \
49
+ apk add --no-cache --update \
50
+ bash gcc g++ jq make nodejs npm python3 tzdata
51
+
52
+RUN mkdir -p /opt/syslog
53
+WORKDIR /opt/syslog
54
+RUN npm install modern-syslog
55
+
56
+### STAGE 3 RUNTIME
57
+
58
+FROM alpine:3.22 AS runtime
59
+
60
+# Copy prepared app from builder stage
61
COPY --from=builder /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral
62
63
# environment variables
@@ -101,13 +114,12 @@ ENV MARIADB_HOST="" \
114
MARIADB_PASS="" \
115
MARIADB_DATABASE=""
116
104
-RUN mkdir -p /opt/meshcentral/meshcentral
117
WORKDIR /opt/meshcentral
118
119
RUN apk update && \
120
echo -e "----------\nINSTALLING ALPINE PACKAGES...\n----------"; \
121
apk add --no-cache --update \
110
- bash gcc g++ jq make nodejs npm python3 tzdata && \
122
+ bash jq nodejs npm tzdata && \
123
rm -rf /var/cache/* \
124
/tmp/* \
125
/usr/share/man/ \
@@ -175,6 +187,12 @@ RUN cd meshcentral && \
187
npm cache clean --force && \
188
rm -rf /root/ /tmp/
189
190
+COPY --from=syslog-compiler /opt/syslog/node_modules/modern-syslog /opt/meshcentral/meshcentral/node_modules/modern-syslog
191
+
192
+RUN jq '.dependencies["modern-syslog"] = "^1.2.0"' /opt/meshcentral/meshcentral/package.json \
193
+ > /opt/meshcentral/meshcentral/package.json.tmp \
194
+ && mv /opt/meshcentral/meshcentral/package.json.tmp /opt/meshcentral/meshcentral/package.json
195
+
196
# Expose needed ports
197
EXPOSE 80 443
198
docker/entrypoint.sh
+4
-2
@@ -1,8 +1,8 @@
1
#!/bin/bash
2
3
graceful_shutdown() {
4
- echo "Received SIGTERM. Cleaning up..."
5
- node /opt/meshcentral/meshcentral/meshcentral --stop
4
+ echo "Received SIGTERM from the container host. Cleaning up..."
5
+ kill -SIGINT $meshcentral_pid
6
7
echo "MeshCentral process stopped. Exiting..."
8
exit 0
@@ -11,6 +11,8 @@ trap graceful_shutdown SIGTERM
11
12
### Start MeshCentral Docker Container.
13
14
+# Make the start more cleared when restarted.
15
+echo "-------------------------------------------------------------"
16
date
17
echo "Config file: $CONFIG_FILE"
18
package.json
+1
@@ -50,6 +50,7 @@
50
"minimist": "1.2.8",
51
"multiparty": "4.2.3",
52
"node-forge": "1.3.1",
53
+ "otplib": "12.0.1",
54
"ua-client-hints-js": "0.1.2",
55
"ua-parser-js": "1.0.40",
56
"ws": "8.18.0",