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>
This commit is contained in:
DaanSelen
2025-09-16 20:22:36 +02:00
committed by GitHub
parent 0f247f835f
commit ea341774e5
4 changed files with 29 additions and 8 deletions

View File

@@ -40,11 +40,24 @@ RUN if [ -n "$DISABLE_MINIFY" ] || [ -n "$DISABLE_TRANSLATE" ]; then \
RUN rm -rf /opt/meshcentral/meshcentral/docker
RUN rm -rf /opt/meshcentral/meshcentral/node_modules
### STAGE 2 BUILDING.
### STAGE 2 PRECOMPILE SYSLOG MODULE
FROM alpine:3.22
FROM alpine:3.22 AS syslog-compiler
# copy files from builder-image
RUN apk update && \
echo -e "----------\nINSTALLING ALPINE PACKAGES...\n----------"; \
apk add --no-cache --update \
bash gcc g++ jq make nodejs npm python3 tzdata
RUN mkdir -p /opt/syslog
WORKDIR /opt/syslog
RUN npm install modern-syslog
### STAGE 3 RUNTIME
FROM alpine:3.22 AS runtime
# Copy prepared app from builder stage
COPY --from=builder /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral
# environment variables
@@ -101,13 +114,12 @@ ENV MARIADB_HOST="" \
MARIADB_PASS="" \
MARIADB_DATABASE=""
RUN mkdir -p /opt/meshcentral/meshcentral
WORKDIR /opt/meshcentral
RUN apk update && \
echo -e "----------\nINSTALLING ALPINE PACKAGES...\n----------"; \
apk add --no-cache --update \
bash gcc g++ jq make nodejs npm python3 tzdata && \
bash jq nodejs npm tzdata && \
rm -rf /var/cache/* \
/tmp/* \
/usr/share/man/ \
@@ -175,6 +187,12 @@ RUN cd meshcentral && \
npm cache clean --force && \
rm -rf /root/ /tmp/
COPY --from=syslog-compiler /opt/syslog/node_modules/modern-syslog /opt/meshcentral/meshcentral/node_modules/modern-syslog
RUN jq '.dependencies["modern-syslog"] = "^1.2.0"' /opt/meshcentral/meshcentral/package.json \
> /opt/meshcentral/meshcentral/package.json.tmp \
&& mv /opt/meshcentral/meshcentral/package.json.tmp /opt/meshcentral/meshcentral/package.json
# Expose needed ports
EXPOSE 80 443

View File

@@ -1,8 +1,8 @@
#!/bin/bash
graceful_shutdown() {
echo "Received SIGTERM. Cleaning up..."
node /opt/meshcentral/meshcentral/meshcentral --stop
echo "Received SIGTERM from the container host. Cleaning up..."
kill -SIGINT $meshcentral_pid
echo "MeshCentral process stopped. Exiting..."
exit 0
@@ -11,6 +11,8 @@ trap graceful_shutdown SIGTERM
### Start MeshCentral Docker Container.
# Make the start more cleared when restarted.
echo "-------------------------------------------------------------"
date
echo "Config file: $CONFIG_FILE"

View File

@@ -50,6 +50,7 @@
"minimist": "1.2.8",
"multiparty": "4.2.3",
"node-forge": "1.3.1",
"otplib": "12.0.1",
"ua-client-hints-js": "0.1.2",
"ua-parser-js": "1.0.40",
"ws": "8.18.0",