【发布时间】:2016-04-08 09:01:37
【问题描述】:
我在 github 上的私有存储库中有一个节点应用程序。此节点应用程序还具有我制作的自定义模块,它们位于单独的私有存储库中。
这是示例节点应用程序网址:
git@github.com:thomas/node-application.git
这些都是节点应用程序使用的节点模块。
git@github.com:thomas/node-module1.git
git@github.com:thomas/node-module2.git
您可以使用以下方式在 github 上安装私有 npm 模块。
npm install git+ssh://git@github.com:thomas/node_module1.git
为了让这个工作,机器需要设置 ssh 密钥。
我的本地机器设置了我的 github 用户密钥并可以访问我的所有存储库。
在我的服务器上,但是我使用的是部署密钥。我知道如何使用多个部署密钥的唯一方法如下。
Host na.github.com
HostName github.com
User git
IdentityFile ~/.ssh/gh_node-application
ForwardAgent yes
Host nm1.github.com
HostName github.com
User git
IdentityFile ~/.ssh/gh_node-module1
ForwardAgent yes
Host nm2.github.com
HostName github.com
User git
IdentityFile ~/.ssh/gh_node-module2
ForwardAgent yes
所以我需要在服务器上安装模块
npm install git+ssh://git@nm1.github.com:thomas/node_module1.git
^^^
这意味着生产和开发的依赖会不同
"node-module": "git+ssh://git@github.com:thomas/node-module1.git"
对
"node-module": "git+ssh://git@nm1.github.com:thomas/node-module1.git"
^^^
如果我能做这样的事情,这可能会奏效……
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/gh_node-application
IdentityFile ~/.ssh/gh_node-module1
IdentityFile ~/.ssh/gh_node-module2
ForwardAgent yes
【问题讨论】:
-
我走的是Machine Users的路线。我真的很讨厌XD
-
您是否尝试将部署密钥添加到您的 github 帐户?添加到您帐户的所有密钥都将允许您访问您的私人包。此解决方案只有在没有太多键并且它们不会频繁更改时才有效。