Skip to content

Commit

Permalink
Merge pull request #18 from brunoamaral/docker
Browse files Browse the repository at this point in the history
Install Node-Red with docker and dependencies
  • Loading branch information
brunoamaral authored Sep 19, 2021
2 parents bd419ee + 796465c commit 4776b42
Show file tree
Hide file tree
Showing 4,495 changed files with 8,609 additions and 588,556 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ data/articles.json
data/trials.json
public/
modules/
content/article/*/
content/article/*/
docker-data/
workspace.code-workspace
docker-python/
docker-data/
117 changes: 117 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
ARG ARCH=amd64
ARG NODE_VERSION=12
ARG OS=buster-slim

#### Stage BASE ########################################################################################################
FROM ${ARCH}/node:${NODE_VERSION}-${OS} AS base

# Copy scripts
COPY scripts/*.sh /tmp/

# 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 \
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 /usr/src/node-red/known_hosts.sh

# package.json contains Node-RED NPM module and node dependencies
COPY package.json .
COPY flows.json /data/
COPY /python-ml /python-ml
RUN chown -R node-red:root /python-ml

#### Stage BUILD #######################################################################################################
FROM base AS build

# Install Build tools
RUN apt-get update && apt-get install -y build-essential python && \
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 python3-dev python3 \
python3-pip python3-numpy python3-pandas python3-h5py && \
pip3 install scikit-learn tensorflow && \
rm -r /tmp/*
RUN pip3 install -r /python-ml/requirements.txt

USER node-red

# Install Gregory Nodes
RUN npm install node-red-contrib-cheerio && \
npm install node-red-contrib-moment && \
npm install node-red-contrib-sqlstring && \
npm install node-red-dashboard && \
npm install node-red-node-feedparser && \
npm install node-red-node-sqlite && \
npm install node-red-node-ui-list


# 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

# 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

# Saving for future reference in case we have trouble with copying python scripts and flows to the container
# COPY --from=base /python-ml /python-ml
# COPY --from=base /data/flows.json /data/flows.json

# 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", "--cache", "/data/.npm", "--", "--userDir", "/data"]
19 changes: 17 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ version: "3.7"

services:
node-red:
image: nodered/node-red:latest
build: .
# image: nodered/node-red:latest
restart: always
container_name: node-red
environment:
Expand All @@ -18,7 +19,8 @@ services:
networks:
- traefik_proxy
volumes:
- ./docker-data:/data
- flows:/data
- python:/python-ml
# The labels below are used to configure Traefik. Traefik is a reverse proxy and more information can be found here: https://traefik.io/
labels:
- "traefik.enable=true"
Expand All @@ -29,6 +31,19 @@ services:
# - "traefik.http.routers.nodered.rule=Host(`gregory.${DOMAIN_NAME}`)"


volumes:
flows:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: './docker-data'
python:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: './docker-python'

networks:
traefik_proxy:
Expand Down
Loading

0 comments on commit 4776b42

Please sign in to comment.