testcontainers / testcontainers-go

Testcontainers for Go is a Go package that makes it simple to create and clean up container-based dependencies for automated integration/smoke tests. The clean, easy-to-use API enables developers to programmatically define containers that should be run as part of a test and clean up those resources when the test is done.
https://golang.testcontainers.org
MIT License
3.54k stars 489 forks source link

[Enhancement]: Document github container registry authentication without docker #2784

Open koliyo opened 2 weeks ago

koliyo commented 2 weeks ago

Proposal

I was struggling with login in to our github container registry because the ghcr.io/atc0005/go-ci image does not have the docker binary. I did however find a working solution, by handcrafting a .docker/config.json as mentioned here: https://golang.testcontainers.org/features/docker_auth/

But having explicit instructions how to actually do it for github actions would be very helpful. So I suggest adding the following setup as an example in a github action workflow:

    - name: Docker registry login
      run: |
        mkdir -p $HOME/.docker
        AUTH_BASE64=$(echo ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} | base64)
        echo '{"auths":{"ghcr.io":{"auth":"{#}"}}}' | sed "s/{#}/$AUTH_BASE64/g" > $HOME/.docker/config.json

This will work with testcontainers even if the host container does not contain the docker binary.

mdelapenya commented 2 weeks ago

Hi @koliyo, thanks for raising this issue. We already explain in https://golang.testcontainers.org/features/docker_auth/ the different mechanisms to discover the Docker auth, but I'm not against adding custom examples for how to achieve what you did.

Do you mind submitting a PR to the docs site, to that page? I could imagine adding it at the end of the page with something like this:

## Docker Auth examples

### Creating a custom Docker config file
(...your code snippet...)

I think the matter of being GHCR or any other site it's an implementation detail, so I'd not create a dedicated entry for GHCR, but use it as the code snippet for a general way for building the auth config file.

Wdyt?