Skip to content

Commit

Permalink
feat(docker): Use cache for "/dockerRegistry/images/tags" instead of …
Browse files Browse the repository at this point in the history
…requesting docker registry every time (#3809)

This commit changes "/dockerRegistry/images/tags" endpoint to use cache made by caching agent, it provides better performance especially the image has a lot of tags. In order for sorting tags ("sortTagsByDate" option), this commit adds new "date" attribute in the taggedImage cache.
  • Loading branch information
dragon3 authored and asher committed Jul 1, 2019
1 parent a0f7b18 commit ba2b640
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,24 @@ class DockerRegistryImageLookupController {
@RequestMapping(value = "/tags", method = RequestMethod.GET)
List<String> getTags(@RequestParam('account') String account, @RequestParam('repository') String repository) {
def credentials = (DockerRegistryNamedAccountCredentials) accountCredentialsProvider.getCredentials(account)
credentials?.getTags(repository)
if (!credentials) {
return []
}

return DockerRegistryProviderUtils.getAllMatchingKeyPattern(
cacheView,
Keys.Namespace.TAGGED_IMAGE.ns,
Keys.getTaggedImageKey(account, repository, "*")
).sort { a, b ->
if (credentials.sortTagsByDate) {
b.attributes.date <=> a.attributes.date
} else {
a.id <=> b.id
}
}.collect {
def parse = Keys.parse(it.id)
return (String) parse.tag
}
}

@RequestMapping(value = '/find', method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class DockerRegistryImageCachingAgent implements CachingAgent, AccountAware, Age
def tagKey = Keys.getTaggedImageKey(accountName, repository, tag)
def imageIdKey = Keys.getImageIdKey(DockerRegistryProviderUtils.imageId(registry, repository, tag))
def digest = null
def creationDate = null

if (credentials.trackDigests) {
try {
Expand All @@ -157,11 +158,17 @@ class DockerRegistryImageCachingAgent implements CachingAgent, AccountAware, Age
}
}
}
try {
creationDate = credentials.client.getCreationDate(repository, tag)
} catch (Exception e) {
log.warn("Unable to fetch tag creation date, reason: {} (tag: {}, repository: {})", e.message, tag, repository)
}

cachedTags[tagKey].with {
attributes.name = "${repository}:${tag}".toString()
attributes.account = accountName
attributes.digest = digest
attributes.date = creationDate
}

cachedIds[imageIdKey].with {
Expand Down

0 comments on commit ba2b640

Please sign in to comment.