rapidapps
rapidapps

Reputation: 63

Bluemix node buildpack and modules in private repos

My node.js app uses a number of private shared modules hosted in git repos. I use git URLs like below in the dependencies block in package.json:

"xxx-accountMgr": "git+ssh://[email protected]:xxx/lib-account-mgr.git",

when "cf push" this errors during npm install on ssh:

npm ERR! git clone --template=/home/vcap/.npm/_git-remotes/_templates --mirror ssh://[email protected]/ipaas/lib-account-mgr.git /home/vcap/.npm/_git-remotes/ssh-git-github-xxx-ibm-com-xxx-lib-account-mgr-git-bf65c10c: ssh: Could not resolve hostname github.xxx.ibm.com: Name or service not known

i expected this as I haven't configured the ssh key in bluemix. is that possible? if not, what's the alternative to install modules from a private repo in bluemix?

Upvotes: 0

Views: 803

Answers (5)

Steve R
Steve R

Reputation: 1

You can also use cfnpm module (https://www.npmjs.com/package/cfnpm) it is designed to deal with private package in cliud foundry

Upvotes: 0

nico
nico

Reputation: 144

This is a workaround what works for me is to use npmjs private modules. On one hand it will work and on the other hand it is really easy to manange versions, and reuse code. Of course you'll need to make some minor changes, but is totally worth it.

  1. Upgrade your npmjs account to use private modules: https://www.npmjs.com/private-modules

  2. On your computer log in to npmjs: npm login

  3. Publish your modules

  4. Copy your npmrc file to your project: cp ~/.npmrc /path/to/your/project

  5. npm install your_module --save

  6. Enjoy!

Be aware that if you ever change your password the token inside .npmrc will be revocated.

The token is not derived from your password password, but changing your password will invalidate all tokens. The token will be valid until the password is changed. You can also invalidate a single token by logging out on a machine that is logged in with that token.

Source: https://docs.npmjs.com/private-modules/ci-server-config#checking-in-your-npmrc

Upvotes: 0

jpapejr
jpapejr

Reputation: 211

The problem here is that Bluemix cannot reach back into the corporate network which is apparently where your github repo lives.

It has nothing to do with authentication, although what the others say here is accurate for publically accessible git repositories

Upvotes: 1

Sai Vennam
Sai Vennam

Reputation: 567

If you are downloading a private module hosted on Git, you should be able to use https protocol (with creds) to access it.

There is a trick that could help avoid this issue if that is not an option for you:

1) Package private modules with your application (in node_modules)

2) Move the private modules to devDependencies in package.json, rather than dependencies, so that your local dev workflow is unaffected.

npm install will install dependencies and devDependencies. By default, Bluemix will only install dependencies

Step 2 is necessary because even if you package the private node_modules with your application, staging for your application will fail because npm still tries to access your private repo to validate the dependency.

Also, if you had a .cfignore file ignoring the entire node_modules directory, that would have to be changed to ignore only the public modules.

Upvotes: 3

Ben Rondeau
Ben Rondeau

Reputation: 3053

If the private repo requires Github authentication to access the shared mdoules, Bluemix won't be able to access them. You can use a command such as git clone https://github.com/repo/etc but that will require the files to be accessible without authentication.

An alternative could be to manual install the files in your repo prior to using cf push so they are available. This is not a great solution but it will solve the problem in the short term.

Upvotes: 1

Related Questions