Support SHA256 digest lookup in local image cache#11585
Support SHA256 digest lookup in local image cache#11585konstantinosGkilas wants to merge 3 commits intotestcontainers:mainfrom
Conversation
Index images by their repoDigests in addition to repoTags when populating LocalImagesCache so that digest-based image references (e.g. alpine@sha256:...) resolve from cache without requiring an extra inspectImageCmd call. Closes testcontainers#1406
yunhwane
left a comment
There was a problem hiding this comment.
Nice work on this! The repoDigests support looks solid and clean.
One thing I noticed — the original issue (#1406) also mentions supporting bare Image IDs (edited by @rnorth on 5 June 2020):
EDIT 5 June 2020: We should also ensure that Image IDs are loaded into the cache - see #699.
The use case is when users reference images by their ID (e.g. from docker build --iidfile):
new GenericContainer<>("sha256:8cf620617c6203b24af7c5bf15a7212386c27ad008fc4c6ff7e37a1bf0a3cdd2")Currently DockerImageName parses this as repository="sha256", tag="8cf620617c...", which produces a canonical name of sha256:8cf620617c... — so it would match correctly if indexed.
Adding something like this to populateFromList() would cover it:
String id = image.getId();
if (id != null) {
cache.put(new DockerImageName(id), imageData);
}Would you be open to adding Image ID indexing as well? That way this PR fully addresses both #1406 and #699.
Yes I would implement the needed changes in order to resolve both issues. |
|
@yunhwane Could I have an update on the new changes, that I have introduced? |
|
Hi, I think you may have tagged the wrong person — I'm not a maintainer or reviewer on this project. I was working on the same issue and noticed our work overlapped. The changes look nice though, good luck with the PR! |
Good to know, for some strange reason GitHub has assigned you as a reviewer of the PR |
Summary
repoDigestsin addition torepoTagswhen populatingLocalImagesCachealpine@sha256:...) now resolve from cache without requiring an extrainspectImageCmdcallProblem
LocalImagesCache.populateFromList()only indexed images byrepoTags. When users referenced images by SHA256 digest, the cache lookup missed, forcing a redundantinspectImageCmdcall on every run.Changes
LocalImagesCache.java:populateFromList()now processes bothimage.getRepoTags()andimage.getRepoDigests(), adding cache entries for eachLocalImagesCacheTest.java: New test class covering tag-only, digest-only, mixed, duplicate, and null scenariosNote
Bare image IDs (
sha256:...without a repository prefix) are not indexed becauseDockerImageNamedoes not support that format. This could be addressed separately if needed.Test plan
LocalImagesCacheTest— 7 unit tests covering all cache population pathscheckstyleMain/checkstyleTest/spotlessCheckpassCloses #1406