0

Using private registry in connection with IBM Cloud DevOps pipeline, we've got modules published. In DevOps pipeline also build is possible using following tactic:

    #!/bin/bash
    export PATH=/opt/IBM/node-v6.7.0/bin:$PATH
    npm config set @<scope>:registry <registry-url>
    echo "//<registry-url-short>:_authToken=$NPM_TOKEN" >> ~/.npmrc
    npm install

This way both public and private modules are found and installed. However, when it comes time to deploy to NodeJS runtime, then 'npm install' is done on platform side.

How can we instruct that with above ?

jarkko
  • 76
  • 8

2 Answers2

1

One possible way is to have your private modules downloaded in a different directory using the postinstall script in npm. Here is a good explanation on how to achieve this.

https://github.com/pmuellr/bluemix-private-packages

S. Holmes
  • 68
  • 1
  • 7
  • I tried this. It seems to stumble on how the scope is handled. It is another folder in node_modules. Thus, when it tries to create node_modules// folder, it fails. If you manage to create node_modules/ for it beforehand - then it works. But I think I'll go with creating .npmrc build time, not to $HOME, but into build package, cause that is less application changes and we have several applications. – jarkko Dec 21 '17 at 11:52
1

Another approach is to package your .npmrc file along with your app when you push it. More info here https://github.com/cloudfoundry/nodejs-buildpack/issues/79

The approach here is to create a .npmrc as part of your build stage and add it to the root of your artifact folder. In the next stage when you deploy the app from the artifact folder your npm configuration will be correctly set for per-project config (see https://docs.npmjs.com/files/npmrc) and the npm install that the cf node build-pack performs will work correctly.

  • Possibly explain a little more on what needs to happen? – Jeffrey Dec 21 '17 at 04:44
  • Simon, When you say "package your .npmrc file" and what I read from the link, it sounds like you would wanna put the file into repository. That is definately not ideal. But it does work. If you could edit your answer to more clearly state, that it can be created during build process, not into $HOME/.npmrc (as I thought), but into build package .npmrc, then I can tick this as the accepted answer. – jarkko Dec 21 '17 at 11:47
  • Quite right. You definitely do not ever want to put your .npmrc with creds in your source control repo. The idea is for your build stage to put your .npmrc file at the root of the folder that you're using for build artifacts. In the deploy stage you then cf push this folder. This sets you up to use a per-project npm config vs. copying this file to ~/.npmrc which is per-user config. See https://docs.npmjs.com/files/npmrc – Simon Kaegi Dec 21 '17 at 17:41