Jos*_*der 1 git pip github heroku
应用程序结构(Python FastAPI):
-my_app
-server.py
-Procfile
-requirements.txt
Run Code Online (Sandbox Code Playgroud)
为了安装 Heroku 应用程序所需的私有 git 存储库,我将以下行添加到我的requirements.txt
:
git+https://<github-token>@github.com/me/my-private-repo.git
Run Code Online (Sandbox Code Playgroud)
然而,在推送时,Github 给我发了一封电子邮件,说由于我在提交中暴露了我的令牌,所以它已撤销了该令牌。(我的应用程序存储库是私有的。)完全公平!但是,我的 Heroku 构建现在失败了,因为它在尝试安装私有存储库时提示输入密码。
我在互联网上搜索过很多次 re: private repos,但总是遇到相互矛盾的建议。
我们将很高兴听到在这种情况下,在自动化构建中安全安装私有存储库的最佳实践是什么。
到目前为止我尝试过的:
git+git://username:password@github.com/me/myrepo.git
而不是令牌显然有同样的问题git+ssh://git@github.com/me/myrepo.git
- 产生错误Host key verification failed.
pip
要扩展该ssh
选项,请在我的本地计算机上执行以下操作:
pip3 install git+ssh://git@github.com/me/my_private-repo.git
git clone https://github.com/me/my_private-repo.git
然而,当我的requirements.txt
contains时git+ssh://git@github.com/me/my_private-repo.git
,我的 Heroku 构建会返回Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
终于开始工作了。我感谢 Michel Blancard 的回答和相关要点,以及 Bo Jeanes 的定制 buidpack:
在requirements.txt
:
git+ssh://git@github.com/me/my-private-repo.git
Run Code Online (Sandbox Code Playgroud)
将我的 SSH 私钥转换为 Heroku 的(旧)PEM 格式(!):
ssh-keygen -f ~/.ssh/id_rsa -m PEM -p
Run Code Online (Sandbox Code Playgroud)
(由于这个答案而致谢)
添加 SSH 私钥作为 Heroku 变量:
heroku config:set BUILDPACK_SSH_KEY="$(cat ~/.ssh/id_rsa)"
Run Code Online (Sandbox Code Playgroud)
添加此自定义构建包以在启用 SSH 私钥的 Python 构建包之前运行:
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-ssh-key.git
Run Code Online (Sandbox Code Playgroud)
部署!
归档时间: |
|
查看次数: |
1102 次 |
最近记录: |