feat(docker): add image variant handler (#439)

pull/441/head
lhalbert 2020-10-19 00:32:18 -04:00 zatwierdzone przez GitHub
rodzic fcfba29746
commit 960a180a10
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 17 dodań i 3 usunięć

Wyświetl plik

@ -11,10 +11,11 @@ export default createBadgenHandler({
'/docker/pulls/amio/node-chrome': 'pulls (scoped)',
'/docker/stars/library/mongo?icon=docker&label=stars': 'stars (icon & label)',
'/docker/size/lukechilds/bitcoind/latest/amd64': 'size (scoped/tag/architecture)',
'/docker/size/lucashalbert/curl/latest/arm/v6': 'size (scoped/tag/architecture/variant)',
},
handlers: {
'/docker/:topic<stars|pulls>/:scope/:name': starPullHandler,
'/docker/size/:scope/:name/:tag?/:architecture?': sizeHandler
'/docker/size/:scope/:name/:tag?/:architecture?/:variant?': sizeHandler
}
})
@ -47,9 +48,10 @@ async function starPullHandler ({ topic, scope, name }: PathArgs) {
}
}
async function sizeHandler ({ scope, name, tag, architecture }: PathArgs) {
async function sizeHandler ({ scope, name, tag, architecture, variant }: PathArgs) {
tag = tag ? tag : 'latest'
architecture = architecture ? architecture : 'amd64'
variant = variant ? variant : ''
/* eslint-disable camelcase */
const endpoint = `https://hub.docker.com/v2/repositories/${scope}/${name}/tags`
let body = await got(endpoint).json<any>()
@ -70,7 +72,7 @@ async function sizeHandler ({ scope, name, tag, architecture }: PathArgs) {
}
}
const imageData = tagData.images.find(image => image.architecture === architecture)
let imageData = tagData.images.find(image => image.architecture === architecture)
if (!imageData) {
return {
@ -80,6 +82,18 @@ async function sizeHandler ({ scope, name, tag, architecture }: PathArgs) {
}
}
if (variant) {
imageData = tagData.images.filter(image => image.architecture === architecture).find(image => image.variant === variant)
if (!imageData) {
return {
subject: 'docker',
status: 'unknown variant',
color: 'grey'
}
}
}
const sizeInMegabytes = (imageData.size / 1024 / 1024).toFixed(2)
return {