diff --git a/nodered/Dockerfile b/nodered/Dockerfile index 49e6591..b1f5edf 100644 --- a/nodered/Dockerfile +++ b/nodered/Dockerfile @@ -1,35 +1,68 @@ -FROM nodered/node-red:latest-12-minimal +FROM node:lts-buster AS base -USER root +# Copy scripts +COPY scripts/*.sh /tmp/ -#RUN sed -i -e 's/v[[:digit:]]\..*\//edge\//g' /etc/apk/repositories \ -# && apk upgrade --update-cache --available - -RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community/" >> /etc/apk/repositories -RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories - -RUN set -ex && apk update \ - && apk --no-cache add -u wget build-base sudo libpcap libpcap-dev make perl net-tools bluez-deprecated arp-scan bluez \ - && rm -rf /var/lib/apt/lists/* - -RUN addgroup sudo && addgroup node-red sudo - -RUN cat /dev/null > /etc/sudoers \ - && echo -e "Set disable_coredump false\n" > /etc/sudo.conf \ - && echo -e "node-red ALL=(ALL) NOPASSWD: ALL\n%sudo ALL=(ALL) NOPASSWD: ALL\n" > /etc/sudoers - -RUN cd /tmp/ && wget http://www.mavetju.org/download/dhcpdump-1.8.tar.gz \ - && tar -xzf dhcpdump-1.8.tar.gz \ - && rm dhcpdump-1.8.tar.gz \ - && cd dhcpdump-1.8 \ - && make \ - && mv ./dhcpdump /usr/bin/dhcpdump \ - && chmod +x /usr/bin/dhcpdump \ - && cd /usr/src/node-red \ - && rm -R /tmp/dhcpdump-1.8 - -RUN apk del build-base libpcap-dev make perl +# Install tools, create Node-RED app and data dir, add user and set rights +RUN set -ex && \ + apt-get update && \ + apt-get intsall --no-cache \ + bash \ + tzdata \ + iputils \ + curl \ + nano \ + git \ + openssl \ + openssh-client && \ + mkdir -p /usr/src/node-red /data && \ + deluser --remove-home node && \ + adduser -h /usr/src/node-red -D -H node-red -u 1000 && \ + 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 +# package.json contains Node-RED NPM module and node dependencies +COPY package.json . + +#### Stage BUILD ####################################################################################################### +FROM base AS build + +# Install Build tools +RUN apt-get update && apt-get intsall --no-cache --virtual buildtools build-base linux-headers udev python && \ + npm install --unsafe-perm --no-update-notifier --only=production && \ + /tmp/remove_native_gpio.sh && \ + cp -R node_modules prod_node_modules + +#### Stage RELEASE ##################################################################################################### +FROM base AS RELEASE + +COPY --from=build /usr/src/node-red/prod_node_modules ./node_modules + +# Chown, install devtools & Clean up +RUN chown -R node-red:node-red /usr/src/node-red && \ + /tmp/install_devtools.sh && \ + rm -r /tmp/* + USER node-red + +# Env variables +ENV NODE_RED_VERSION=$NODE_RED_VERSION \ + NODE_PATH=/usr/src/node-red/node_modules:/data/node_modules \ + FLOWS=flows.json + +# 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 + +# User configuration directory volume +VOLUME ["/data"] + +# Expose the listening port of node-red +EXPOSE 1880 + +# Add a healthcheck (default every 30 secs) +HEALTHCHECK CMD curl http://localhost:1880/ || exit 1 + +ENTRYPOINT ["npm", "start", "--", "--userDir", "/data"]