Heroku: Python dependencies in private repos without storing my password

后端 未结 4 1849
挽巷
挽巷 2021-02-19 02:36

The Problem

My problem is exactly like How do I install in-house requirements for Python Heroku projects? and How to customize pip's requirements.txt in Heroku on

4条回答
  •  既然无缘
    2021-02-19 02:48

    I created a buildpack to solve this problem using a custom ssh key stored as an environment variable. As the buildpack is technology agnostic, it can be used to download dependencies using any tool like composer for php, bundler for ruby, npm for javascript, etc: https://github.com/simon0191/custom-ssh-key-buildpack

    1. Add the buildpack to your app:

      $ heroku buildpacks:add --index 1 https://github.com/simon0191/custom-ssh-key-buildpack
      
    2. Generate a new SSH key (lets say you named it deploy_key)

    3. Add the public key to your private repository account. For example:

      • Github: https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

      • Bitbucket: https://confluence.atlassian.com/bitbucket/add-an-ssh-key-to-an-account-302811853.html

    4. Encode the private key as a base64 string and add it as the CUSTOM_SSH_KEY environment variable of the heroku app.

    5. Make a comma separated list of the hosts for which the ssh key should be used and add it as the CUSTOM_SSH_KEY_HOSTS environment variable of the heroku app.

      # MacOS
      $ heroku config:set CUSTOM_SSH_KEY=$(base64 --input ~/.ssh/deploy_key) CUSTOM_SSH_KEY_HOSTS=bitbucket.org,github.com
      # Ubuntu
      $ heroku config:set CUSTOM_SSH_KEY=$(base64 ~/.ssh/deploy_key) CUSTOM_SSH_KEY_HOSTS=bitbucket.org,github.com
      
    6. Deploy your app and enjoy :)

提交回复
热议问题