Much of the material that used to be in this gist has been moved to the Node-RED documentation page at SensorsIot/IOTstack.
The nodered_list_installed_nodes
script is also part of the IOTstack repository.
The material below is the remainder of the original gist:
#!/usr/bin/env bash
# the name of this script is
SCRIPT=$(basename "$0")
# default image is
DEFAULTIMAGE="iotstack-nodered:latest"
# zero or one arguments supported
if [ "$#" -gt 1 ]; then
echo "Usage: $SCRIPT {image:tag}"
echo " eg: $SCRIPT $DEFAULTIMAGE"
exit -1
fi
# image can be passed as first argument, else default
IMAGE=${1:-"$DEFAULTIMAGE"}
# fetch latest version details from GitHub
LATEST=$(wget -O - -q https://raw.githubusercontent.com/node-red/node-red-docker/master/package.json | jq -r .version)
# figure out the version in the local image
INSTALLED=$(docker image inspect "$IMAGE" | jq -r .[0].Config.Labels[\"org.label-schema.version\"])
# compare versions and report result
if [ "$INSTALLED" = "$LATEST" ] ; then
echo "Node-Red is up-to-date (version $INSTALLED)"
else
/bin/cat <<-COLLECT_TEXT
====================================================================
Node-Red version number has changed on GitHub:
Local Version: $INSTALLED
GitHub Version: $LATEST
This means a new version MIGHT be available on Dockerhub. Check here:
https://hub.docker.com/r/nodered/node-red/tags?page=1&ordering=last_updated
When an updated version is actually avaliable, proceed like this:
$ REBUILD nodered
$ UP nodered
$ docker system prune
====================================================================
COLLECT_TEXT
fi
-
Make sure
~/.local/bin
exists (the following command is non-destructive):$ mkdir -p ~/.local/bin
-
Logout and login again. A new login causes your
.profile
to run. That discovers the~/.local/bin
directory and adds it to your search path. -
Copy the
nodered_version_check
script to the clipboard. -
Paste the script into your favourite text editor.
Note:
- try to avoid using text editors which write line-endings as CR+LF (0x0D 0x0A). You will typically find those on Windows systems but you may also encounter the problem on other platforms if your text editor has a preference which has been set to use CR+LF line-endings. The Raspberry Pi expects LF.
-
Save the script into
~/.local/bin
with the namenodered_version_check
. -
Make the script executable:
$ chmod u+x nodered_version_check
-
Test by running the script:
$ nodered_version_check
nodered_version_check
depends on jq
and wget
. If those are not available on your Raspberry Pi, you can fix that by:
$ sudo apt install -y jq wget
I have two 4GB Raspberry Pi 4Bs which I think of as "live" and "test". They are kept as close to identical as I can manage. As well as being a good testbed, my "test" Raspberry Pi is also there to guard against my "live" Raspberry Pi emitting magic smoke. If that happens, all I will have to do is:
- Restore the latest backup onto the "test" Raspberry Pi (the "live" Raspberry Pi takes two backups per day).
- Change my DHCP server to associate the MACs of the "test" Raspberry Pi with the IP addresses being assigned to the "live" Raspberry Pi.
- Apply power.
Because I have two Raspberry Pis, I have never seen much sense in rebuilding Node-RED on both the "live" and "test" machines. Generally, I will do the rebuild on the "test" Raspberry Pi first, make sure there are no obvious problems, and then think about the "live" Raspberry Pi.
If you're in a similar situation, here's how to avoid rebuilding Node-RED on more than one machine.
If a new base image has become available on DockerHub:
$ cd ~/IOTstack
$ docker-compose build --no-cache --pull nodered
$ docker-compose up -d nodered
$ docker system prune
If you have changed the Dockerfile, you only need:
$ cd ~/IOTstack
$ docker-compose up --build -d nodered
$ docker system prune
-
If you just rebuilt because a new base image became available on DockerHub, you should archive the new base image:
$ docker save nodered/node-red >~/nodered_base.tar
-
Archive the new local image:
$ docker save iotstack_nodered >~/nodered_local.tar
I use scp
but you can use any method that works for you to move the .tar
files from "A" to "B":
$ scp ~/nodered_*.tar pi@OTHERPI:.
where "OTHERPI" is the IP address or domain name of another Raspberry Pi.
On each OTHERPI:
-
If you archived a new base image, restore that first:
$ docker load <~/nodered_base.tar
-
Restore the new local image:
$ docker load <~/nodered_local.tar
-
Apply the changes:
$ cd ~/IOTstack $ docker-compose up -d nodered
-
Clean-up:
$ docker system prune $ rm ~/nodered_*.tar
There is no need to take down the old Node-RED container. The "up" will automatically instantiate a new container based on the newer image and perform a new-for-old swap. Barely any downtime!