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

Fix "latest" tag fallback #242

Merged
merged 1 commit into from
Aug 4, 2021
Merged

Fix "latest" tag fallback #242

merged 1 commit into from
Aug 4, 2021

Conversation

josecanhelp
Copy link
Contributor

Docker Hub paginates the tag list page and in order to pull the full list of tags, we would need to authenticate, which I've been trying to avoid for complexity sake. Luckily, we can expand the page_size parameter and bump it up to read more tags without needing to authenticate.

The next step to my solution is to partition the named tags and the numerical tags. We can rely on the higher numerical tags to be the "actual latest" tags and we can ignore the named tags when takeout is searching for "actual latest".

Copy link
Member

@mattstauffer mattstauffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What wonderful code. Whoever you work for is so freaking lucky ;) OH WAIT THAT IS YOU

}

public function getTags(): Collection
{
$response = json_decode($this->getTagsResponse()->getContents(), true);

return collect($response['results'])
[$numericTags, $alphaTags] = collect($response['results'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So clean!

return is_numeric($tag[0]);
});

$sortedTags = $alphaTags->sortDesc(SORT_NATURAL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also so clean!

Comment on lines +56 to +59
if ($sortedTags->contains('latest')) {
$sortedTags->splice($sortedTags->search('latest'), 1);
$sortedTags->prepend('latest');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DAMN this is so clean.

@@ -69,6 +79,6 @@ protected function buildTagsUrl(): string

protected function tagsUrlTemplate(): string
{
return 'https://registry.hub.docker.com/v2/repositories/%s/%s/tags';
return 'https://registry.hub.docker.com/v2/repositories/%s/%s/tags?page_size=1024';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha that was an easy way to do it!

@mattstauffer mattstauffer merged commit df233bd into main Aug 4, 2021
@mattstauffer mattstauffer deleted the jas/full-tag-list branch August 4, 2021 19:26
@mattstauffer
Copy link
Member

Thank you so much @josecanhelp!

@jonsugar
Copy link

jonsugar commented Aug 5, 2021

What wonderful code. Whoever you work for is so freaking lucky ;) OH WAIT THAT IS YOU

@mattstauffer looks like you're only option is for Tighten to purchase Troika and reabsorb @josecanhelp 🤡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants