refac(docker): fix npm install issues at runtime (#7282)

* 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.

* Integrate the syslog compiler

* Changed logging accordingly.

* Looks to be a working prototype

* chore(docker): bump alpine version

* feat: make simon less anxious :P

* refac: dockerfile and some package.json packages to improve compat

* chore: revert package lock

---------

Co-authored-by: Daan Selen <dselen@systemec.nl>
This commit is contained in:
DaanSelen 2025-09-18 11:23:12 +02:00 committed by GitHub
parent 4379eb5f33
commit 0a837aa96d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 136 additions and 272 deletions

View File

@ -12,6 +12,7 @@ WORKDIR /opt/meshcentral
COPY ./ /opt/meshcentral/meshcentral/
# Check the Docker build arguments and if they are empty do the task.
RUN apk add --no-cache python3 make g++ bash
RUN if [ -n "$DISABLE_MINIFY" ] || [ -n "$DISABLE_TRANSLATE" ]; then \
echo -e "----------\nPREPARING ENVIRONMENT...\n----------"; \
cd meshcentral && \
@ -40,18 +41,23 @@ 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 PRECOMPILE SYSLOG MODULE
### STAGE 2 PRECOMPILE DEPS MODULE
FROM alpine:3.22 AS syslog-compiler
FROM alpine:3.22 AS dep-compiler
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
RUN mkdir -p /opt/meshcentral
COPY ./package.json /opt/meshcentral/package.json
WORKDIR /opt/meshcentral
RUN jq '.dependencies["modern-syslog"] = "1.2.0"' package.json > tmp.$$.json \
&& mv tmp.$$.json package.json \
&& npm i --package-lock-only \
&& npm ci
### STAGE 3 RUNTIME
@ -59,6 +65,7 @@ FROM alpine:3.22 AS runtime
# Copy prepared app from builder stage
COPY --from=builder /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral
COPY --from=dep-compiler /opt/meshcentral/node_modules /opt/meshcentral/meshcentral/node_modules
# environment variables
ENV NODE_ENV="production" \
@ -183,16 +190,9 @@ RUN case "$INCLUDE_MARIADB_TOOLS" in \
# install dependencies from package.json
RUN cd meshcentral && \
npm install && \
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

384
package-lock.json generated

File diff suppressed because it is too large Load Diff