add proxy support for nodejs plugin

Bug #1611372 reported by Mitsuya Shibata
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
Invalid
Medium
Unassigned

Bug Description

npm command cannot access registry server over ssl.

  https://github.com/npm/npm/issues/2050

Generally, to workaround this problem, npm user will set http"s"-proxy config to use "http" proxy or set registry config to use via http.

  npm config set https-proxy "http://proxy:port/"
    or
  npm config set registry "http://registry.npmjs.org/"

Could you introduce this workaround to nodejs plugin?

Revision history for this message
Mark Shuttleworth (sabdfl) wrote : Re: [Bug 1611372] [NEW] add proxy support for nodejs plugin

The interesting thing here is that this option seems to be
location-specific. It's not something you'd want in a shared
snapcraft.yaml because every developer would have a different preference
or requirement. So this needs to be something that a developer can set
as a snapcraft option which just gets applied every time snapcraft is
being used to drive npm.

So this is a snapcraft config item that is specific to the nodejs
plugin, which is cool.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

We have logic for this when using maven picking up proxy configuration from the environment. We need to create a part specific npm configuration file and would get the same result.

Changed in snapcraft:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Mitsuya Shibata (cosmos-door) wrote :

Hi Mark and Sergio,

> It's not something you'd want in a shared
> snapcraft.yaml because every developer would have a different preference
> or requirement.

Indeed. Proxy settings shouldn't be in snapcraft.yaml.

Already mentioned by Sergio, maven plugin create config file from
http_proxy/https_proxy environment variables before run maven command.

Calling "npm config -g" provides nearly feature of this. With "-g" option,
config file will be create in parts directory, doesn't affect developer's
settings (as like ~/.npmrc).

I sent pull request for this ticket. Could you review this?
https://github.com/snapcore/snapcraft/pull/738

Revision history for this message
Leo Arias (elopio) wrote :

Thanks for bringing this up and for your code!

From what I understood after reading the npm issue and the PR, I don't think this should be worked around in snapcraft.

If your https proxy is not good to work with npm, the solution is not going to be to always use the http proxy instead. I think snapcraft should just respect the environment, so you would fix this by setting npm_config_https_proxy to whatever is correct for your network, before calling snapcraft.

Revision history for this message
Mitsuya Shibata (cosmos-door) wrote :

> If your https proxy is not good to work with npm, the solution is not going to be to always use the http proxy instead. I think snapcraft should just respect the environment, so you would fix this by setting npm_config_https_proxy to whatever is correct for your network, before calling snapcraft.

Umm..., I'm sure you're right.

Until it pointed out by Sergio, I didn't know about npm_config_ENV mechanism (sorry its my bad). It seems that setting npm_config_ENV instead of changing generally used https_proxy by user (not snapcraft command) on builder environment is reasonably way. I thought if customizing https_proxy is only solution for this problem, then snapcraft command should do that and afterwards restore previous value by automatically.

I will close this ticket and pull request.

Thanks!

Changed in snapcraft:
status: Triaged → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.