Cloud-builders: Fetch npm package from private github or google repo.

Created on 21 Mar 2017  ·  7Comments  ·  Source: GoogleCloudPlatform/cloud-builders

npm allows you to fetch node_modules directly from a github private repo.

"dependencies": {
    "express": "4.14.0",
    "privatepackage": "git+https://github.com/myaccount/privatepackage.git"
  }

Is there a way in builder to access either github or if I mirror the repo at google.

    "privatepackage": "https://source.developers.google.com/p/$PROJECT_ID/r/privatepackage"

How would I pass credentials?

Most helpful comment

This newly-published doc on Using Encrypted Files in your build should be helpful.

All 7 comments

I have a "hack" not what I would call a "solution" to this problem. It involves,

  1. Make a copy of package.json
  2. Download private repo, using either gcloud builder or git buider.
  3. remove private repo from package.json
  4. run npm install.
  5. copy private repo to node_modules.
  6. replace package.json with original.
  7. run npm rebuild.
  8. build image.

It's not elegant.

Hey!

We don’t have an integrated solution as of today, but here are a few solutions coming from users:

  1. Create a Github token with “repo” scope, then use this syntax in the package.json:

"my-private-module": "git+https://<github_token>:[email protected]/<user>/<repo>.git"

  1. Use a Deploy or User Key that you could store in GCS for example, and pull it as a previous build step.

I hope this helps.

Thanks, @Philmod, the only problem with that approach, is that if you don't commit the url including the github token to GitHub, you will have to do some kind of "sed" like replacement in package.json. You would have to do it both on the developer side and the builder side, or .gitignore package.json and copy package.json.builder to package.json, all of which is messy. I think i'll need to do the same thing that i did with kubectl bring the git auth in from GCS and configure git. Like it is on my dev box.

This newly-published doc on Using Encrypted Files in your build should be helpful.

Wow, thanks @bendory, that is simple and effective. Way better than storing the account.json file in gs//.

Great! So glad you like it!
Shall we close this issue?

I'm closing this issue with the assumption that our doc on Using Encrypted Files resolves this issue. Please re-open if that does not provide you with what you need.

Was this page helpful?
0 / 5 - 0 ratings