fix(nodered): seed /data/settings.js via entrypoint wrapper

The /data named volume hides anything Dockerfile COPYs into /data, so
the previous CMD override pointing at /usr/src/bf-settings.js didn't
help — Node-RED's launch script still looks for /data/settings.js by
default, which doesn't exist after the volume overlays.

Solution: entrypoint wrapper copies /usr/src/bf-settings.js to
/data/settings.js on first boot when missing, then exec's npm start.
Subsequent boots keep the user-edited version in the volume.
This commit is contained in:
Mitchell R 2026-05-19 03:57:42 +02:00
parent 6473f0fc95
commit 7baa1a07f9
No known key found for this signature in database
2 changed files with 23 additions and 4 deletions

View file

@ -11,9 +11,12 @@ USER root
# Copy our nodes into a path outside /data (which is volume-mounted) # Copy our nodes into a path outside /data (which is volume-mounted)
COPY nodered /usr/src/betterframe-nodes COPY nodered /usr/src/betterframe-nodes
# Settings file at a non-/data path so the nodered-data volume doesn't # Settings template + entrypoint that seeds /data/settings.js on first boot
# overlay it. CMD passes --settings to point Node-RED at it. # (the /data named volume hides anything we COPY directly there, so we have
# to plant the file after the volume mount comes up).
COPY deploy/docker/nodered-settings.js /usr/src/bf-settings.js COPY deploy/docker/nodered-settings.js /usr/src/bf-settings.js
COPY deploy/docker/nodered-entrypoint.sh /usr/local/bin/bf-nodered-entrypoint
RUN chmod +x /usr/local/bin/bf-nodered-entrypoint
# Install deps for the nodes # Install deps for the nodes
RUN cd /usr/src/betterframe-nodes && \ RUN cd /usr/src/betterframe-nodes && \
@ -22,5 +25,5 @@ RUN cd /usr/src/betterframe-nodes && \
USER node-red USER node-red
# Override the default CMD to use the baked settings.js. ENTRYPOINT ["/usr/local/bin/bf-nodered-entrypoint"]
CMD ["npm", "start", "--cache", "/data/.npm", "--", "--userDir", "/data", "--settings", "/usr/src/bf-settings.js"] CMD []

View file

@ -0,0 +1,16 @@
#!/usr/bin/env sh
# Seed /data/settings.js with our BF defaults on first boot.
# /data is volume-mounted, so the COPY in the Dockerfile gets hidden
# unless we plant a copy after the mount comes up.
set -eu
DATA=/data
TPL=/usr/src/bf-settings.js
if [ ! -f "$DATA/settings.js" ]; then
echo "[bf-nodered] seeding $DATA/settings.js from $TPL"
cp "$TPL" "$DATA/settings.js"
fi
# Exec the upstream nodered entrypoint args verbatim.
exec npm start --cache /data/.npm -- --userDir /data "$@"