Skip to content

Commit 108bf35

Browse files
authored
Merge pull request #591 from Paraphraser/20220708-nodered-old-menu
20220708 Node-RED - old-menu branch - PR 2 of 2
2 parents c81fd37 + 7426144 commit 108bf35

File tree

3 files changed

+95
-40
lines changed

3 files changed

+95
-40
lines changed

.templates/nodered/build.sh

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ node_selection=$(whiptail --title "Node-RED nodes" --checklist --separate-output
1212
"node-red-configurable-ping" " " "ON" \
1313
"node-red-node-openweathermap" " " "OFF" \
1414
"node-red-contrib-discord" " " "OFF" \
15-
"node-red-node-email" " " "on" \
15+
"node-red-node-email" " " "OFF" \
1616
"node-red-node-google" " " "OFF" \
1717
"node-red-node-emoncms" " " "OFF" \
1818
"node-red-node-geofence" " " "OFF" \
@@ -21,13 +21,16 @@ node_selection=$(whiptail --title "Node-RED nodes" --checklist --separate-output
2121
"node-red-node-smooth" " " "OFF" \
2222
"node-red-node-darksky" " " "OFF" \
2323
"node-red-node-sqlite" " " "OFF" \
24+
"node-red-node-serialport" " " "OFF" \
2425
"node-red-contrib-config" " " "OFF" \
2526
"node-red-contrib-grove" " " "OFF" \
2627
"node-red-contrib-diode" " " "OFF" \
28+
"node-red-contrib-sunevents" " " "OFF" \
2729
"node-red-contrib-bigtimer" " " "OFF" \
2830
"node-red-contrib-esplogin" " " "OFF" \
2931
"node-red-contrib-timeout" " " "OFF" \
3032
"node-red-contrib-moment" " " "OFF" \
33+
"node-red-contrib-telegrambot" " " "OFF" \
3134
"node-red-contrib-particle" " " "OFF" \
3235
"node-red-contrib-web-worldmap" " " "OFF" \
3336
"node-red-contrib-ramp-thermostat" " " "OFF" \
@@ -41,6 +44,13 @@ node_selection=$(whiptail --title "Node-RED nodes" --checklist --separate-output
4144
"node-red-contrib-heater-controller" " " "OFF" \
4245
"node-red-contrib-deconz" " " "OFF" \
4346
"node-red-contrib-generic-ble" " " "OFF" \
47+
"node-red-contrib-zigbee2mqtt" " " "OFF" \
48+
"node-red-contrib-vcgencmd" " " "OFF" \
49+
"node-red-contrib-themes/midnight-red" " " "OFF" \
50+
"node-red-contrib-tf-function" " " "OFF" \
51+
"node-red-contrib-tf-model" " " "OFF" \
52+
"node-red-contrib-post-object-detection" " " "OFF" \
53+
"node-red-contrib-bert-tokenizer" " " "OFF" \
4454
3>&1 1>&2 2>&3)
4555

4656
##echo "$check_selection"
@@ -50,12 +60,33 @@ nr_dfile=./services/nodered/Dockerfile
5060

5161
sqliteflag=0
5262

53-
touch $nr_dfile
54-
echo "FROM nodered/node-red:latest-12" >$nr_dfile
63+
# initialise Dockerfile ('EOT' syntax avoids bash substitutions)
64+
cat <<-'EOT' >"$nr_dfile"
65+
# reference argument - omitted defaults to latest
66+
ARG DOCKERHUB_TAG=latest
5567
56-
echo "USER root" >>$nr_dfile
57-
echo "RUN apk update && apk add --no-cache eudev-dev" >>$nr_dfile
58-
echo "USER node-red" >>$nr_dfile
68+
# Download base image
69+
FROM nodered/node-red:${DOCKERHUB_TAG}
70+
71+
# reference argument - omitted defaults to null
72+
ARG EXTRA_PACKAGES
73+
ENV EXTRA_PACKAGES=${EXTRA_PACKAGES}
74+
75+
# default user is node-red - need to be root to install packages
76+
USER root
77+
78+
# install packages
79+
RUN apk update && apk add --no-cache eudev-dev ${EXTRA_PACKAGES}
80+
81+
# switch back to default user
82+
USER node-red
83+
84+
# variable not needed inside running container
85+
ENV EXTRA_PACKAGES=
86+
87+
# add-on nodes follow
88+
89+
EOT
5990

6091
#node red install script inspired from https://tech.scargill.net/the-script/
6192
echo "RUN for addonnodes in \\" >>$nr_dfile

.templates/nodered/service.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
nodered:
22
container_name: nodered
3-
build: ./services/nodered/.
3+
build:
4+
context: ./services/nodered/.
5+
args:
6+
- DOCKERHUB_TAG=latest
7+
- EXTRA_PACKAGES=
48
restart: unless-stopped
59
user: "0"
610
env_file: ./services/nodered/nodered.env
Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,61 @@
11
#!/usr/bin/env bash
22

3-
INTERNAL="/usr/src/node-red/node_modules"
4-
EXTERNAL="$HOME/IOTstack/volumes/nodered/data/node_modules"
5-
6-
echo -e "\nNodes installed by Dockerfile INSIDE the container at $INTERNAL"
7-
8-
CANDIDATES=$(docker exec nodered bash -c "ls -1d $INTERNAL/node-red-*")
9-
10-
for C in $CANDIDATES; do
11-
12-
NODE=$(basename "$C")
13-
14-
# is a node of the same name also present externally
15-
if [ -d "$EXTERNAL/$NODE" ] ; then
16-
17-
# yes! the internal node is blocked by the external node
18-
echo " BLOCKED: $NODE"
19-
20-
else
21-
22-
# no! so that means it's active
23-
echo " ACTIVE: $NODE"
24-
3+
# where Dockerfile installs components INSIDE the container
4+
DOCKERFILE="/usr/src/node-red"
5+
6+
# paths to the persistent store
7+
PERSISTENT_INTERNAL="/data"
8+
PERSISTENT_EXTERNAL="$HOME/IOTstack/volumes/nodered/data"
9+
10+
# the folder in each case containing node modules
11+
MODULES="node_modules"
12+
13+
# assume no modules are blocked
14+
unset BLOCKED
15+
16+
# start the command hint
17+
UNBLOCK="docker exec -w /data nodered npm uninstall"
18+
19+
# fetch what npm knows about components that form part of the image
20+
echo -e "\nFetching list of candidates installed via Dockerfile"
21+
CANDIDATES=$(docker exec nodered bash -c "cd \"$DOCKERFILE\" ; npm list --depth=0 --parseable 2>/dev/null")
22+
23+
# report
24+
echo -e "\nComponents built into the image (via Dockerfile)"
25+
PARENT=$(basename "$DOCKERFILE")
26+
for CANDIDATE in $CANDIDATES; do
27+
COMPONENT=$(basename "$CANDIDATE")
28+
if [ "$COMPONENT" != "$PARENT" ] ; then
29+
if [ -d "$PERSISTENT_EXTERNAL/$MODULES/$COMPONENT" ] ; then
30+
# yes! the internal node is blocked by the external node
31+
echo " BLOCKED: $COMPONENT"
32+
BLOCKED=true
33+
UNBLOCK="$UNBLOCK $COMPONENT"
34+
else
35+
# no! so that means it's active
36+
echo " ACTIVE: $COMPONENT"
37+
fi
2538
fi
26-
2739
done
2840

29-
echo -e "\nNodes installed by Manage Palette OUTSIDE the container at $EXTERNAL"
30-
31-
CANDIDATES=$(ls -1d "$EXTERNAL/node-red-"*)
32-
33-
for C in $CANDIDATES; do
34-
35-
NODE=$(basename "$C")
36-
37-
echo " $NODE"
38-
41+
# fetch what npm knows about components that are in the persistent store
42+
echo -e "\nFetching list of candidates installed via Manage Palette or npm"
43+
CANDIDATES=$(docker exec nodered bash -c "cd \"$PERSISTENT_INTERNAL\" ; npm list --depth=0 --parseable")
44+
45+
# report
46+
echo -e "\nComponents in persistent store at\n $PERSISTENT_EXTERNAL/$MODULES"
47+
PARENT=$(basename "$PERSISTENT_INTERNAL")
48+
for CANDIDATE in $CANDIDATES; do
49+
COMPONENT=$(basename "$CANDIDATE")
50+
if [ "$COMPONENT" != "$PARENT" ] ; then
51+
echo " $COMPONENT"
52+
fi
3953
done
4054

4155
echo ""
56+
57+
if [ -n "$BLOCKED" ] ; then
58+
echo "Blocking nodes can be removed by running the following commands"
59+
echo "\$ $UNBLOCK"
60+
echo "\$ docker-compose -f ~/IOTstack/docker-compose.yml restart nodered"
61+
fi

0 commit comments

Comments
 (0)