Dockerfile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. FROM --platform=$BUILDPLATFORM node:20-alpine AS builder
  2. RUN mkdir -p /opt/meshcentral/meshcentral
  3. COPY ./ /opt/meshcentral/meshcentral/
  4. WORKDIR /opt/meshcentral
  5. ARG DISABLE_MINIFY=""
  6. ARG DISABLE_TRANSLATE=""
  7. RUN if ! [ -z "$DISABLE_MINIFY" ] && [ "$DISABLE_MINIFY" != "yes" ] && [ "$DISABLE_MINIFY" != "YES" ] \
  8. && [ "$DISABLE_MINIFY" != "true" ] && [ "$DISABLE_MINIFY" != "TRUE" ]; then \
  9. echo -e "\e[0;31;49mInvalid value for build argument DISABLE_MINIFY, possible values: yes/true\e[;0m"; exit 1; \
  10. fi
  11. RUN if ! [ -z "$DISABLE_TRANSLATE" ] && [ "$DISABLE_TRANSLATE" != "yes" ] && [ "$DISABLE_TRANSLATE" != "YES" ] \
  12. && [ "$DISABLE_TRANSLATE" != "true" ] && [ "$DISABLE_TRANSLATE" != "TRUE" ]; then \
  13. echo -e "\e[0;31;49mInvalid value for build argument DISABLE_TRANSLATE, possible values: yes/true\e[;0m"; exit 1; \
  14. fi
  15. # install translate/minify modules if need too
  16. RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral && npm install html-minifier@4.0.0 jsdom@22.1.0 esprima@4.0.1; fi
  17. # first extractall if need too
  18. RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js extractall; fi
  19. # minify files
  20. RUN if [ -z "$DISABLE_MINIFY" ]; then cd meshcentral/translate && node translate.js minifyall; fi
  21. # translate
  22. RUN if [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js translateall; fi
  23. # cleanup
  24. RUN rm -rf /opt/meshcentral/meshcentral/docker
  25. RUN rm -rf /opt/meshcentral/meshcentral/node_modules
  26. FROM --platform=$TARGETPLATFORM alpine:3.19
  27. #Add non-root user, add installation directories and assign proper permissions
  28. RUN mkdir -p /opt/meshcentral/meshcentral
  29. # meshcentral installation
  30. WORKDIR /opt/meshcentral
  31. RUN apk update \
  32. && apk add --no-cache --update tzdata nodejs npm bash python3 make gcc g++ \
  33. && rm -rf /var/cache/apk/*
  34. RUN npm install -g npm@latest
  35. ARG INCLUDE_MONGODBTOOLS=""
  36. ARG PREINSTALL_LIBS="false"
  37. # environment variables
  38. ENV NODE_ENV="production"
  39. ENV CONFIG_FILE="config.json"
  40. # environment variables for initial configuration file
  41. ENV USE_MONGODB="false"
  42. ENV MONGO_INITDB_ROOT_USERNAME="root"
  43. ENV MONGO_INITDB_ROOT_PASSWORD="pass"
  44. ENV MONGO_URL=""
  45. ENV HOSTNAME="localhost"
  46. ENV ALLOW_NEW_ACCOUNTS="true"
  47. ENV ALLOWPLUGINS="false"
  48. ENV LOCALSESSIONRECORDING="false"
  49. ENV MINIFY="true"
  50. ENV WEBRTC="false"
  51. ENV IFRAME="false"
  52. ENV SESSION_KEY=""
  53. ENV REVERSE_PROXY="false"
  54. ENV REVERSE_PROXY_TLS_PORT=""
  55. ENV ARGS=""
  56. RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ] && [ "$INCLUDE_MONGODBTOOLS" != "yes" ] && [ "$INCLUDE_MONGODBTOOLS" != "YES" ] \
  57. && [ "$INCLUDE_MONGODBTOOLS" != "true" ] && [ "$INCLUDE_MONGODBTOOLS" != "TRUE" ]; then \
  58. echo -e "\e[0;31;49mInvalid value for build argument INCLUDE_MONGODBTOOLS, possible values: yes/true\e[;0m"; exit 1; \
  59. fi
  60. RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then apk add --no-cache mongodb-tools; fi
  61. # copy files from builder-image
  62. COPY --from=builder /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral
  63. COPY ./docker/startup.sh ./startup.sh
  64. COPY ./docker/config.json.template /opt/meshcentral/config.json.template
  65. # install dependencies from package.json and nedb
  66. RUN cd meshcentral && npm install && npm install nedb
  67. # NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN meshcentral.js mainStart()
  68. RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then cd meshcentral && npm install mongodb@4.13.0 saslprep@1.0.3; fi
  69. RUN if ! [ -z "$PREINSTALL_LIBS" ] && [ "$PREINSTALL_LIBS" == "true" ]; then cd meshcentral && npm install ssh2@1.16.0 semver@7.5.4 nodemailer@6.9.15 image-size@1.1.1 wildleek@2.0.0 otplib@10.2.3 yubikeyotp@0.2.0; fi
  70. EXPOSE 80 443 4433
  71. # volumes
  72. VOLUME /opt/meshcentral/meshcentral-data
  73. VOLUME /opt/meshcentral/meshcentral-files
  74. VOLUME /opt/meshcentral/meshcentral-web
  75. VOLUME /opt/meshcentral/meshcentral-backups
  76. CMD ["bash", "/opt/meshcentral/startup.sh"]