From ea341774e5168d1868b802d48ba41371343469a6 Mon Sep 17 00:00:00 2001 From: DaanSelen <80752476+DaanSelen@users.noreply.github.com> Date: Tue, 16 Sep 2025 20:22:36 +0200 Subject: [PATCH] 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 * 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 --- .github/workflows/docker.yml | 2 +- docker/Dockerfile | 28 +++++++++++++++++++++++----- docker/entrypoint.sh | 6 ++++-- package.json | 1 + 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5a2751b0..1ce9c603 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -43,7 +43,7 @@ jobs: include_postgresql: false include_mysql: true tag_suffix: "-mysql" - + steps: - name: Checkout repository uses: actions/checkout@v4 diff --git a/docker/Dockerfile b/docker/Dockerfile index 42da9422..921c1649 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index ca758ac3..04580c23 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -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" diff --git a/package.json b/package.json index dba7104e..043c930e 100644 --- a/package.json +++ b/package.json @@ -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",