From 82c296a51936bb1c2b0844c7761274f52c26d20d Mon Sep 17 00:00:00 2001 From: Armin Beck Date: Tue, 13 Jul 2021 07:58:00 +0000 Subject: [PATCH] settings.js folder moved --- Dockerfile.amd64 | 13 +++++-------- Dockerfile.i386 | 13 +++++-------- README.md | 4 ++++ auth/user-authentication_v2.js | 2 +- init.d/entrypoint.sh | 22 +++++++++++++++++++++- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/Dockerfile.amd64 b/Dockerfile.amd64 index 1633906..64b18e7 100644 --- a/Dockerfile.amd64 +++ b/Dockerfile.amd64 @@ -11,7 +11,7 @@ LABEL org.label-schema.build-date=$BUILD_DATE \ org.label-schema.vcs-ref=$VCS_REF #version -ENV HILSCHERNETFIELD_NODERED_VERSION 1.0.1 +ENV HILSCHERNETFIELD_NODERED_VERSION 1.0.2 #labeling LABEL maintainer="netiotedge@hilscher.com" \ @@ -42,13 +42,10 @@ RUN apt-get update && apt-get -y install curl sudo build-essential python-dev py && echo ' "dependencies": {' >> package.json \ && echo ' }' >> package.json \ && echo '}' >> package.json \ -#generate keys and self-signed certificate +#prepare separate settings.js folder for Node-RED + && mkdir /root/settings/ \ + && cd /root/settings/ \ && npm install when request \ - && mkdir -p /root/.node-red/certs \ - && cd /root/.node-red/certs \ - && openssl genrsa -out ./node-key.pem 2048 \ - && openssl req -new -sha256 -key ./node-key.pem -out ./node-csr.pem -subj "/C=DE/ST=Hessen/L=Hattersheim/O=Hilscher/OU=Hilscher/CN=myown/emailAddress=myown@hilscher.com" \ - && openssl x509 -req -in ./node-csr.pem -signkey ./node-key.pem -out ./node-cert.pem \ # -------------------- Install standard nodes from the community -------------------------------------------------------------- && cd /root/.node-red/ \ # -------------------- Install OPC UA nodes and all dependencies -------------------- @@ -85,7 +82,7 @@ RUN apt-get update && apt-get -y install curl sudo build-essential python-dev py # -------------------- Do all necessary copies -------------------- -COPY "./auth/*" /root/.node-red/ +COPY "./auth/*" /root/settings/ #copy files COPY "./init.d/*" /etc/init.d/ diff --git a/Dockerfile.i386 b/Dockerfile.i386 index 1633906..64b18e7 100644 --- a/Dockerfile.i386 +++ b/Dockerfile.i386 @@ -11,7 +11,7 @@ LABEL org.label-schema.build-date=$BUILD_DATE \ org.label-schema.vcs-ref=$VCS_REF #version -ENV HILSCHERNETFIELD_NODERED_VERSION 1.0.1 +ENV HILSCHERNETFIELD_NODERED_VERSION 1.0.2 #labeling LABEL maintainer="netiotedge@hilscher.com" \ @@ -42,13 +42,10 @@ RUN apt-get update && apt-get -y install curl sudo build-essential python-dev py && echo ' "dependencies": {' >> package.json \ && echo ' }' >> package.json \ && echo '}' >> package.json \ -#generate keys and self-signed certificate +#prepare separate settings.js folder for Node-RED + && mkdir /root/settings/ \ + && cd /root/settings/ \ && npm install when request \ - && mkdir -p /root/.node-red/certs \ - && cd /root/.node-red/certs \ - && openssl genrsa -out ./node-key.pem 2048 \ - && openssl req -new -sha256 -key ./node-key.pem -out ./node-csr.pem -subj "/C=DE/ST=Hessen/L=Hattersheim/O=Hilscher/OU=Hilscher/CN=myown/emailAddress=myown@hilscher.com" \ - && openssl x509 -req -in ./node-csr.pem -signkey ./node-key.pem -out ./node-cert.pem \ # -------------------- Install standard nodes from the community -------------------------------------------------------------- && cd /root/.node-red/ \ # -------------------- Install OPC UA nodes and all dependencies -------------------- @@ -85,7 +82,7 @@ RUN apt-get update && apt-get -y install curl sudo build-essential python-dev py # -------------------- Do all necessary copies -------------------- -COPY "./auth/*" /root/.node-red/ +COPY "./auth/*" /root/settings/ #copy files COPY "./init.d/*" /etc/init.d/ diff --git a/README.md b/README.md index f6d79c9..90ce7a8 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,10 @@ A `docker-compose.yml` file could look like this volumes: - nodered:/root/.node-red + volumes: + nodered: + + ### Container access The container starts Node-RED and all involved services automatically when deployed. diff --git a/auth/user-authentication_v2.js b/auth/user-authentication_v2.js index 2a96699..b768071 100644 --- a/auth/user-authentication_v2.js +++ b/auth/user-authentication_v2.js @@ -12,7 +12,7 @@ module.exports = { }, authenticate: function(username,password) { return new Promise(function(resolve) { - var auth = 'Basic ' + new Buffer(username + ':' + password).toString('base64'); + var auth = 'Basic ' + new Buffer.from(username + ':' + password).toString('base64'); var url = 'https://127.0.0.1/cockpit/login' request.get({ url : url, diff --git a/init.d/entrypoint.sh b/init.d/entrypoint.sh index 2cac49e..1ae9f2a 100755 --- a/init.d/entrypoint.sh +++ b/init.d/entrypoint.sh @@ -53,8 +53,28 @@ else fi +if [ ! -e container_first_start ]; then + + echo "Container is starting the first time" + + #copy the settings file to the correct location + cp /usr/lib/node_modules/node-red/settings.js /root/settings/settings.js + + + #generate keys and self-signed certificate + + mkdir -p /root/.node-red/certs + openssl genrsa -out /root/.node-red/certs/node-key.pem 4096 + openssl req -new -sha256 -key /root/.node-red/certs/node-key.pem -out /root/.node-red/certs/node-csr.pem -subj "/C=DE/ST=Hessen/L=Hattersheim/O=Hilscher/OU=Hilscher/CN=$HOSTNAME/emailAddress=myown@hilscher.com" + openssl x509 -req -days 365 -in /root/.node-red/certs/node-csr.pem -signkey /root/.node-red/certs/node-key.pem -out /root/.node-red/certs/node-cert.pem + + touch container_first_start + +fi + + # start Node-RED as background task -/usr/bin/node-red flows.json & +/usr/bin/node-red --settings /root/settings/settings.js flows.json & # wait forever not to exit the container while true