【问题标题】:Multiple github private npm repositories on a server服务器上的多个 github 私有 npm 存储库
【发布时间】: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 帐户?添加到您帐户的所有密钥都将允许您访问您的私人包。此解决方案只有在没有太多键并且它们不会频繁更改时才有效。

标签: node.js github ssh npm


【解决方案1】:

您必须使用 Deploy Keys 授予服务器对您的私有 github 存储库的 SSH 访问权限。

https://developer.github.com/guides/managing-deploy-keys/

【讨论】:

    【解决方案2】:

    查看有关从全局目录或其他路径加载模块的 Node.js 文档。

    http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders

    【讨论】:

      猜你喜欢
      • 2021-02-26
      • 1970-01-01
      • 2023-03-25
      • 2018-02-07
      • 1970-01-01
      • 2012-05-31
      • 1970-01-01
      • 2021-11-24
      • 2022-11-04
      相关资源
      最近更新 更多