Giter VIP home page Giter VIP logo

heroku-buildpack-github-netrc's Introduction

Heroku buildpack: GitHub private repo access via ~/.netrc

This buildpack uses a GitHub OAuth2 token exposed as GITHUB_AUTH_TOKEN to resolve private repository URLs without putting a specific username or password in the URLs saved in local files (e.g. package.json).

See Easier builds and deployments using Git over HTTPS and OAuth and GitHub OAuth โ€” Non-web Application Flow for more detail. Also, you may want to choose a user with read-only access.

If you use this in conjunction with the labs:pipeline feature of Heroku, you may avoid setting the GITHUB_AUTH_TOKEN environment variable on your test & prod apps, and instead only set it on the app where you push your code & which runs the buildpack.

Requirements

You'll need to make a GitHub authorization token. Here's the curl command you can use.

$ curl -u 'my-read-only-user' -d '{"scopes":["repo"],"note":"GITHUB_AUTH_TOKEN for Heroku deplyoments","note_url":"https://github.com/timshadel/heroku-buildpack-github-netrc"}' https://api.github.com/authorizations  # GitHub API call
Enter host password for user 'username':  [type password]

{
  "scopes": [
    "repo"
  ],
  "token": "your_token",
  "app": {
    "url": "http://developer.github.com/v3/oauth/#oauth-authorizations-api",
    "name": "Help example (API)"
  },
  "url": "https://api.github.com/authorizations/123456",
  "note": "GITHUB_AUTH_TOKEN for Heroku deployments.",
  "note_url": "https://github.com/timshadel/heroku-buildpack-github-netrc",
  "id": 123456,
}

This token may be revoked at any time by visiting the Applications area of your GitHub account. You'll see the note linked to the note_url and the revoke button right next to it.

You may also create a new token using the GitHub UI; follow the instructions in the GitHub OAuth help article and ensure your token has the "repo" scope.

Usage

First, make sure your app already has a buildpack set:

$ heroku buildpacks

If this does not output an existing buildpack, follow the instructions at https://devcenter.heroku.com/articles/buildpacks

Next, prepend this buildpack to your list of buildpacks, so it runs before your app is built:

$ heroku buildpacks:add -i 1 https://github.com/timshadel/heroku-buildpack-github-netrc.git

Set your GitHub auth token:

$ heroku config:set GITHUB_AUTH_TOKEN=<my-read-only-token>

Deploy your app:

$ git push heroku master  # push your changes to Heroku

...git output...

-----> Fetching custom git buildpack... done
-----> Multipack app detected
=====> Downloading Buildpack: https://github.com/timshadel/heroku-buildpack-github-netrc.git
=====> Detected Framework: github-netrc
       Generated .netrc & .curlrc files (available only at build-time)
       GitHub User:   my-read-only-user
       Authorization: GITHUB_AUTH_TOKEN for Heroku deplyoments (private repo access)
       Organizations: my-org, another-org
...

heroku-buildpack-github-netrc's People

Contributors

camshaft avatar dzuelke avatar mc-jordan-andree avatar mcolyer avatar ryanbrainard avatar timshadel avatar tt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

heroku-buildpack-github-netrc's Issues

Doesn't work with yarn, does work with npm

This is probably a yarn issue for not reading from netrc, but I figured I'd ask you anyway since I'm a big dumb-dumb with respect to how this actually works. Please advise if you have an idea of what yarn might be doing wrong!

doesn't work

-----> github-netrc app detected
       Generated .netrc & .curlrc files (available only at build-time)
/app/tmp/buildpacks/eeb32e6e6d5d4de74da7a5db6b6ecd56d059db9e34b150f0574844b853937897162815fa2429ab515bbf53c66a754091f086ed265408cc53634a034363efe95e/lib/github.rb:20:in `[]': no implicit conversion of String into Integer (TypeError)
	from /app/tmp/buildpacks/eeb32e6e6d5d4de74da7a5db6b6ecd56d059db9e34b150f0574844b853937897162815fa2429ab515bbf53c66a754091f086ed265408cc53634a034363efe95e/lib/github.rb:20:in `block in github_user_orgs'
	from /app/tmp/buildpacks/eeb32e6e6d5d4de74da7a5db6b6ecd56d059db9e34b150f0574844b853937897162815fa2429ab515bbf53c66a754091f086ed265408cc53634a034363efe95e/lib/github.rb:20:in `each'
	from /app/tmp/buildpacks/eeb32e6e6d5d4de74da7a5db6b6ecd56d059db9e34b150f0574844b853937897162815fa2429ab515bbf53c66a754091f086ed265408cc53634a034363efe95e/lib/github.rb:20:in `map'
	from /app/tmp/buildpacks/eeb32e6e6d5d4de74da7a5db6b6ecd56d059db9e34b150f0574844b853937897162815fa2429ab515bbf53c66a754091f086ed265408cc53634a034363efe95e/lib/github.rb:20:in `github_user_orgs'
	from /app/tmp/buildpacks/eeb32e6e6d5d4de74da7a5db6b6ecd56d059db9e34b150f0574844b853937897162815fa2429ab515bbf53c66a754091f086ed265408cc53634a034363efe95e/lib/github.rb:26:in `user_block'
	from /app/tmp/buildpacks/eeb32e6e6d5d4de74da7a5db6b6ecd56d059db9e34b150f0574844b853937897162815fa2429ab515bbf53c66a754091f086ed265408cc53634a034363efe95e/bin/compile:54:in `<main>'
 !     Push rejected, failed to compile github-netrc app.
 !     Push failed

Add usage docs

I'm hoping to get this buildpack updated for compatibility with the Heroku successor to the user-env-compile labs feature.

The README mentions using this buildpack to keep secrets out of package.json, but it's not clear to me how this works in practice. I did a little investigating and it doesn't appear that npm uses .netrc or environment variables when fetching dependencies.

@timshadel, can you shed some light on this?

cc @friism

Error compiling buildpack

This buildpack started failing recently with:

/tmp/buildpacks/e9338.../lib/github.rb:14:in `github_user_login': undefined method `[]' for nil:NilClass (NoMethodError)
	from /tmp/buildpacks/e9338.../lib/github.rb:8:in `login'
	from /tmp/buildpacks/e9338.../lib/github.rb:4:in `valid_login?'
	from /tmp/buildpacks/e9338.../bin/compile:42:in `<main>' 

Installing packages from private repos does not work with pip

-----> Installing dependencies with pip
       Obtaining aaaclient from git+https://github.com/org/repo#egg=aaa (from -r requirements.txt (line 15))
         Cloning https://github.com/org/repo to ./.heroku/src/aaa
fatal: could not read Username for 'https://github.com': No such device or address
         Complete output from command /usr/bin/git clone -q https://github.com/org/repo /app/.heroku/src/aaaclient:

         ----------------------------------------
         Command "/usr/bin/git clone -q https://github.com/org/repo /app/.heroku/src/aaaclient" failed with error code 128 in None

Am I doing something wrong?
It seems like the credentials disappear so that python build pack cannot use them..

Buildpack fails on Heroku-22 due to no system Ruby

Hi!

The Heroku-22 stack was just released:
https://devcenter.heroku.com/changelog-items/2429

However in Heroku-22, there is no longer a system install of Ruby:
https://devcenter.heroku.com/articles/heroku-22-stack#system-ruby-is-no-longer-installed

This buildpack is written entirely in Ruby, and so currently does not work on Heroku-22.

Heroku has it's own fork of this buildpack (https://github.com/heroku/heroku-buildpack-github-netrc), which has solved the issue with Heroku-22 by converting the buildpack to use bash scripts instead of Ruby:
heroku/heroku-buildpack-github-netrc#3

I would recommend either:

  1. Pulling in those changes into this repo.
  2. Or, if you no longer wish to maintain this repo (now that there's a Heroku version), adding deprecation warning messages to the output of this buildpack encouraging users to migrate to the Heroku version.

Many thanks :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.