Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]: Allow temporarily disabling TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX via ImageSubstitutor #2554

Closed
zann1x opened this issue May 24, 2024 · 6 comments · Fixed by #2577
Labels
enhancement New feature or request

Comments

@zann1x
Copy link

zann1x commented May 24, 2024

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.

@zann1x zann1x added the enhancement New feature or request label May 24, 2024
@mdelapenya
Copy link
Member

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?

@zann1x
Copy link
Author

zann1x commented Jun 12, 2024

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.

@mdelapenya
Copy link
Member

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)?

@zann1x
Copy link
Author

zann1x commented Jun 13, 2024

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.

@mdelapenya
Copy link
Member

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 🙏

@zann1x
Copy link
Author

zann1x commented Jun 13, 2024

Yeah, that's perfectly fine 🙂

@zann1x zann1x closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants