docker-compose is not able to resolve Git URIs from TFS (Team Foundation Server)

Viewed 1560

TL;DR

Is there any way I can get docker-compose to work with TFS Git URIs?


I have written a simple docker-compose.yml that pulls from a repository containing a dockerfile and builds an image.

version: '3.4'

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

When you run this with:

docker-compose up --build

it will automatically pull the git repository (master branch), build the ubuntu image and run it.

I have a repository on TFS with a dockerfile that works when you pull it manually and run it. So, git clone ... to clone the repo, docker build . to build the image and then docker run -it ubuntu:14.04 (for example with the same repo pulled as above in TFS).

However, the docker-compose method that I used above does not work as the Git URI for TFS fails to resolve. It expects a HTTPS Git URI ("https://server-name/repository-name.git") but in TFS, Git URIs are in the format ("https://server-name/tfs/Default/project-name/_git/repository-name").

docker-compose fails to resolve this URI and outputs this error:

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 ...

The HTML is just an error page with the following error code :

Full HTML here.

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

Is there any way I can get docker-compose to work with TFS Git URIs?


UPDATE:

I have tested it with the tokenized URI:

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

which works, but using the same URI in the docker-compose.yml file does not - gives this error:

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"`

I think this is just returning the error page on TFS for an inaccessible resource?

1 Answers

The example that you've shown (with the https://github.com/dockerfile/ubuntu.git URL) assumes that the Git repository is publicly accessible, and does not require authentication. Your TFS URL, on the other hand, does require you to authenticate.

The best way to do this would be by creating a personal access token. This will allow you to both limit access to the resource and support simplified authentication schemes (like HTTP Basic). Create a personal access token for "Code (read)" and make a note of it.

Now you can specify the personal access token in the URL you use to connect:

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

For example:

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

Note that your personal access token is like a password and should be secured as such. If you don't want to store the personal access token directly in the docker-compose.yml then you could use an environment variable:

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