-
Notifications
You must be signed in to change notification settings - Fork 784
[ENH](/[REFAC]) Docker Image Building and Usage refactor. #6937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
da5ef52
ddeeb8c
6eb85fa
5594b15
86ecc42
e11a858
59194ab
660312e
62443dd
1604764
8448a6a
c2f590e
6a99f3c
162b372
51ad698
7f0f12a
3919c12
470f22b
1e897ee
c5a2286
39e5691
910f12c
db7eacb
9e6b98a
e3636c0
75df7b8
6008767
ea1b71e
46f7784
9464c1b
17a3632
23c8c49
ecd32fa
8b2dcf4
90b2a3d
4cd9196
5f306a2
0514f4a
8c5c319
b7512b9
39395c9
59ca8b0
d864789
5d47415
6eacc9f
f17b96b
5223cbd
5d18a1a
933b37f
6bb6b18
620df54
ae0aa7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -310,4 +310,5 @@ __pycache__/ | |
|
|
||
| # When running mkdocs locally as dev | ||
| docs/__pycache__/ | ||
| docs/env/ | ||
| docs/env/ | ||
| docker-compose.yaml | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,103 +1,181 @@ | ||
| FROM --platform=$BUILDPLATFORM node:22-alpine AS builder | ||
| ### STAGE 1 BUILDING. | ||
| FROM node:lts-alpine3.21 AS builder | ||
|
|
||
| # Any value inside one of the disable ARGs will be accepted. | ||
| ARG DISABLE_MINIFY="yes" \ | ||
| DISABLE_TRANSLATE="yes" | ||
|
|
||
| RUN mkdir -p /opt/meshcentral/meshcentral | ||
| COPY ./ /opt/meshcentral/meshcentral/ | ||
| WORKDIR /opt/meshcentral | ||
| COPY ./ /opt/meshcentral/meshcentral/ | ||
|
|
||
| ARG DISABLE_MINIFY="" | ||
| ARG DISABLE_TRANSLATE="" | ||
|
|
||
|
|
||
| RUN if ! [ -z "$DISABLE_MINIFY" ] && [ "$DISABLE_MINIFY" != "yes" ] && [ "$DISABLE_MINIFY" != "YES" ] \ | ||
| && [ "$DISABLE_MINIFY" != "true" ] && [ "$DISABLE_MINIFY" != "TRUE" ]; then \ | ||
| echo -e "\e[0;31;49mInvalid value for build argument DISABLE_MINIFY, possible values: yes/true\e[;0m"; exit 1; \ | ||
| # Check the Docker build arguments and if they are empty do the task. | ||
| RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then \ | ||
| cd meshcentral && \ | ||
| npm install [email protected] [email protected] [email protected] && \ | ||
| cd translate && \ | ||
| node translate.js extractall && \ | ||
| case "$DISABLE_MINIFY" in \ | ||
DaanSelen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| false|no|FALSE|NO) \ | ||
| node translate.js minifyall;; \ | ||
| *) \ | ||
| echo "Setting MINIFY as disabled.";; \ | ||
| esac && \ | ||
| case "$DISABLE_TRANSLATE" in \ | ||
| false|no|FALSE|NO) \ | ||
| node translate.js translateall;; \ | ||
| *) \ | ||
| echo "Setting TRANSLATE as disabled.";; \ | ||
| esac \ | ||
| fi | ||
| RUN if ! [ -z "$DISABLE_TRANSLATE" ] && [ "$DISABLE_TRANSLATE" != "yes" ] && [ "$DISABLE_TRANSLATE" != "YES" ] \ | ||
| && [ "$DISABLE_TRANSLATE" != "true" ] && [ "$DISABLE_TRANSLATE" != "TRUE" ]; then \ | ||
| echo -e "\e[0;31;49mInvalid value for build argument DISABLE_TRANSLATE, possible values: yes/true\e[;0m"; exit 1; \ | ||
| fi | ||
|
|
||
| # install translate/minify modules if need too | ||
| RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral && npm install [email protected] [email protected] [email protected]; fi | ||
|
|
||
| # first extractall if need too | ||
| RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js extractall; fi | ||
| # Possible more updated alternative? @minify-html/[email protected] -> https://www.npmjs.com/package/@minify-html/node | ||
|
|
||
| # minify files | ||
| RUN if [ -z "$DISABLE_MINIFY" ]; then cd meshcentral/translate && node translate.js minifyall; fi | ||
| RUN cd meshcentral \ | ||
| && npm uninstall html-minifier jsdom esprima | ||
|
|
||
| # translate | ||
| RUN if [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral/translate && node translate.js translateall; fi | ||
| # cleanup for inter-container copying. | ||
|
|
||
| # cleanup | ||
| RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then cd meshcentral && npm remove html-minifier jsdom esprima; fi | ||
| RUN rm -rf /opt/meshcentral/meshcentral/docker | ||
| RUN rm -rf /opt/meshcentral/meshcentral/node_modules | ||
|
|
||
| ### STAGE 2 BUILDING. | ||
|
|
||
| FROM --platform=$TARGETPLATFORM alpine:3.21 | ||
| FROM alpine:3.21 | ||
|
|
||
| #Add non-root user, add installation directories and assign proper permissions | ||
| RUN mkdir -p /opt/meshcentral/meshcentral | ||
| # environment variables | ||
| ENV NODE_ENV="production" \ | ||
| CONFIG_FILE="/opt/meshcentral/meshcentral-data/config.json" \ | ||
| DYNAMIC_CONFIG="false" | ||
|
|
||
| # environment variables for the above defined MeshCentral Config.json | ||
| ENV ALLOW_PLUGINS="false" \ | ||
| ALLOW_NEW_ACCOUNTS="false" \ | ||
| ALLOWED_ORIGIN="false" \ | ||
| IFRAME="false" \ | ||
| REGEN_SESSIONKEY="false" \ | ||
| WEBRTC="false" \ | ||
| LOCAL_SESSION_RECORDING="true" \ | ||
| MINIFY="true" \ | ||
| HOSTNAME="localhost" \ | ||
| REVERSE_PROXY="" \ | ||
| REVERSE_PROXY_TLS_PORT="443" \ | ||
| TRUSTED_PROXY="" \ | ||
| ARGS="" | ||
|
|
||
| # Database | ||
| # Multi-variable declaration to reduce layers. | ||
| ENV USE_MONGODB="false" \ | ||
| USE_POSTGRESQL="false" \ | ||
| USE_MARIADB="false" | ||
|
|
||
| # Preinstallation args | ||
| ARG PREINSTALL_LIBS="false" \ | ||
| INCLUDE_MONGODB_TOOLS="false" \ | ||
| INCLUDE_POSTGRESQL_TOOLS="false" \ | ||
| INCLUDE_MARIADB_TOOLS="false" | ||
|
|
||
| # MongoDB Variables | ||
| # The following MONGO_URL variable overwrites most other mongoDb related varialbes. | ||
| ENV MONGO_HOST="" \ | ||
| MONGO_PORT="27017" \ | ||
| MONGO_USERNAME="" \ | ||
| MONGO_PASS="" \ | ||
| MONGO_URL="" | ||
|
|
||
| # PostgreSQL Variables | ||
| ENV PSQL_HOST="" \ | ||
| PSQL_PORT="5432" \ | ||
| PSQL_USER="" \ | ||
| PSQL_PASS="" \ | ||
| PSQL_DATABASE="" | ||
|
|
||
| # MariaDB/MySQL Variables, Alpine Linux only provides the actual MariaDB binaries. | ||
| ENV MARIADB_HOST="" \ | ||
| MARIADB_PORT="3306" \ | ||
| MARIADB_USER="" \ | ||
| MARIADB_PASS="" \ | ||
| MARIADB_DATABASE="" | ||
|
|
||
| # meshcentral installation | ||
| RUN mkdir -p /opt/meshcentral/meshcentral | ||
| WORKDIR /opt/meshcentral | ||
|
|
||
| RUN apk update \ | ||
| && apk add --no-cache --update tzdata nodejs npm bash python3 make gcc g++ \ | ||
| && rm -rf /var/cache/apk/* | ||
| && apk add --no-cache --update \ | ||
| bash gcc g++ jq make nodejs npm python3 tzdata \ | ||
| && rm -rf /var/cache/* \ | ||
| /tmp/* \ | ||
| /usr/share/man/ \ | ||
| /usr/share/doc/ \ | ||
| /var/log/* \ | ||
| /var/spool/* \ | ||
| /usr/lib/debug/ | ||
| RUN npm install -g npm@latest | ||
|
|
||
| ARG INCLUDE_MONGODBTOOLS="" | ||
| ARG PREINSTALL_LIBS="false" | ||
|
|
||
| # environment variables | ||
| ENV NODE_ENV="production" | ||
| ENV CONFIG_FILE="config.json" | ||
|
|
||
| # environment variables for initial configuration file | ||
| ENV USE_MONGODB="false" | ||
| ENV MONGO_INITDB_ROOT_USERNAME="root" | ||
| ENV MONGO_INITDB_ROOT_PASSWORD="pass" | ||
| ENV MONGO_URL="" | ||
| ENV HOSTNAME="localhost" | ||
| ENV ALLOW_NEW_ACCOUNTS="true" | ||
| ENV ALLOWPLUGINS="false" | ||
| ENV LOCALSESSIONRECORDING="true" | ||
| ENV MINIFY="false" | ||
| ENV WEBRTC="false" | ||
| ENV IFRAME="false" | ||
| ENV SESSION_KEY="" | ||
| ENV REVERSE_PROXY="false" | ||
| ENV REVERSE_PROXY_TLS_PORT="" | ||
| ENV ARGS="" | ||
| ENV ALLOWED_ORIGIN="false" | ||
|
|
||
| RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ] && [ "$INCLUDE_MONGODBTOOLS" != "yes" ] && [ "$INCLUDE_MONGODBTOOLS" != "YES" ] \ | ||
| && [ "$INCLUDE_MONGODBTOOLS" != "true" ] && [ "$INCLUDE_MONGODBTOOLS" != "TRUE" ]; then \ | ||
| echo -e "\e[0;31;49mInvalid value for build argument INCLUDE_MONGODBTOOLS, possible values: yes/true\e[;0m"; exit 1; \ | ||
| fi | ||
|
|
||
| RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then apk add --no-cache mongodb-tools; fi | ||
| RUN case "$PREINSTALL_LIBS" in \ | ||
DaanSelen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| true|yes|TRUE|YES) \ | ||
| cd meshcentral && \ | ||
| npm install [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected];; \ | ||
| false|no|FALSE|NO) \ | ||
| echo "Not pre-installing libraries.";; \ | ||
| *) \ | ||
| echo -e "Invalid value for build argument INCLUDE_POSTGRESQL_TOOLS, possible values: 'yes' or 'true'"; \ | ||
| exit 1;; \ | ||
| esac | ||
|
|
||
| # NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN meshcentraljs mainStart() | ||
| RUN case "$INCLUDE_MONGODB_TOOLS" in \ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider grouping the RUN statements into one to reduce the layers for the image.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing apt cache? I think we are using Alpine Linux with apk, with which we use |
||
| true|yes|TRUE|YES) \ | ||
| apk add --no-cache mongodb-tools && \ | ||
| cd meshcentral && npm install [email protected] \ | ||
| ;; \ | ||
| false|no|FALSE|NO) \ | ||
| echo "Not including MongoDB Tools.";; \ | ||
| *) \ | ||
| echo "Invalid value for build argument INCLUDE_MONGODB_TOOLS, possible values: 'yes' or 'true'"; \ | ||
| exit 1;; \ | ||
| esac | ||
|
|
||
| RUN case "$INCLUDE_POSTGRESQL_TOOLS" in \ | ||
| true|yes|TRUE|YES) \ | ||
| apk add --no-cache postgresql-client && \ | ||
| cd meshcentral && npm install [email protected] \ | ||
| ;; \ | ||
| false|no|FALSE|NO) \ | ||
| echo "Not including PostgreSQL Tools.";; \ | ||
| *) \ | ||
| echo -e "Invalid value for build argument INCLUDE_POSTGRESQL_TOOLS, possible values: 'yes' or 'true'"; \ | ||
| exit 1;; \ | ||
| esac | ||
|
|
||
| RUN case "$INCLUDE_MARIADB_TOOLS" in \ | ||
| true|yes|TRUE|YES) \ | ||
| apk add --no-cache mariadb-client && \ | ||
| cd meshcentral && npm install [email protected] [email protected] \ | ||
| ;; \ | ||
| false|no|FALSE|NO) \ | ||
| echo "Not including MariaDB/MySQL Tools.";; \ | ||
| *) \ | ||
| echo -e "Invalid value for build argument INCLUDE_MARIADB_TOOLS, possible values: 'yes' or 'true'"; \ | ||
| exit 1;; \ | ||
| esac | ||
|
|
||
| # copy files from builder-image | ||
| COPY --from=builder /opt/meshcentral/meshcentral /opt/meshcentral/meshcentral | ||
| COPY ./docker/startup.sh ./startup.sh | ||
| COPY ./docker/config.json.template /opt/meshcentral/config.json.template | ||
|
|
||
| # install dependencies from package.json | ||
| RUN cd meshcentral && npm install | ||
|
|
||
| # NOTE: ALL MODULES MUST HAVE A VERSION NUMBER AND THE VERSION MUST MATCH THAT USED IN meshcentral.js mainStart() | ||
| RUN if ! [ -z "$INCLUDE_MONGODBTOOLS" ]; then cd meshcentral && npm install [email protected]; fi | ||
| RUN if ! [ -z "$PREINSTALL_LIBS" ] && [ "$PREINSTALL_LIBS" == "true" ]; then cd meshcentral && npm install [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]; fi | ||
|
|
||
| EXPOSE 80 443 4433 | ||
| # Expose needed ports | ||
| EXPOSE 80 443 | ||
|
|
||
| # volumes | ||
| # These volumes will be created by default even without any declaration, this allows default persistence in Docker/Podman. | ||
| VOLUME /opt/meshcentral/meshcentral-data | ||
| VOLUME /opt/meshcentral/meshcentral-files | ||
| VOLUME /opt/meshcentral/meshcentral-web | ||
| VOLUME /opt/meshcentral/meshcentral-backups | ||
DaanSelen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| CMD ["bash", "/opt/meshcentral/startup.sh"] | ||
| # Copy images from Git repo, place it before ending so recompilation can make good use of cache. | ||
| COPY ./docker/entrypoint.sh ./entrypoint.sh | ||
| COPY ./docker/config.json.template /opt/meshcentral/config.json.template | ||
DaanSelen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ENTRYPOINT ["bash", "/opt/meshcentral/entrypoint.sh"] | ||
Uh oh!
There was an error while loading. Please reload this page.