testcontainers-go icon indicating copy to clipboard operation
testcontainers-go copied to clipboard

[Feature]: Support custom auth configs in container options

Open SpencerC opened this issue 1 year ago • 4 comments

Problem

In sandboxed/hermetic environments such as Bazel, $HOME is not available. This causes builds to fail following #2727. In our case, we're just using public registries so appearently being unable to load an auth config wasn't a problem before.

Solution

Add DockerConfig and DockerAuthConfig options to ContainerRequest or FromDockerfile.

Benefit

This would simplify the upgrade/management process for users running TestContainers in sandboxed environments. It also seems more consistent with the design of the rest of the package (e.g. configuration in code vs. environment variables).

Alternatives

Testers can always set DOCKER_CONFIG or DOCKER_AUTH_CONFIG in their bash profile, but then this needs to be done on every system running the tests.

Another approach is to map a sandbox path and set DOCKER_CONFIG at runtime:

dac, err := runfiles.Rlocation("_main/docker/.config")
if err != nil {
	log.Fatalf("could not get absolute path to docker auth config: %v", err)
}
if err := os.Setenv("DOCKER_CONFIG", dac); err != nil {
	log.Fatalf("could not set DOCKER_CONFIG: %v", err)
}

But this is a bit hacky.

Would you like to help contributing this feature?

Yes

SpencerC avatar Aug 31 '24 14:08 SpencerC