“找不到 <package> 的匹配发行版(不可用)”

问题描述 投票:0回答:1

问题

我正在尝试使用

Dockerfile
构建 Docker 映像,该映像使用
pip
安装托管在 GitHub URL 上的 Python 包。此 URL 代表一个“内部”存储库,由企业帐户拥有。作为企业 GitHub 帐户的内部存储库,我必须将秘密的 GitHub 个人访问令牌注入到容器中才能访问存储库。

Dockerfile

中,我在

pip install
之前注入该令牌,如下所示:
RUN --mount=type=secret,id=github_token,uid=1000  git config --global url."https://$(cat /run/secrets/github_token):@github.com/".insteadOf "https://github.com/"
RUN pip install -r requirements.txt

我在以下代码片段中构建
Dockerfile

时注入我的令牌:

docker build --no-cache --secret id=github_token,src=/tmp/github_token.txt .

我已经验证我的令牌文本确实存在于上面引用的 
/tmp/github_token.txt

文件中。

requirements.txt

中的所有要求似乎都安装得很好,直到尝试安装我的私有/内部包,此时 Docker 构建失败并出现以下

pip
错误:
ERROR: Could not find a version that satisfies the requirement <package name> (unavailable) (from versions: none)
ERROR: No matching distribution found for <package name> (unavailable)

我肯定会注入令牌,并且内部存储库肯定存在,那么问题可能是什么?

git docker github pip token
1个回答
0
投票

错误

No matching distribution found for <package name> (unavailable)

并没有告诉我们太多信息。因此,我尝试了一种不同的方法来访问

Dockerfile
中的私人/内部企业存储库,看看是否可以获得不同的错误消息。
我修改了 

Dockerfile

以简单地克隆存储库,将

RUN pip install -r requirements.txt
替换为
RUN git clone https://github.com/<company name>/<package name>
docker 构建在 

git clone

上失败,这是预料之中的。然而,立即出现的错误却有所不同,如下所示:

Cloning into '<package name>'...
remote: The '<company name>' organization has enabled or enforced SAML SSO.
remote: To access this repository, visit https://github.com/orgs/<company name>/sso?authorization_request=xxx and try your request again.
fatal: unable to access 'https://<my secret token>:@github.com/<company name>/<package name>/': The requested URL returned error: 403

尤里卡!我不仅收到了信息更丰富的错误 (
403

),这条 GitHub 特定消息还为我提供了一个超链接,我可以将其粘贴到浏览器中,最终使用 SSO 验证了我的个人访问令牌。

访问 URL 并单击 SSO 按钮后,我能够将 

Dockerfile

恢复到之前的状态并成功安装我的私有/内部软件包。

tl;博士

与所使用的个人访问令牌关联的帐户需要通过 SSO 使用组织的 GitHub 帐户进行身份验证。我能够使用在

git

错误中给我的链接来完成此操作,尽管我相信这也可以通过登录 GitHub 时通过网络浏览器导航到组织的 GitHub 帐户来完成。

    

© www.soinside.com 2019 - 2024. All rights reserved.