Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open question for anyone who has a good understanding of npm #587

Open
Paraphraser opened this issue Jul 4, 2022 · 0 comments
Open

Open question for anyone who has a good understanding of npm #587

Paraphraser opened this issue Jul 4, 2022 · 0 comments

Comments

@Paraphraser
Copy link

This is a request for guidance from anyone who has a good understanding of NPM (which isn't me).

I start at IOTstack/.templates/nodered/addons.yml. This is the directives file used as the basis for generating the Node-RED Dockerfile for IOTstack.

I want to focus on line 5 which is:

dockerFileInstallCommand: "RUN cd /usr/src/node-red && npm install --save "

If you run the menu, select Node-RED and accept the "default on" nodes, the Dockerfile you get is:

FROM nodered/node-red:latest-12
USER root
RUN apk update && apk add --no-cache eudev-dev
USER node-red

RUN cd /usr/src/node-red && npm install --save  node-red-configurable-ping
RUN cd /usr/src/node-red && npm install --save  node-red-contrib-boolean-logic
RUN cd /usr/src/node-red && npm install --save  node-red-contrib-influxdb
RUN cd /usr/src/node-red && npm install --save  node-red-dashboard
RUN cd /usr/src/node-red && npm install --save  node-red-node-pi-gpiod
RUN cd /usr/src/node-red && npm install --save  node-red-node-rbe

Question 1: why cd /usr/src/node-red?

The first command on each of the last 6 lines is cd /usr/src/node-red.

Our Dockerfile runs atop the Node-RED Dockerfile. Line 33 of the upstream Dockerfile sets the working directory:

WORKDIR /usr/src/node-red

and that is inherited when our IOTstack Dockerfile runs. It's easy enough to prove this by adding pwd && between the RUN and the cd:

 => [3/8] RUN pwd && cd /usr/src/node-red && npm install --save  node-red-configurable-ping
 => # /usr/src/node-red
 …

Question 2: why --save?

The Dockerfile generated by the menu uses the latest-12 tag but latest-14 and latest-16 tags are also available on DockerHub:

# build with latest-12
$ docker exec nodered bash -c 'node --version ; npm --version'
v12.22.8
6.14.15

# build with latest-14
$ docker exec nodered bash -c 'node --version ; npm --version'
v14.18.2
6.14.15

# build with latest-16
$ docker exec nodered bash -c 'node --version ; npm --version'
v16.13.1
8.1.2

I take that to mean that the earliest version of npm we need to consider is 6.14.15.

  • Neither the (legacy) v6 documentation nor the (current) v8 documentation for npm install lists the --save flag.
  • According to the (discontinued) NPM blog, --save has been the default since NPM version 5. This seems to be borne out by PR 15666 which is dated 2017-05-02.

Practical experience

My own Dockerfile has looked like this for getting on for 2 years:

FROM nodered/node-red:latest-14
USER root
RUN apk update && apk add --no-cache eudev-dev mosquitto-clients bind-tools tcpdump tree
USER node-red
RUN npm install \ 
  node-red-node-pi-gpiod \
  node-red-dashboard \
  node-red-contrib-influxdb \
  node-red-contrib-boolean-logic \
  node-red-node-tail \
  node-red-configurable-ping \
  node-red-node-email

I have no change of directory ahead of the npm install and no --save option. Node-RED (the container, and all the add-ons, whether installed via Dockerfile or Manage Palette) have always just worked and have never given me a moment's trouble.

Is my conclusion correct that both the change of directory and the --save are redundant, or is there something about this that I'm missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant