Skip to content

Commit dbc2759

Browse files
committed
fix(requests): retrieve more tags when requesting them from the registry
Now it first tries to request the tags using the v1 API, which returns all entries. v2 is still present as a fallback, for which the page size is increased from undefined (defaults to 10) to 10000. This will be capped at the server side to 100 by Docker Hub.
1 parent a29382d commit dbc2759

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/requests/getTags.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,37 @@ const getTags: (opts: { repository: string; https: boolean; host: string }) => P
99
https,
1010
host,
1111
}) => {
12+
// Prefer the v1 API over v2, as it will return all tags on the first request
1213
try {
13-
const result = await request({ https, host, path: `/v2/repositories/${repository}/tags/` })
14+
const result = await request({ https, host, path: `/v1/repositories/${repository}/tags` })
15+
const tags = result.data?.map(({ name }: { name: string }) => ({ name }))
16+
17+
if (tags?.length > 0) {
18+
return tags
19+
}
20+
} catch (error) {
21+
console.error(error)
22+
}
23+
24+
console.log('Failed retrieving tags using the v1 API, falling back to v2')
25+
26+
try {
27+
// @todo Add pagination to properly iterate through all tags
28+
const result = await request({
29+
https,
30+
host,
31+
path: `/v2/repositories/${repository}/tags/?page_size=10000`,
32+
})
1433
const tags = result.data?.results?.map(({ name }: { name: string }) => ({ name }))
1534

16-
return tags ?? []
35+
if (tags?.length > 0) {
36+
return tags
37+
}
1738
} catch (error) {
1839
console.error(error)
19-
return []
2040
}
41+
42+
return []
2143
}
2244

2345
export default getTags

0 commit comments

Comments
 (0)