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

npm install from values file #198

Closed
2 tasks done
beasteers opened this issue Jan 4, 2023 · 7 comments
Closed
2 tasks done

npm install from values file #198

beasteers opened this issue Jan 4, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@beasteers
Copy link

beasteers commented Jan 4, 2023

Is your feature request related to a problem? Please describe.

Many times, people want to use custom nodes in nodered, but there isn't an obvious way to install them using the configuration. Basically, just looking for a way to do npm i pkgA from values.yaml.

Describe the solution you'd like

Some options:

  1. simplest - working example using an init container/sidecar (commented out) in values.yaml.
  2. allow package.json from config map - requires the user to populate the rest of the package.json and could have other implications (? or benefits?)
  3. Add startupCommands: ["npm i pkgA"] or installPackages: ["pkgA"] to values.yaml

Describe alternatives you've considered

I'm working on getting the right init container/sidecar setup but need to figure out the right base image, volume mounts, and other config necessary. I'm not sure I understand the difference between /data/package.json and /usr/src/node-red/package.json tho

Search

  • I did search for other open and closed issues before opening this.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Additional context

No response

@beasteers beasteers added the enhancement New feature or request label Jan 4, 2023
@dirien
Copy link
Collaborator

dirien commented Jan 22, 2023

hi @beasteers,

Had no time to check on this one. Is this still needed for you?

@beasteers
Copy link
Author

No worries, I ended up forking and did the install by overriding container command to install before launching node-red. It'd be a good thing to have built-in to the chart though

@hinrichd
Copy link
Contributor

hinrichd commented Jun 5, 2023

Hi,
I think from the k8s microservice perspective the additional node modules (npm packages) should be installed when reading/refresh the flows from the k8s-sidecar. This would be insure there are no missing nodes. Check nodes requirements, install modules, reload flowrefresh.py....

The modules can be installed via API request (POST /nodes) and existing sidecar and preserves privilege escalation in the container as npm needs admin rights.

Actually, for automating this process I am missing the node module name from the GET /flows json v2 result to check if the node is installed (GET /nodes)and if not installing the corresponding node module (POST /nodes) .

Workaround would be an extra helm list value witch installs the npm modules from an extra sidecar. The modules had to declared separately and have to match with the flows nodes modules.

I am facing the same feature for my installation. Not sure witch method is the best to choose from.

@hinrichd
Copy link
Contributor

I started a thread in the node-red user forum.

https://discourse.nodered.org/t/api-install-flows-and-modules-automated-via-api-requests/78962/3

But it looks like i have to declare the module names (npm packages) separately.

Most probably you have to. There's no data referencing the (e.g. npm) package name of a node in the flows json. If you try to guess the package name, you may even fall over ambiguities - as there's no mechanism to ensure that a node name may only be used once in the Node-RED universe...

This means the package module names have to be declared manually. If using the sidecar in the helm chart for import flows this have to match.

I can write a python script for installing extra node modules, same way like in the sidecar for flows. Not sure if this is the best way to do it. Declare extra NPM Module Names in a ConfigMap. Watch the ConfigMap and interate threw the module names and install each one.... Have to check if this is possible within the existing sidecar, or even within the flow_refresh script. There will be some ups and downside depending on how you use the helm chart.

@beasteers and @dirien
What do you think?

@hinrichd
Copy link
Contributor

Have done some testing with the flow_refresh.py script. I think it works very well....New Script

  1. Put NODE_MODULES variable in sidecar.extraEnv, e.g.
  extraEnv:
    - name: LOG_LEVEL
      value: "DEBUG"
    - name: NODE_MODULES
      value: "node-red-contrib-xkeys_setunitid, node-red-contrib-microsoft-teams-tasks, node-red-contrib-json"
  1. Script will check if this modules are already installed and install missing ones.
  2. Script will reload flows

Node Modules will be installed shortly after pod startup. ExtraEnv is not the best place to store the node module names. This is just for a first poc or test. Maybe a configMap would be fit better.

python3 flow_refresh.py

----START PYTHON SIDECAR SCRIPT----
node-red node module install and flow refresh api call via k8s-sidecar
sidecar sleeping for 5 seconds...
----TOKEN----
node-red bearer token successfully created - 200
----INSTALL EXTRA MODULES----
extra node modules from env - ['node-red-contrib-xkeys_setunitid', 'node-red-contrib-microsoft-teams-tasks', 'node-red-contrib-json']
installed node modules - ['node-red-contrib-xkeys_setunitid', 'node-red']
node module node-red-contrib-xkeys_setunitid already installed...
node module node-red-contrib-microsoft-teams-tasks successfully installed -  200
node module node-red-contrib-json successfully installed -  200
----RELOAD FLOWS----
node-red flows successfully reloaded - 200

@dirien
Copy link
Collaborator

dirien commented Jul 29, 2023

Hey @beasteers,

Hope the feature from @hinrichd is helping you. Closing this issue for now.

@dirien dirien closed this as completed Jul 29, 2023
@beasteers
Copy link
Author

There's one issue with the current solution - this doesn't support packages that are needed in the settings.js file which will prevent nodered from starting in the first place - e.g. authentication providers, themes, etc.

I guess the best place for this to live would be in an init container?

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

No branches or pull requests

3 participants