cloud-builders icon indicating copy to clipboard operation
cloud-builders copied to clipboard

Fetch npm package from private github or google repo.

Open DocBradfordSoftware opened this issue 9 years ago • 7 comments

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?

DocBradfordSoftware avatar Mar 21 '17 20:03 DocBradfordSoftware

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.

DocBradfordSoftware avatar Mar 22 '17 10:03 DocBradfordSoftware

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.

Philmod avatar Mar 24 '17 15:03 Philmod

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.

DocBradfordSoftware avatar Apr 14 '17 23:04 DocBradfordSoftware

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

bendory avatar Jun 15 '17 22:06 bendory

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

DocBradfordSoftware avatar Jun 15 '17 23:06 DocBradfordSoftware

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

bendory avatar Jun 16 '17 00:06 bendory

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.

bendory avatar Jun 19 '17 15:06 bendory