openfaas / templates

OpenFaaS Classic templates
https://www.openfaas.com
MIT License
276 stars 228 forks source link

Support request for private registries and HTTP proxies in Node #223

Closed knulpi closed 3 years ago

knulpi commented 3 years ago

Expected Behaviour

When building and deploying functions in a restricted environment (e.g. a corporate environment), additional settings for npm and npm install might become necessary to be set, including:

Current Behaviour

Currently, it is not possible (or hard, using environment variables for e.g. proxy settings) to specify additional settings for npm.

Possible Solution

The above settings (and more) can be achieved by defining an .npmrc file. When the file is present in the working directory, when executing npm install, npm will consider the configuration from it.

So the proposed solution would be:

Context

The problem is valid in any environment that needs custom npm settings, like custom repositories or proxy settings.

Your Environment

alexellis commented 3 years ago

We have had this request come up in the past over on the faas-cli repo. I'll try to link back to it later, or you can search and add the reference here. https://github.com/openfaas/faas-cli/pull/364 https://github.com/openfaas/faas-cli/issues/255

Adding a .npmrc file with credentials to private npm repos is almost always going to be the wrong solution, it's dangerous and very likely to leak into the image which you are deploying. Perhaps you can clone the private images as part of your GitLab build, and then add them into the build? Have you seen the "copy common files" feature? https://docs.openfaas.com/reference/yaml/#copy

Using --build-arg to inject the data may be a better approach, but be careful to check whether it's cached in the image layers.

For the HTTP proxy, you should be inject this via the --build-arg HTTP_PROXY= mechanism or using the stack.yml file

alexellis commented 3 years ago

/set title: Support request for private registries and HTTP proxies in Node

knulpi commented 3 years ago

I totally agree with the argument of leaking into the image. This may be true and hard to cure.

And --build-arg may be the better solution as well.

Closing here.