gpt4 book ai didi

git - docker-compose 无法从 TFS (Team Foundation Server) 解析 Git URI

转载 作者:太空狗 更新时间:2023-10-29 14:16:32 26 4
gpt4 key购买 nike

长话短说

有什么方法可以让 docker-compose 与 TFS Git URI 一起工作?


我编写了一个简单的 docker-compose.yml,它从包含 dockerfile 的存储库中提取数据并构建图像。

version: '3.4'

services:
ubuntu:
image: ubuntu-fromrepo
build:
context: https://github.com/dockerfile/ubuntu.git
dockerfile: Dockerfile

当你运行它时:

docker-compose up --build

它会自动 pull git 仓库(master 分支),构建 ubuntu 镜像并运行它。

我在 TFS 上有一个带有 dockerfile 的存储库,当您手动 pull 它并运行它时,它就可以工作。因此,git clone ... 克隆 repo,docker build . 构建镜像,然后 docker run -it ubuntu:14.04 (例如,在 TFS 中使用与上面相同的 repo )。

但是,我上面使用的 docker-compose 方法不起作用,因为 TFS 的 Git URI 无法解析。它需要一个 HTTPS Git URI ("https://server-name/repository-name.git") 但在 TFS 中,Git URI 的格式是 ("https ://server-name/tfs/Default/project-name/_git/repository-name").

docker-compose 无法解析此 URI 并输出此错误:

Service '...' failed to build: {'message': 'error downloading remote context http://.../tfs/Default/.../_git/...: failed to GET http://.../tfs/Default/.../_git/... with status 401 Unauthorized: \r\n ...

HTML 只是一个带有以下错误代码的错误页面:

完整的 HTML here .

TF400813: Resource not available for anonymous access. Client authentication required.

有什么方法可以让 docker-compose 与 TFS Git URI 一起工作?


更新:

我已经使用标记化的 URI 对其进行了测试:

git clone https://token@servername/tfs/Default/projectname/_git/repositoryname

有效,但在 docker-compose.yml 文件中使用相同的 URI 无效 - 给出此错误:

ERROR: compose.cli.errors.log_api_error: error detecting content type for remote http://...@.../tfs/Default/.../_git/...: unsupported Content-Type "text/html; charset=utf-8"`

我认为这只是针对无法访问的资源在 TFS 上返回错误页面?

最佳答案

您展示的示例(使用 https://github.com/dockerfile/ubuntu.git URL)假定 Git 存储库可公开访问,并且不需要身份验证。另一方面,您的 TFS URL确实需要您进行身份验证。

最好的方法是创建一个 personal access token .这将允许您限制对资源的访问并支持简化的身份验证方案(如 HTTP Basic)。为“代码(读取)”创建个人访问 token 并记下它。

现在您可以在用于连接的 URL 中指定个人访问 token :

https://username:personal_access_token@servername/tfs/Default/projectname/_git/repositoryname

例如:

https://ethomson:a3bwcvdie7figfhriij4krlfmznko7pgqmr7s7tbuwvdw7xiybza@tfs:8080/tfs/DefaultCollection/Test/_git/testrepo

请注意,您的个人访问 token 就像密码 一样应该受到保护。如果您不想将个人访问 token 直接存储在 docker-compose.yml 中,那么您可以使用环境变量:

services:
ubuntu:
image: ubuntu-fromrepo
build:
context: https://username:${PAT}@servername/tfs/Default/projectname/_git/repositoryname
dockerfile: Dockerfile

关于git - docker-compose 无法从 TFS (Team Foundation Server) 解析 Git URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54037803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com