-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Accept image names with library/
prefix as a valid substitute
#6174
Conversation
Docker official images can be pulled with or without `library/` prefix as part of the image name. For example, `mysql` or `library/mysql`. This is explicit when using private repositories.
modules/neo4j/src/test/java/org/testcontainers/containers/Neo4jContainerTest.java
Outdated
Show resolved
Hide resolved
@eddumelendez have you considered having it in |
Thanks a lot for providing the context here in the PR @eddumelendez and thanks to @bsideup for more ideas. My preferred way initially was to combine both changes (either within this PR, or 2 distinct PRs):
Reflecting on this, I see no drawback with doing 1), especially since it is a very local change. Regarding 2) I am now unsure. What binds is more strongly to Docker implementation details and is more prone to breaking, using |
I am not sure about this one. This indeed exposes Docker's internal impl and, should they change it, we might be in trouble. I see no reason to touch how we define the images ( |
@bsideup Yes makes sense, we will proceed with 1) only. |
I think the implementation becomes much more straightforward if moved to public boolean isCompatibleWith(DockerImageName other) {
// is this image already the same or equivalent?
- if (other.equals(this)) {
+ DockerImageName imageWithLibraryPrefix = DockerImageName.parse("library/" + other.repository);
+ if (other.equals(this) || imageWithLibraryPrefix.equals(this)) {
return true;
}
[...]
} |
finalImageName = LIBRARY_PREFIX + this.repository; | ||
} | ||
DockerImageName imageWithLibraryPrefix = DockerImageName.parse(finalImageName); | ||
if (other.equals(this) || imageWithLibraryPrefix.equals(this)) { |
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.
(Minor) More cleaner
if (Objects.equals(other, this) || Objects.equals(imageWithLibraryPrefix, this)) {
....
}
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 don't think this changes the degree of "cleanness", but a question of taste (beside the null-safety of Objects.equals()
in general). Either style should be fine in this case.
core/src/test/java/org/testcontainers/utility/DockerImageNameCompatibilityTest.java
Show resolved
Hide resolved
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.
LGTM, I much prefer the implementation in isCompatibleWith()
👍
See the open comment, I think we can merge once adressed.
finalImageName = LIBRARY_PREFIX + this.repository; | ||
} | ||
DockerImageName imageWithLibraryPrefix = DockerImageName.parse(finalImageName); | ||
if (other.equals(this) || imageWithLibraryPrefix.equals(this)) { |
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 don't think this changes the degree of "cleanness", but a question of taste (beside the null-safety of Objects.equals()
in general). Either style should be fine in this case.
@@ -232,7 +234,14 @@ public DockerImageName asCompatibleSubstituteFor(DockerImageName otherImageName) | |||
*/ | |||
public boolean isCompatibleWith(DockerImageName other) { | |||
// is this image already the same or equivalent? |
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 comment makes no more sense here like this. Instead, we can add a comment saying:
// Make sure we always compare against a version of the image name containing the LIBRARY_PREFIX
Co-authored-by: Kevin Wittek <[email protected]>
Docker official images can be pulled with or without
library/
prefix as part of the image name. For example,
mysql
orlibrary/mysql
. This is explicit when using private repositories.Container classes such as
CassandraContainer
, for example, italready considers as a valid substitution
cassandra
.This change, by default adds a new substitution with
library/
prefix.