使用POYMENT和deploy密钥从Github安装多个私有软件包

2024-09-27 00:15:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用POYMENT将多个私有Github存储库作为python包安装到我的存储库中。这在本地运行poetry install时效果很好,因为我将我的公共SSH密钥添加到Github,这允许poetry访问私有repo。问题是,我想在我的CI/CD管道中安装这些相同的私有包,为此,我需要为每个repo添加一个部署密钥。需要将正确的部署密钥用于正确的存储库,为了使其正常工作,我需要使用以下格式的一些别名设置配置(我实际上还不知道这是否会正常工作):

// /.ssh/config
Host repo-1.github.com
 IdentityFile ~/.ssh/repo-1-deploy-key
Host repo-2.github.com
 IdentityFile ~/.ssh/repo-2-deploy-key

其中repo-1repo-2是我需要安装的私有存储库的名称。在本地运行时pyproject.toml包需要按以下格式设置:

// pyproject.toml
...
[tool.poetry.dependencies]
repo-1 = { git = "ssh://git@github.com/equinor/repo-1.git" }
repo-2 = { git = "ssh://git@github.com/equinor/repo-2.git" }
...

因为这将允许开发人员在没有任何配置的情况下安装软件包(假定他们有访问权限)。但是,对于CI/CD管道,URL需要与SSH配置文件中的别名匹配,因此需要如下所示:

// pyproject.toml
...
[tool.poetry.dependencies]
repo-1 = { git = "ssh://git@repo-1.github.com/equinor/repo-1.git" }
repo-2 = { git = "ssh://git@repo-2.github.com/equinor/repo-2.git" }
...

现在,我似乎陷入困境的是如何在同一个pyproject文件中包含两个不同的git路径?我尝试了以下方法:

//pyproject.toml

[tool.poetry.dependencies]
repo-1 = { git = "ssh://git@repo-1.github.com/equinor/repo-1.git", optional=true }
repo-2 = { git = "ssh://git@repo-2.github.com/equinor/repo-2.git", optional=true }

[tool.poetry.dev-dependencies]
repo-1 = { git = "ssh://git@repo-1.github.com/equinor/repo-1.git" }
repo-2 = { git = "ssh://git@repo-2.github.com/equinor/repo-2.git" }

[tool.poetry.extras]
cicd_modules = ["repo-1", "repo-2"]

这样我就可以在本地运行poetry install,它将使用开发依赖项和CI/CD管道中的poetry install --no-dev --extras cicd_modules来使用别名路径。遗憾的是,这给了我一个CalledProcessError,因为尽管optional标志设置为true,poetry似乎仍试图安装可选包

我在这里做错了什么?我是否以某种方式错误地使用了可选标志?有没有更好的办法解决这个问题总之,我只希望能够在CI/CD管道中使用POYMENT和Github部署密钥将多个私有存储库安装为软件包,而不破坏本地安装行为,如果是以这种方式或其他更好的方式,我真的没有强烈的意见


Tags: gitgithubcomcipoetry管道密钥cd

热门问题