Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
da5ef52
Modified Dockerfile for readability
DaanSelen Mar 19, 2025
ddeeb8c
Renamed the workflow for better recognition and upgraded docker/build…
DaanSelen Mar 19, 2025
6eb85fa
Refactored more Dockerfile
DaanSelen Mar 20, 2025
5594b15
Merge branch 'Ylianst:master' into master
DaanSelen Mar 21, 2025
86ecc42
@DaanSelen Docker overhaul intermediate commit.
DaanSelen Mar 21, 2025
e11a858
I hate sed modification but I must.
DaanSelen Mar 21, 2025
59194ab
More work done on the logic. mongoDB url editing works.
DaanSelen Mar 22, 2025
660312e
Working prototype and clear and easy to understand logic.
DaanSelen Mar 22, 2025
62443dd
Dockerfile change.
DaanSelen Mar 23, 2025
1604764
Merge branch 'Ylianst:master' into dockerrewrite
DaanSelen Mar 23, 2025
8448a6a
Further foolproofed the Dockerfile.
DaanSelen Mar 23, 2025
c2f590e
Merge branch 'dockerrewrite' into latestcode
DaanSelen Mar 23, 2025
6a99f3c
Merge pull request #1 from DaanSelen/latestcode
DaanSelen Mar 23, 2025
162b372
Move preinstall libs to top.
DaanSelen Mar 23, 2025
51ad698
Use jq with mongo.
DaanSelen Mar 23, 2025
7f0f12a
sorted.
DaanSelen Mar 23, 2025
3919c12
Finishing up.
DaanSelen Mar 24, 2025
470f22b
Merge branch 'Ylianst:master' into dockerrewrite
DaanSelen Mar 24, 2025
1e897ee
Added support for psql mariadb.
DaanSelen Mar 24, 2025
c5a2286
More platforms supported.
DaanSelen Mar 24, 2025
39e5691
Make qemu ready.
DaanSelen Mar 24, 2025
910f12c
Merge branch 'Ylianst:master' into master
DaanSelen Mar 24, 2025
db7eacb
Added trustedproxy to dynamic config feature.
DaanSelen Mar 25, 2025
9e6b98a
Made names consistent
DaanSelen Mar 25, 2025
e3636c0
Merge pull request #2 from DaanSelen/master
DaanSelen Mar 25, 2025
75df7b8
added "true" to the all option for trusted_proxy env variable.
DaanSelen Mar 25, 2025
6008767
Wrong variable.
DaanSelen Mar 25, 2025
ea1b71e
Merge branch 'Ylianst:master' into dockerrewrite
DaanSelen Mar 31, 2025
46f7784
Release candidate.
DaanSelen Mar 31, 2025
9464c1b
Change example values
DaanSelen Mar 31, 2025
17a3632
Also for the docker compose
DaanSelen Mar 31, 2025
23c8c49
Compression of build arguments and environment variables.
DaanSelen Apr 9, 2025
ecd32fa
Pinning LTS version.
DaanSelen Apr 9, 2025
8b2dcf4
Removed case sensitivity in true/false prompts
DaanSelen Apr 9, 2025
90b2a3d
Add other volumes to readme.
DaanSelen Apr 9, 2025
4cd9196
case insensitivity hotfix.
DaanSelen Apr 9, 2025
5f306a2
include_mongodb_tools fix in workflow.
DaanSelen Apr 12, 2025
0514f4a
Merge branch 'Ylianst:master' into dockerrewrite
DaanSelen Apr 12, 2025
8c5c319
Pinning to Alpine 3.21
DaanSelen Apr 12, 2025
b7512b9
Disable dynamic config feature by default.
DaanSelen Apr 13, 2025
39395c9
Merge branch 'Ylianst:master' into dockerrewrite
DaanSelen Apr 25, 2025
59ca8b0
Merge branch 'Ylianst:master' into dockerrewrite
DaanSelen May 9, 2025
d864789
bump version
DaanSelen May 18, 2025
5d47415
added npm install and removed saslprep dependency.
DaanSelen May 18, 2025
6eacc9f
Merge branch 'master' into dockerrewrite
DaanSelen May 19, 2025
f17b96b
Commented out docker scout
DaanSelen May 19, 2025
5223cbd
removed possible unwanted references
DaanSelen May 19, 2025
5d18a1a
Added default exposure of non-encrypted http port.
DaanSelen May 19, 2025
933b37f
Merge branch 'Ylianst:master' into dockerrewrite
DaanSelen May 19, 2025
6bb6b18
Added mysql dependency
DaanSelen May 19, 2025
620df54
Merge branch 'Ylianst:master' into dockerrewrite
DaanSelen May 23, 2025
ae0aa7e
Merge branch 'master' into dockerrewrite
DaanSelen May 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Docker
name: Docker-Builder
on:
push:
branches:
- master
release:
types: [published]
types: [ published ]

env:
REGISTRY: ghcr.io
Expand All @@ -22,7 +22,7 @@ jobs:
MY_TOKEN: ${{ secrets.MY_TOKEN }}
if: "${{ env.MY_TOKEN != '' }}"
run: echo "token_defined=true" >> "$GITHUB_OUTPUT"

build:
name: Release
runs-on: ubuntu-latest
Expand All @@ -36,6 +36,8 @@ jobs:

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -54,14 +56,25 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
INCLUDE_MONGODBTOOLS=true
INCLUDE_MONGODB_TOOLS=true
INCLUDE_POSTGRESQL_TOOLS=true
INCLUDE_MARIADB_TOOLS=true
PREINSTALL_LIBS=true

#- name: Docker Scout
# id: docker-scout
# uses: docker/scout-action@v1
# with:
# command: quickview,cves
# image: image://
# summary: true
# only-severities: critical,high,medium,low,unspecified
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,5 @@ __pycache__/

# When running mkdocs locally as dev
docs/__pycache__/
docs/env/
docs/env/
docker-compose.yaml
29 changes: 0 additions & 29 deletions docker/BUILD.md

This file was deleted.

220 changes: 149 additions & 71 deletions docker/Dockerfile
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 \
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 \
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 \
Copy link

Choose a reason for hiding this comment

The 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.
Also might want to remove APT cache after install like on line 100?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 --no-cache mode.

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

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

ENTRYPOINT ["bash", "/opt/meshcentral/entrypoint.sh"]
Loading
Loading