Dockerfile-debian 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. ### STAGE 1 BUILDING.
  2. FROM node:22-trixie-slim AS builder
  3. # Any value inside one of the disable ARGs will be accepted.
  4. ARG DISABLE_EXTRACT="yes"
  5. ARG DISABLE_MINIFY="yes"
  6. ARG DISABLE_TRANSLATE="yes"
  7. # NODE_OPTIONS="--max_old_space_size=4096"
  8. # If your process gets OOM killed, perhaps the above will help.
  9. RUN mkdir -p /opt/meshcentral/meshcentral
  10. WORKDIR /opt/meshcentral
  11. COPY ./ /opt/meshcentral/meshcentral/
  12. # Check the Docker build arguments and if they are empty do the task.
  13. RUN if [ -n "$DISABLE_EXTRACT" ] || [ -n "$DISABLE_MINIFY" ] || [ -n "$DISABLE_TRANSLATE" ]; then \
  14. echo -e "----------\nPREPARING ENVIRONMENT...\n----------"; \
  15. cd meshcentral && \
  16. npm install [email protected] [email protected] [email protected] && \
  17. cd translate && \
  18. case "$DISABLE_EXTRACT" in \
  19. false|no|FALSE|NO) \
  20. echo -e "----------\nSTARTING THE EXTRACTING PROCESS...\n----------"; \
  21. node translate.js extractall;; \
  22. *) \
  23. echo "Setting EXTRACT as disabled.";; \
  24. esac && \
  25. case "$DISABLE_MINIFY" in \
  26. false|no|FALSE|NO) \
  27. echo -e "----------\nSTARTING THE MINIFYING PROCESS...\n----------"; \
  28. node translate.js minifyall;; \
  29. *) \
  30. echo "Setting MINIFY as disabled.";; \
  31. esac && \
  32. case "$DISABLE_TRANSLATE" in \
  33. false|no|FALSE|NO) \
  34. echo -e "----------\nSTARTING THE TRANSLATING PROCESS...\n----------"; \
  35. node translate.js translateall;; \
  36. *) \
  37. echo "Setting TRANSLATE as disabled.";; \
  38. esac; \
  39. npm uninstall html-minifier-terser jsdom esprima; \
  40. fi
  41. # Possible more updated alternative? @minify-html/[email protected] -> https://www.npmjs.com/package/@minify-html/node
  42. RUN rm -rf /opt/meshcentral/meshcentral/docker /opt/meshcentral/meshcentral/node_modules /opt/meshcentral/meshcentral/docs
  43. ### STAGE 2 PRECOMPILE DEPS MODULE
  44. FROM node:22-trixie-slim AS dep-compiler
  45. ENV NODE_ENV="production"
  46. RUN apt-get update && \
  47. echo -e "----------\nINSTALLING DEBIAN PACKAGES...\n----------"; \
  48. apt-get install -y --no-install-recommends --no-install-suggests \
  49. bash gcc g++ jq make python3 tzdata
  50. COPY --from=builder /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral
  51. WORKDIR /opt/meshcentral/meshcentral
  52. RUN jq '.dependencies += {"modern-syslog": "1.2.0", "telegram": "2.26.22"}' package.json > temp.json && mv temp.json package.json \
  53. && npm i --package-lock-only \
  54. && npm ci --omit=dev \
  55. && npm cache clean --force
  56. ### STAGE 3 fun. building from source...
  57. FROM golang:trixie AS mongo-tools-compiler
  58. ARG INCLUDE_MONGODB_TOOLS="false"
  59. RUN apt-get update && \
  60. apt-get install -y --no-install-recommends --no-install-suggests \
  61. git lsb-release
  62. RUN case "$INCLUDE_MONGODB_TOOLS" in \
  63. true|yes|TRUE|YES) \
  64. git clone https://github.com/mongodb/mongo-tools /mongo-tools; \
  65. cd /mongo-tools; \
  66. ./make build -pkgs=mongodump,mongorestore;; \
  67. false|no|FALSE|NO) \
  68. echo "Not building MongoDB Tools from source, what a shame!"; \
  69. mkdir -p /mongo-tools/bin;; \
  70. *) \
  71. echo "Invalid value for build argument INCLUDE_MONGODB_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
  72. exit 1;; \
  73. esac
  74. ### STAGE 4 BUILDING.
  75. FROM node:22-trixie-slim AS finalizer
  76. # Copy files from previous layers
  77. COPY --from=dep-compiler /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral
  78. COPY --from=mongo-tools-compiler /mongo-tools/bin/ /tmp/bin/
  79. # environment variables
  80. ENV NODE_ENV="production" \
  81. CONFIG_FILE="/opt/meshcentral/meshcentral-data/config.json" \
  82. DYNAMIC_CONFIG="false"
  83. # environment variables for the above defined MeshCentral Config.json. Can be done like that following: https://docs.docker.com/reference/dockerfile/#env
  84. ENV ALLOW_PLUGINS="false" \
  85. ALLOW_NEW_ACCOUNTS="false" \
  86. ALLOWED_ORIGIN="false" \
  87. HOSTNAME="localhost" \
  88. PORT="443" \
  89. REDIR_PORT="80" \
  90. INSTALL_STYLISHUI="false" \
  91. IFRAME="false" \
  92. LOCAL_SESSION_RECORDING="true" \
  93. MINIFY="true" \
  94. REVERSE_PROXY="" \
  95. REVERSE_PROXY_TLS_PORT="443" \
  96. REGEN_SESSIONKEY="false" \
  97. STYLISHUI_FORCE_LATEST="false" \
  98. WEBRTC="false" \
  99. TRUSTED_PROXY="" \
  100. ARGS=""
  101. # Database
  102. # Multi-variable declaration to reduce layers.
  103. ENV USE_MONGODB="false" \
  104. USE_POSTGRESQL="false" \
  105. USE_MARIADB="false"
  106. # Preinstallation args one per line due to: https://docs.docker.com/reference/dockerfile/#arg
  107. ARG PREINSTALL_LIBS="false"
  108. ARG INCLUDE_MONGODB_TOOLS="false"
  109. ARG INCLUDE_POSTGRESQL_TOOLS="false"
  110. ARG INCLUDE_MARIADB_TOOLS="false"
  111. # MongoDB Variables
  112. # The following MONGO_URL variable overwrites most other mongoDb related varialbes.
  113. ENV MONGO_HOST="" \
  114. MONGO_PORT="27017" \
  115. MONGO_USERNAME="" \
  116. MONGO_PASS="" \
  117. MONGO_URL=""
  118. # PostgreSQL Variables
  119. ENV PSQL_HOST="" \
  120. PSQL_PORT="5432" \
  121. PSQL_USER="" \
  122. PSQL_PASS="" \
  123. PSQL_DATABASE=""
  124. # MariaDB/MySQL Variables.
  125. ENV MARIADB_HOST="" \
  126. MARIADB_PORT="3306" \
  127. MARIADB_USER="" \
  128. MARIADB_PASS="" \
  129. MARIADB_DATABASE=""
  130. WORKDIR /opt/meshcentral
  131. RUN apt-get update && \
  132. echo -e "----------\nINSTALLING DEBIAN PACKAGES...\n----------"; \
  133. apt-get install -y --no-install-recommends --no-install-suggests \
  134. bash curl jq tzdata && \
  135. rm -rf \
  136. /var/cache/* \
  137. /usr/share/man/ \
  138. /usr/share/doc/ \
  139. /var/log/* \
  140. /var/spool/* \
  141. /var/tmp/* \
  142. /usr/lib/debug/ && \
  143. npm install -g npm@latest
  144. RUN case "$PREINSTALL_LIBS" in \
  145. true|yes|TRUE|YES) \
  146. cd meshcentral && \
  147. echo -e "----------\nPREINSTALLING LIBRARIES...\n----------"; \
  148. npm install [email protected] [email protected] [email protected] [email protected] [email protected] [email protected];; \
  149. false|no|FALSE|NO) \
  150. echo "Not pre-installing libraries.";; \
  151. *) \
  152. echo -e "Invalid value for build argument INCLUDE_POSTGRESQL_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
  153. exit 1;; \
  154. esac
  155. # NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN meshcentraljs mainStart()
  156. RUN case "$INCLUDE_MONGODB_TOOLS" in \
  157. true|yes|TRUE|YES) \
  158. mv /tmp/bin/* /usr/bin; \
  159. cd meshcentral && \
  160. echo -e "----------\nPREINSTALLING MONGODB LIBRARIES...\n----------"; \
  161. npm install [email protected] @mongodb-js/[email protected];; \
  162. false|no|FALSE|NO) \
  163. echo "Not including MongoDB Tools.";; \
  164. *) \
  165. echo "Invalid value for build argument INCLUDE_MONGODB_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
  166. exit 1;; \
  167. esac
  168. RUN case "$INCLUDE_POSTGRESQL_TOOLS" in \
  169. true|yes|TRUE|YES) \
  170. apt-get install -y --no-install-recommends --no-install-suggests postgresql-client-17; \
  171. cd meshcentral && \
  172. echo -e "----------\nPREINSTALLING POSTGRESQL LIBRARIES...\n----------"; \
  173. npm install [email protected];; \
  174. false|no|FALSE|NO) \
  175. echo "Not including PostgreSQL Tools.";; \
  176. *) \
  177. echo -e "Invalid value for build argument INCLUDE_POSTGRESQL_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
  178. exit 1;; \
  179. esac
  180. RUN case "$INCLUDE_MARIADB_TOOLS" in \
  181. true|yes|TRUE|YES) \
  182. apt-get install -y --no-install-recommends --no-install-suggests default-mysql-client mariadb-client; \
  183. cd meshcentral && \
  184. echo -e "----------\nPREINSTALLING MARIADB/MYSQL LIBRARIES...\n----------"; \
  185. npm install [email protected] [email protected];; \
  186. false|no|FALSE|NO) \
  187. echo "Not including MariaDB/MySQL Tools.";; \
  188. *) \
  189. echo -e "Invalid value for build argument INCLUDE_MARIADB_TOOLS, possible values: 'yes', 'true', 'no' or 'false'"; \
  190. exit 1;; \
  191. esac
  192. # Remove left over files and cache
  193. RUN cd meshcentral \
  194. && rm -rf /root /tmp/* /var/tmp/* /usr/lib/node_modules/npm/man /usr/lib/node_modules/npm/doc /usr/lib/node_modules/npm/html \
  195. && npm cache clean --force
  196. # Expose needed ports
  197. EXPOSE ${PORT}
  198. EXPOSE ${REDIR_PORT}
  199. # These volumes will be created by default even without any declaration, this allows default persistence in Docker/Podman. Dummy-proofing.
  200. VOLUME /opt/meshcentral/meshcentral-data
  201. VOLUME /opt/meshcentral/meshcentral-files
  202. VOLUME /opt/meshcentral/meshcentral-web
  203. VOLUME /opt/meshcentral/meshcentral-backups
  204. # Copy images from Git repo, place it before ending so recompilation can make good use of cache.
  205. COPY ./docker/entrypoint.sh /opt/meshcentral/entrypoint.sh
  206. COPY ./docker/config.json.template /opt/meshcentral/config.json.template
  207. ENTRYPOINT ["/bin/bash", "/opt/meshcentral/entrypoint.sh"]