来自私有 git 存储库的 Golang 和依赖项
Golang and dependencies from private git repositories
假设我有一个 Go 项目依赖于来自 github 的 2 个不同的私有存储库。我正在使用部署密钥进行 github 身份验证。我正在尝试设置 CI 来构建、测试和部署整个东西。
CI 创建了环境,其中包含所有 2 个部署 ssh 密钥(我们称它们为 ~/.ssh/key1
和 ~/.ssh/key2
)
当我 运行 go build
时,它会尝试一次下载所有依赖项。如何避免 repo 不存在的异常(由于身份验证问题)?您将如何解决该问题?
如果您使用两个不同的密钥,则需要修改这些依赖项的 URL 以便引用这些单独的密钥。
这是通过 ~/.ssh/config
完成的(假设 Jenkins 代理 运行 拥有正确的用户,并且可以访问 ~/.ssh/config
在 ~/.ssh/config
中,您声明了两个 'Host' 条目,每个条目都引用了自己的私钥:
Host repo1
User git
Hostname git.server.com
IdentityFile ~/.ssh/key1
Host repo2
User git
Hostname git.server.com
IdentityFile ~/.ssh/key2
然后确保 repo1 的依赖关系,例如,不再是 git@git.server.com:aUser/aRepo 而是:
repo1:aUser/aRepo
假设我有一个 Go 项目依赖于来自 github 的 2 个不同的私有存储库。我正在使用部署密钥进行 github 身份验证。我正在尝试设置 CI 来构建、测试和部署整个东西。
CI 创建了环境,其中包含所有 2 个部署 ssh 密钥(我们称它们为 ~/.ssh/key1
和 ~/.ssh/key2
)
当我 运行 go build
时,它会尝试一次下载所有依赖项。如何避免 repo 不存在的异常(由于身份验证问题)?您将如何解决该问题?
如果您使用两个不同的密钥,则需要修改这些依赖项的 URL 以便引用这些单独的密钥。
这是通过 ~/.ssh/config
完成的(假设 Jenkins 代理 运行 拥有正确的用户,并且可以访问 ~/.ssh/config
在 ~/.ssh/config
中,您声明了两个 'Host' 条目,每个条目都引用了自己的私钥:
Host repo1
User git
Hostname git.server.com
IdentityFile ~/.ssh/key1
Host repo2
User git
Hostname git.server.com
IdentityFile ~/.ssh/key2
然后确保 repo1 的依赖关系,例如,不再是 git@git.server.com:aUser/aRepo 而是:
repo1:aUser/aRepo