【问题标题】:docker-compose is not able to resolve Git URIs from TFS (Team Foundation Server)docker-compose 无法从 TFS(Team Foundation Server)解析 Git URI
【发布时间】:2019-01-04 22:56:54
【问题描述】:

TL;DR

有什么方法可以让 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

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

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

但是,我上面使用的 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 并输出此错误:

服务 '...' 未能构建:{'message': '错误下载远程上下文 http://.../tfs/Default/.../_git/...: 无法 GET http://.../tfs/Default/.../_git/... 状态为 401 Unauthorized: \r\n .. .

HTML 只是一个错误页面,错误代码如下:

完整的 HTML here.

TF400813:资源不可用于匿名访问。需要客户端身份验证。

有什么方法可以让 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 上为不可访问的资源返回错误页面?

【问题讨论】:

  • 该错误消息的其余部分是什么?似乎不太可能是 URL,似乎更有可能是无法通过身份验证。
  • 更新了问题并在 pastebin 中添加了指向 HTML 错误页面的链接
  • 嗯。 username:pat 真的应该是正确的格式。您的克隆测试是否有可能是误报?您可能在本地安装了凭证助手吗?

标签: git docker tfs docker-compose


【解决方案1】:

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

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

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

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

例如:

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

请注意,您的个人访问令牌类似于密码,因此应该受到保护。如果您不想将个人访问令牌直接存储在 docker-compose.yml 中,那么您可以使用环境变量:

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

【讨论】:

  • 谢谢,我认为您的输入确实帮助我找到了正确的方向 - http://**username**:**token**@.... 的格式不起作用。但是,http://**token**@... 做到了。诡异的。我只是要测试一些东西......
  • 使用新 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"
  • 抱歉 - 我错误地更新了你的答案而不是我的问题 - @moderator 你能恢复更改吗?
猜你喜欢
  • 2010-10-11
  • 1970-01-01
  • 1970-01-01
  • 2013-04-15
  • 2011-01-12
  • 2012-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多