git - docker-compose 无法从 TFS(Team Foundation Server)解析 Git URI
问题描述
TL;博士
有什么方法可以让 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 存储库(主分支),构建 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/存储库-名称”)。
docker-compose 无法解析此 URI 并输出此错误:
服务 '...' 未能构建:{'message': '错误下载远程上下文http://.../tfs/Default/.../_git/ ...: 无法获取http://。 ../tfs/Default/.../_git/ ... 状态为 401 未经授权:\r\n ...
HTML 只是一个带有以下错误代码的错误页面:
完整的 HTML在这里。
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 上为无法访问的资源返回错误页面?
解决方案
您显示的示例(带有https://github.com/dockerfile/ubuntu.git
URL)假定 Git 存储库可公开访问,并且不需要身份验证。另一方面,您的 TFS URL确实需要您进行身份验证。
最好的方法是创建一个个人访问令牌。这将允许您限制对资源的访问并支持简化的身份验证方案(如 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
推荐阅读
- c - 如何在 Windows 的文件系统驱动程序中查找 PNP 设备 ID
- node.js - user.save() 不在 mongodb 中保存(什么都不做)
- vba - 执行 mailmerge 会删除所有书签。有什么选择?
- elasticsearch - ElasticSearch 范围查询
- css - 平板电脑上的 Firefox 正在为输入添加一个蓝色指针
- schema.org - mainEntityOfPage 模式的正确用法是什么
- git - Git如何检查连接到哪个repo项目
- angular6 - 非法状态:无法加载指令 AppComponent 的摘要
- android - Android Studio 与 GitHub 组织整合
- java - Preferences.flush() 和 Preferences.sync() 有什么区别?