-
Notifications
You must be signed in to change notification settings - Fork 80
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
Allow customization of test containers image name #266
Conversation
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Andy Su (Apps).
|
3cd79ca
to
aa99a08
Compare
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Andy Su (Apps).
|
aa99a08
to
b4a5de7
Compare
ba9e9cd
to
3fb6096
Compare
gateway-ha/src/test/java/io/trino/gateway/CustomImageNameSubstitutor.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/CustomImageNameSubstitutor.java
Outdated
Show resolved
Hide resolved
@Override | ||
public DockerImageName apply(DockerImageName dockerImageName) | ||
{ | ||
if (dockerImageName.asCanonicalNameString().equals("trinodb/trino:latest") && System.getenv(TESTCONTAINERS_TRINO_IMAGE_SUBSTITUTE) != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the 1st condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first condition makes sure we are overriding a specific image. If we don't specify it will just substitute all images
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #266 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand you want to change only Trino image names. I suppose we should tweak the condition to exclude the version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can probably use this getUnversionedPart()
from https://javadoc.io/doc/org.testcontainers/testcontainers/1.15.1/org/testcontainers/utility/DockerImageName.html#getUnversionedPart--
gateway-ha/src/test/java/io/trino/gateway/CustomImageNameSubstitutor.java
Outdated
Show resolved
Hide resolved
{ | ||
return "custom image name substitutor"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testcontainers.properties
isn't required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was going to use env variables to configure this. https://java.testcontainers.org/features/configuration/
It looks like we can just choose one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use env variables, why this class is required? I'm looking the following sentence:
Setting environment variables TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX=registry.mycompany.com/mirror/
https://java.testcontainers.org/features/image_name_substitution/#automatically-modifying-docker-hub-image-names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may not work because it needs image name to be predictable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it needs image name to be predictable
I don't understand this. Can you elaborate on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use env variables, why this class is required? I'm looking the following sentence:
Setting environment variables TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX=registry.mycompany.com/mirror/
https://java.testcontainers.org/features/image_name_substitution/#automatically-modifying-docker-hub-image-names
The link you are looking at is specifically adding prefix to image name. It has an assumption:
Consider this if:
Your private registry has copies of images from Docker Hub where the names are predictable, and just adding a prefix is enough. For example, registry.mycompany.com/mirror/mysql:8.0.36 can be derived from the original Docker Hub image name (mysql:8.0.36) with a consistent prefix string: registry.mycompany.com/mirror/
Also, it looks like even though we can change the registry, the names of the image have to match. In our case, we have different image names from the dockerhub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your explanation.
we have different image names from the dockerhub.
This is the important fact I didn't know. Please leave the code comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
I can't find it.
3fb6096
to
46a14fe
Compare
import org.testcontainers.utility.DockerImageName; | ||
import org.testcontainers.utility.ImageNameSubstitutor; | ||
|
||
public class CustomImageNameSubstitutor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class name is misleading. Please rename to CustomTrinoImageNameSubstitutor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the doc I suppose we can only have one ImageNameSubstitutor, then we use TESTCONTAINERS_IMAGE_SUBSTITUTOR=com.mycompany.testcontainers.ExampleImageNameSubstitutor
to tell testcontainer to use this class. Therefore, I think this class should have a generic name as this is the only substitutor that testcontainer will look at.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still disagree with the current name. Even CustomImageNameSubstitutor doesn't explain whether TESTCONTAINERS_IMAGE_SUBSTITUTOR supports single substitutor or several substitutors either.
I don't understand your concern to be honest. There's only one class extending ImageNameSubstitutor in this repository. Who will try setting several substitutors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the class CustomImageNameSubstitutor is used for other images, CustomImageNameSubstitutor
seems right but since this is only applied to trino image, I think it's better off with what ebyhr saids. We can change the name to a more general one if there are other images to substitute in future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still disagree with the current name. Even CustomImageNameSubstitutor doesn't explain whether TESTCONTAINERS_IMAGE_SUBSTITUTOR supports single substitutor or several substitutors either.
I don't understand your concern to be honest. There's only one class extending ImageNameSubstitutor in this repository. Who will try setting several substitutors?
The concern is we can only have one ImageSubstitutor. Naming it to CustomTrinoImageNameSubstitutor
is misleading because it might lead to thinking it's only for substituting Trino image. However, this class should be flexible to substitute other images as well. I agree with @Chaho12's suggestion. We can change the name to be generic later as we need.
46a14fe
to
4f404b6
Compare
We probably want to add how to use this class to the documentation. @mosabua could you suggest a good place for adding this doc? |
Most people won't use this feature. Please leave javadoc in the class. |
@Override | ||
public DockerImageName apply(DockerImageName dockerImageName) | ||
{ | ||
String trinoImage = "trinodb/trino"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to a constant.
@Override | ||
protected String getDescription() | ||
{ | ||
return "custom image name substitutor"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "custom image name substitutor"; | |
return "custom Trino image name substitutor"; |
gateway-ha/src/test/java/io/trino/gateway/CustomTrinoImageNameSubstitutor.java
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/CustomTrinoImageNameSubstitutor.java
Outdated
Show resolved
Hide resolved
249f71d
to
28fb73f
Compare
|
{ | ||
String trinoImageSubstitute = System.getenv(TESTCONTAINERS_TRINO_IMAGE_SUBSTITUTE); | ||
if (dockerImageName.getUnversionedPart().equals(TRINO_IMAGE) && trinoImageSubstitute != null) { | ||
String imageSubstitute = System.getenv(TESTCONTAINERS_TRINO_IMAGE_SUBSTITUTE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant variable. You have it above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change requested
28fb73f
to
8455dd6
Compare
Problem: Some tests download trino docker images from public dockerhub. For example:
trino-gateway/gateway-ha/src/test/java/io/trino/gateway/ha/TestGatewayHaMultipleBackend.java
Line 55 in e2aaa0e
However, this will fail when running behind a proxy. Our in-house images have different names from the names on dockerhub. Therefore, we need a way to override
trinodb/trino
to a completely different name when necessary. This will eventually expand to other public images as they are added to the codebase.