Last active
December 13, 2022 21:22
-
-
Save tve/262b800a8b063c346eff4d7cad050f2f to your computer and use it in GitHub Desktop.
Dockerfile for node-red-mcu-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG ARCH=amd64 | |
ARG OS=bullseye-slim | |
ARG NODE_VERSION=18 | |
ARG NODE_RED_VERSION=3.0.2 | |
#### Stage BASE ######################################################################################################## | |
FROM ${ARCH}/node:${NODE_VERSION}-${OS} AS base | |
# Install tools, create Node-RED app and data dir, add user and set rights | |
RUN set -ex && \ | |
apt-get update &&\ | |
apt-get install -y \ | |
bash \ | |
tzdata \ | |
curl \ | |
nano \ | |
wget \ | |
git \ | |
openssl \ | |
openssh-client \ | |
vim \ | |
net-tools \ | |
netcat-openbsd \ | |
ca-certificates && \ | |
mkdir -p /usr/src/node-red /data && \ | |
deluser --remove-home node && \ | |
# adduser --home /usr/src/node-red --disabled-password --no-create-home node-red --uid 1000 && \ | |
useradd --home-dir /usr/src/node-red --uid 1000 node-red && \ | |
chown -R node-red:root /data && chmod -R g+rwX /data && \ | |
chown -R node-red:root /usr/src/node-red && chmod -R g+rwX /usr/src/node-red | |
# chown -R node-red:node-red /data && \ | |
# chown -R node-red:node-red /usr/src/node-red | |
# Set work directory | |
WORKDIR /usr/src/node-red | |
# Setup SSH known_hosts file | |
COPY known_hosts.sh . | |
RUN ./known_hosts.sh /etc/ssh/ssh_known_hosts && rm ./known_hosts.sh | |
RUN echo "PubkeyAcceptedKeyTypes +ssh-rsa" >> /etc/ssh/ssh_config | |
# package.json contains Node-RED NPM module and node dependencies | |
COPY package.json . | |
COPY flows.json /data | |
# COPY scripts/entrypoint.sh . | |
# Install Moddable SDK | |
RUN apt-get install -y gcc git wget make libncurses-dev flex bison gperf libgtk-3-dev | |
RUN cd /usr/src && git clone https://github.com/Moddable-OpenSource/moddable | |
RUN export MODDABLE=/usr/src/moddable &&\ | |
cd $MODDABLE/build/makefiles/lin &&\ | |
make | |
# Install ESP-IDF SDK | |
RUN apt-get install -y cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 | |
RUN apt-get install -y python3 python3-venv python3-pip | |
RUN cd /usr/src && git clone -b v4.4.3 --recursive https://github.com/espressif/esp-idf.git | |
RUN cd /usr/src/esp-idf && ./install.sh esp32,esp32s3 | |
#### Stage BUILD ####################################################################################################### | |
FROM base AS build | |
# Install Build tools | |
RUN apt-get update && apt-get install -y build-essential && \ | |
npm install --unsafe-perm --no-update-notifier --no-fund --only=production && \ | |
npm uninstall node-red-node-gpio && \ | |
cp -R node_modules prod_node_modules | |
#### Stage RELEASE ##################################################################################################### | |
FROM base AS RELEASE | |
ARG BUILD_DATE | |
ARG BUILD_VERSION | |
ARG BUILD_REF | |
ARG NODE_RED_VERSION | |
ARG ARCH | |
ARG TAG_SUFFIX=default | |
LABEL org.label-schema.build-date=${BUILD_DATE} \ | |
org.label-schema.docker.dockerfile=".docker/Dockerfile.debian" \ | |
org.label-schema.license="Apache-2.0" \ | |
org.label-schema.name="Node-RED" \ | |
org.label-schema.version=${BUILD_VERSION} \ | |
org.label-schema.description="Low-code programming for event-driven applications." \ | |
org.label-schema.url="https://nodered.org" \ | |
org.label-schema.vcs-ref=${BUILD_REF} \ | |
org.label-schema.vcs-type="Git" \ | |
org.label-schema.vcs-url="https://github.com/node-red/node-red-docker" \ | |
org.label-schema.arch=${ARCH} \ | |
authors="Dave Conway-Jones, Nick O'Leary, James Thomas, Raymond Mouthaan" | |
COPY --from=build /usr/src/node-red/prod_node_modules ./node_modules | |
# Chown, install devtools & Clean up | |
RUN chown -R node-red:root /usr/src/node-red && \ | |
apt-get update && apt-get install -y build-essential python-dev python3 && \ | |
rm -r /tmp/* | |
RUN npm config set cache /data/.npm --global | |
RUN npm config set python `which python3` --global | |
RUN npm install --omit=dev --no-fund --no-audit https://github.com/ralphwetzel/node-red-mcu-plugin | |
RUN sed -i \ | |
-e "78a rm = rm.replace(/node_modules.*/, '');return rm + req_path" \ | |
node_modules/@ralphwetzel/node-red-mcu-plugin/mcu_plugin.js | |
RUN tail +5 node_modules/@ralphwetzel/node-red-mcu-plugin/mcu_plugin.js | head -n 10 | |
USER node-red | |
# Env variables | |
ENV NODE_RED_VERSION=$NODE_RED_VERSION \ | |
NODE_PATH=/usr/src/node-red/node_modules:/data/node_modules \ | |
PATH=/usr/src/node-red/node_modules/.bin:${PATH} \ | |
FLOWS=flows.json \ | |
MODDABLE=/usr/src/moddable \ | |
ESPIDF=/usr/src/isp-idf | |
# ENV NODE_RED_ENABLE_SAFE_MODE=true # Uncomment to enable safe start mode (flows not running) | |
# ENV NODE_RED_ENABLE_PROJECTS=true # Uncomment to enable projects option | |
# Expose the listening port of node-red | |
EXPOSE 1880 | |
# Add a healthcheck (default every 30 secs) | |
# HEALTHCHECK CMD curl http://localhost:1880/ || exit 1 | |
COPY entrypoint.sh . | |
ENTRYPOINT ["./entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
trap stop SIGINT SIGTERM | |
function stop() { | |
kill $CHILD_PID | |
wait $CHILD_PID | |
} | |
/usr/local/bin/node $NODE_OPTIONS node_modules/node-red/red.js --userDir /data $FLOWS & | |
CHILD_PID="$!" | |
wait "${CHILD_PID}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "f6f2187d.f17ca8", | |
"type": "tab", | |
"label": "Flow 1", | |
"disabled": false, | |
"info": "" | |
}, | |
{ | |
"id": "3cc11d24.ff01a2", | |
"type": "comment", | |
"z": "f6f2187d.f17ca8", | |
"name": "WARNING: please check you have started this container with a volume that is mounted to /data\\n otherwise any flow changes are lost when you redeploy or upgrade the container\\n (e.g. upgrade to a more recent node-red docker image).\\n If you are using named volumes you can ignore this warning.\\n Double click or see info side panel to learn how to start Node-RED in Docker to save your work", | |
"info": "\nTo start docker with a bind mount volume (-v option), for example:\n\n```\ndocker run -it -p 1880:1880 -v /home/user/node_red_data:/data --name mynodered nodered/node-red\n```\n\nwhere `/home/user/node_red_data` is a directory on your host machine where you want to store your flows.\n\nIf you do not do this then you can experiment and redploy flows, but if you restart or upgrade the container the flows will be disconnected and lost. \n\nThey will still exist in a hidden data volume, which can be recovered using standard docker techniques, but that is much more complex than just starting with a named volume as described above.", | |
"x": 350, | |
"y": 80, | |
"wires": [] | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Originally taken from the Flux project (https://github.com/fluxcd/flux/tree/master/docker) where is under an | |
# Apache-2.0 license | |
set -eu | |
known_hosts_file=${1} | |
known_hosts_file=${known_hosts_file:-/etc/ssh/ssh_known_hosts} | |
hosts="github.com gitlab.com bitbucket.org ssh.dev.azure.com vs-ssh.visualstudio.com" | |
hosts_2022="source.developers.google.com" | |
# The heredoc below was generated by constructing a known_hosts using | |
# | |
# ssh-keyscan github.com gitlab.com bitbucket.org ssh.dev.azure.com vs-ssh.visualstudio.com > ./known_hosts | |
# | |
# then generating the sorted fingerprints with | |
# | |
# ssh-keygen -l -f ./known_hosts | LC_ALL=C sort | |
# | |
# then checking against the published fingerprints from: | |
# - github.com: https://help.github.com/articles/github-s-ssh-key-fingerprints/ | |
# - gitlab.com: https://docs.gitlab.com/ee/user/gitlab_com/#ssh-host-keys-fingerprints | |
# - bitbucket.org: https://confluence.atlassian.com/bitbucket/ssh-keys-935365775.html | |
# - ssh.dev.azure.com & vs-ssh.visualstudio.com: sign in, then go to User settings -> SSH Public Keys | |
# (this is where the public key fingerprint is shown; it's not a setting) | |
# - source.developers.google.com: https://cloud.google.com/source-repositories/docs/cloning-repositories | |
fingerprints=$(mktemp -t) | |
cleanup() { | |
rm -f "$fingerprints" | |
} | |
trap cleanup EXIT | |
# make sure sorting is in the same locale as the heredoc | |
export LC_ALL=C | |
generate() { | |
ssh-keyscan ${hosts} > ${known_hosts_file} | |
ssh-keyscan -p 2022 ${hosts_2022} >> ${known_hosts_file} | |
} | |
validate() { | |
ssh-keygen -l -f ${known_hosts_file} | sort > "$fingerprints" | |
diff - "$fingerprints" <<EOF | |
2048 SHA256:ROQFvPThGrW4RuWLoL9tq9I9zJ42fK4XywyRtbOz/EQ gitlab.com (RSA) | |
2048 SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 github.com (RSA) | |
2048 SHA256:ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og ssh.dev.azure.com (RSA) | |
2048 SHA256:ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og vs-ssh.visualstudio.com (RSA) | |
2048 SHA256:zzXQOXSRBEiUtuE8AikJYKwbHaxvSc0ojez9YXaGp1A bitbucket.org (RSA) | |
256 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU github.com (ED25519) | |
256 SHA256:AGvEpqYNMqsRNIviwyk4J4HM0lEylomDBKOWZsBn434 [source.developers.google.com]:2022 (ECDSA) | |
256 SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw gitlab.com (ECDSA) | |
256 SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8 gitlab.com (ED25519) | |
256 SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM github.com (ECDSA) | |
EOF | |
} | |
retries=10 | |
count=0 | |
ok=false | |
wait=2 | |
until ${ok}; do | |
generate && validate && ok=true || ok=false | |
count=$(($count + 1)) | |
if [[ ${count} -eq ${retries} ]]; then | |
echo "ssh-keyscan failed, no more retries left" | |
exit 1 | |
fi | |
sleep ${wait} | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "node-red-docker", | |
"version": "3.0.2", | |
"description": "Low-code programming for event-driven applications", | |
"homepage": "http://nodered.org", | |
"license": "Apache-2.0", | |
"repository": { | |
"type": "git", | |
"url": "https://github.com/node-red/node-red-docker.git" | |
}, | |
"main": "node_modules/node-red/red/red.js", | |
"scripts": { | |
"start": "node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS", | |
"debug": "node --inspect=0.0.0.0:9229 $NODE_OPTIONS node_modules/node-red/red.js $FLOWS", | |
"debug_brk": "node --inspect=0.0.0.0:9229 --inspect-brk $NODE_OPTIONS node_modules/node-red/red.js $FLOWS" | |
}, | |
"contributors": [ | |
{ | |
"name": "Dave Conway-Jones" | |
}, | |
{ | |
"name": "Nick O'Leary" | |
}, | |
{ | |
"name": "James Thomas" | |
}, | |
{ | |
"name": "Raymond Mouthaan" | |
} | |
], | |
"dependencies": { | |
"node-red": "3.0.2" | |
}, | |
"engines": { | |
"node": ">=12" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
docker run --rm -ti -p 1880:1880 \ | |
-v $PWD/nr-data:/data \ | |
-e TZ=America/Los_Angeles \ | |
--name node-red-mcu \ | |
node-red-mcu | |
exit 0 | |
MOD=/home/sw/moddable | |
cd $MOD | |
CMD="set -x; npm i ./node-red-* --omit=dev --no-fund --no-audit" | |
CMD="$CMD; npm start --cache /data/.npm -- -v --userDir /data" | |
exec docker run --rm -ti -p 1770:1880 \ | |
-v $PWD/nr-data:/data \ | |
-v $PWD/node-red-mcu-plugin:/usr/src/node-red/node-red-mcu-plugin \ | |
-v $PWD/moddable:/usr/src/moddable \ | |
-e TZ=America/Los_Angeles \ | |
-e MODDABLE=/usr/src/moddable \ | |
--entrypoint bash \ | |
--name node-red-mcu \ | |
nodered/node-red:3.0.2-18 \ | |
-c "$CMD" | |
# CMD="$CMD; sed -i -e '/start/s/\$N/--inspect \$N/' package.json" | |
# CMD="$CMD; egrep 'start' package.json" | |
# CMD="$CMD; echo \$NODE_OPTIONS" | |
#CMD="$CMD; npm run debug_brk --cache /data/.npm -- -v -userDir /data" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment