From 70e6b11b2a63a7a73a521b86c9d8635507756100 Mon Sep 17 00:00:00 2001 From: Ludo Mikula Date: Mon, 9 Jun 2025 18:46:36 +0200 Subject: [PATCH] new: add mongo-express to all-in-one image for accessing of internal mongodb --- deploy/docker/Dockerfile | 8 +++- .../all-in-one/conf/nginx_mongo-ui.conf | 9 +++++ deploy/docker/all-in-one/entrypoint.sh | 16 +++++--- .../conf-available/15-mongo-express.conf | 18 +++++++++ .../all-in-one/scripts/mongo-ui-entrypoint.sh | 39 +++++++++++++++++++ deploy/docker/default.env | 2 + deploy/docker/frontend/server.conf | 2 + 7 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 deploy/docker/all-in-one/conf/nginx_mongo-ui.conf create mode 100644 deploy/docker/all-in-one/etc/supervisord/conf-available/15-mongo-express.conf create mode 100755 deploy/docker/all-in-one/scripts/mongo-ui-entrypoint.sh diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile index 5ecbbd579d..9b20442413 100644 --- a/deploy/docker/Dockerfile +++ b/deploy/docker/Dockerfile @@ -239,6 +239,7 @@ COPY deploy/docker/frontend/nginx-http.conf /etc/nginx/nginx-http.conf COPY deploy/docker/frontend/nginx-https.conf /etc/nginx/nginx-https.conf COPY deploy/docker/frontend/ssl-certificate.conf /etc/nginx/ssl-certificate.conf COPY deploy/docker/frontend/ssl-params.conf /etc/nginx/ssl-params.conf +COPY deploy/docker/all-in-one/conf/nginx_mongo-ui.conf /etc/nginx/mongo-ui.conf # Add lowcoder frontend @@ -259,6 +260,11 @@ RUN mkdir -p /lowcoder/plugins/ && chown lowcoder:lowcoder /lowcoder/plugins/ # Add lowcoder node-service COPY --chown=lowcoder:lowcoder --from=lowcoder-ce-node-service /lowcoder/node-service /lowcoder/node-service +# Add mongo-express for managing mongodb database +RUN mkdir -p /lowcoder/mongo-express && chown lowcoder:lowcoder /lowcoder/mongo-express +COPY --chown=lowcoder:lowcoder --from=mongo-express:1-20-alpine3.19 /app /lowcoder/mongo-express/app +COPY --chown=lowcoder:lowcoder --chmod=0755 deploy/docker/all-in-one/scripts/mongo-ui-entrypoint.sh /lowcoder/mongo-express/mongo-ui-entrypoint.sh + # Add services configuration COPY --chown=lowcoder:lowcoder deploy/docker/all-in-one/etc /lowcoder/etc @@ -276,9 +282,9 @@ RUN echo \ && chown -R lowcoder:root /var/log \ && chmod -R g+rw /run /etc/nginx /var/cache/nginx /var/log -EXPOSE 27017 EXPOSE 3000 EXPOSE 3443 +EXPOSE 9999 ENTRYPOINT [ "/bin/sh" , "/lowcoder/entrypoint.sh" ] CMD ["/usr/bin/supervisord", "-n" , "-c" , "/lowcoder/etc/supervisord.conf"] diff --git a/deploy/docker/all-in-one/conf/nginx_mongo-ui.conf b/deploy/docker/all-in-one/conf/nginx_mongo-ui.conf new file mode 100644 index 0000000000..a15954d90a --- /dev/null +++ b/deploy/docker/all-in-one/conf/nginx_mongo-ui.conf @@ -0,0 +1,9 @@ + + location /mongo-ui { + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_pass http://127.0.0.1:9999/mongo-ui; + } + diff --git a/deploy/docker/all-in-one/entrypoint.sh b/deploy/docker/all-in-one/entrypoint.sh index 74403a08d1..727e9967fd 100644 --- a/deploy/docker/all-in-one/entrypoint.sh +++ b/deploy/docker/all-in-one/entrypoint.sh @@ -18,12 +18,7 @@ if [ ! "$(id --group lowcoder)" -eq ${GROUP_ID} ]; then fi; # Update host on which mongo is supposed to listen -# If LOWCODER_MONGODB_EXPOSED is true, it will listen on all interfaces -if [ "${LOWCODER_MONGODB_EXPOSED}" = "true" ]; then - export MONGO_LISTEN_HOST="0.0.0.0" -else - export MONGO_LISTEN_HOST="127.0.0.1" -fi; +export MONGO_LISTEN_HOST="127.0.0.1" # Set the default mongodb connection string if not set explicitly if [ -z "${LOWCODER_MONGODB_URL}" ]; then @@ -36,6 +31,7 @@ CERT="/lowcoder-stacks/ssl" # Create folder for holding application logs and data mkdir -p ${LOGS}/redis \ ${LOGS}/mongodb \ + ${LOGS}/mongo-ui \ ${LOGS}/api-service \ ${LOGS}/node-service \ ${LOGS}/frontend \ @@ -78,9 +74,17 @@ if [ "${LOWCODER_NODE_SERVICE_ENABLED:=true}" = "true" ]; then ln ${SUPERVISOR_AVAILABLE}/11-node-service.conf ${SUPERVISOR_ENABLED}/11-node-service.conf fi; +# Enable mongo-express web UI for mongodb if configured to run +if [ "${LOWCODER_MONGODB_EXPOSED:=false}" = "true" ]; then + ln ${SUPERVISOR_AVAILABLE}/15-mongo-express.conf ${SUPERVISOR_ENABLED}/15-mongo-express.conf +fi; + # Enable frontend if configured to run if [ "${LOWCODER_FRONTEND_ENABLED:=true}" = "true" ]; then ln ${SUPERVISOR_AVAILABLE}/20-frontend.conf ${SUPERVISOR_ENABLED}/20-frontend.conf + sed -i 's@# include mongo-ui.conf;@include mongo-ui.conf;@' /etc/nginx/server.conf +else + sed -i 's@\(\s*\)\(include mongo-ui\.conf;\)@\1# \2@' /etc/nginx/server.conf fi; # disable user directive if image is running non-root (Openshift) diff --git a/deploy/docker/all-in-one/etc/supervisord/conf-available/15-mongo-express.conf b/deploy/docker/all-in-one/etc/supervisord/conf-available/15-mongo-express.conf new file mode 100644 index 0000000000..f4fae87fe0 --- /dev/null +++ b/deploy/docker/all-in-one/etc/supervisord/conf-available/15-mongo-express.conf @@ -0,0 +1,18 @@ +[program:mongo-ui] +# privileges will be dropped in entrypoint +user=root +directory=/lowcoder/mongo-express +command=/lowcoder/mongo-express/mongo-ui-entrypoint.sh +priority=15 +autostart=true +autorestart=true +startsecs=10 +startretries=3 +stdout_logfile=/lowcoder-stacks/logs/%(program_name)s/%(program_name)s.log +redirect_stderr=true +stdout_logfile_maxbytes=10MB +stderr_logfile_maxbytes=10MB +stdout_logfile_backups=5 +stderr_logfile_backups=5 +stdout_events_enabled=true +stderr_events_enabled=true diff --git a/deploy/docker/all-in-one/scripts/mongo-ui-entrypoint.sh b/deploy/docker/all-in-one/scripts/mongo-ui-entrypoint.sh new file mode 100755 index 0000000000..af50b6ad9a --- /dev/null +++ b/deploy/docker/all-in-one/scripts/mongo-ui-entrypoint.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +set -e + +export USER_ID=${LOWCODER_PUID:=9001} +export GROUP_ID=${LOWCODER_PGID:=9001} + +# Mongo express configuration +export ME_CONFIG_MONGODB_URL="${LOWCODER_MONGODB_URL:=mongodb://localhost:27017/lowcoder?authSource=admin}" +export ME_CONFIG_MONGODB_ENABLE_ADMIN=true +export ME_CONFIG_SITE_BASEURL="/mongo-ui" +export ME_CONFIG_REQUEST_SIZE=200mb +export ME_CONFIG_OPTIONS_NO_DELETE=true +export ME_CONFIG_OPTIONS_EDITORTHEME=rubyblue +export ME_CONFIG_SITE_GRIDFS_ENABLED=true +export ME_CONFIG_OPTIONS_FULLWIDTH_LAYOUT=false +export ME_CONFIG_BASICAUTH=${LOWCODER_MONGODB_EXPOSED:false} +export ME_CONFIG_BASICAUTH_USERNAME="${LOWCODER_MONGOUI_USERNAME}" +export ME_CONFIG_BASICAUTH_PASSWORD="${LOWCODER_MONGOUI_PASSWORD}" +export VCAP_APP_HOST="127.0.0.1" +export PORT="9999" + +export ME_CONFIG_SITE_COOKIESECRET=`cat /proc/sys/kernel/random/uuid | sed 's/[-]//g' | head -c 30` +export ME_CONFIG_SITE_SESSIONSECRET=`cat /proc/sys/kernel/random/uuid | sed 's/[-]//g' | head -c 30` + +cd /lowcoder/mongo-express/app + +echo +echo "Running Mongodb UI with:" +if [ "$(id -u)" -eq 0 ]; then + # only use su if its possible, suppress for containers running non-root + echo " user id: ${USER_ID}" + echo " group id: ${GROUP_ID}" + GOSU="gosu ${USER_ID}:${GROUP_ID}" +fi +echo + +exec $GOSU node app + diff --git a/deploy/docker/default.env b/deploy/docker/default.env index 8b4445a3d4..4349ddee9f 100644 --- a/deploy/docker/default.env +++ b/deploy/docker/default.env @@ -33,6 +33,8 @@ LOWCODER_FRONTEND_ENABLED="true" # (applies to all-in-one deployment) # LOWCODER_MONGODB_EXPOSED="false" +LOWCODER_MONGOUI_USERNAME="admin" +LOWCODER_MONGOUI_PASSWORD="s3cr3t!" ## ## Generic parameters diff --git a/deploy/docker/frontend/server.conf b/deploy/docker/frontend/server.conf index b068162982..a1a65170f8 100644 --- a/deploy/docker/frontend/server.conf +++ b/deploy/docker/frontend/server.conf @@ -56,3 +56,5 @@ proxy_pass __LOWCODER_NODE_SERVICE_URL__; } + # include mongo-ui.conf; +