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.

Home Page:https://golang.testcontainers.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Enhancement]: Allow temporarily disabling `TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX` via `ImageSubstitutor`

zann1x opened this issue · comments

Proposal

When using a custom implementation of an ImageSubstitutor while also having set TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX, the prefix will be prepended if testcontainers decides that the image name still needs a substitution before starting the container. This is adequate behavior for all the cases where there should be a default registry to fall back to if none of the prior ImageSubstitutors set one. But it poses a problem when the image under test was built and tagged locally and has not been published to a registry yet.
It would be great if an ImageSubstitutor could have the option disable the prefixing mechanism.

Hi @zann1x so the issue is when building an image from a Dockerfile, in which we do not have yet an image name as it's empty, right? I can think of why it's happening: the substitutors are always applied before the build image is processed, so the built image receives a tag without the substitutors applied. I think I can elaborate a fix soon for this.

Do you mind if I change this issue to a bug?

Hi @zann1x so the issue is when building an image from a Dockerfile, in which we do not have yet an image name as it's empty, right?

Not quite.
It might be important to note that I don't build the image via testcontainers. The build process is a CI pipeline step that happens explicitly via docker build -t localhost/foobar .. This is done before calling anything related to testcontainers and before publishing the image to a registry. The issue is that when using this local image, testcontainers will prepend the prefix specified in TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX to localhost/foobar. An image with this prefix doesn't actually exist, so there is no way that testcontainers can create a container from it.

Mmm my question then is, if the build happens in the CI, and your testcontainers settings add the prefix, why does not your CI build all the images (e.g. localhost/foobar and myprefix/localhost/foobar)?

The prefix is only used so that external images (e.g. ryuk) aren't pulled from Docker Hub but are proxied through our own registry. I would have expected that I could simply override the prefixing behavior for internal images on a container level with ImageSubstitutors. This wasn't the case, so I created this feature proposal.

My problem can indeed be fixed by adding some prefix to the image name. So it would be fine for me if you decide that this feature shouldn't be supported and this issue is closed.

I'd say that this use case can be bypassed with a custom setup, so I'd try to avoid custom fixes in the library for them.

Hope you understand 🙏

Yeah, that's perfectly fine 🙂