Add lscr.io support to Docker update checker
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2026-05-16 17:28:06 +02:00
parent fdf616d5e8
commit 2a7801f430
2 changed files with 23 additions and 9 deletions
+20 -7
View File
@@ -86,25 +86,26 @@ async function getLatestDigest(image: string, tag: string): Promise<string | nul
} catch { return null }
}
async function getGhcrLatestDigest(image: string, tag: string): Promise<string | null> {
const cacheKey = `ghcr:${image}:${tag}`
async function getGenericRegistryDigest(
registry: string, image: string, tag: string, bearerToken?: string
): Promise<string | null> {
const cacheKey = `${registry}:${image}:${tag}`
const cached = fromCache<string>(cacheKey, HUB_TTL)
if (cached) return cached
try {
const ghToken = process.env.GITHUB_TOKEN
const authHeaders: Record<string, string> = ghToken
? { Authorization: `Bearer ${ghToken}` }
const authHeaders: Record<string, string> = bearerToken
? { Authorization: `Bearer ${bearerToken}` }
: {}
const tokenRes = await axios.get(
`https://ghcr.io/token?service=ghcr.io&scope=repository:${image}:pull`,
`https://${registry}/token?service=${registry}&scope=repository:${image}:pull`,
{ headers: authHeaders, timeout: 8000 }
)
const token = tokenRes.data.token as string
const res = await axios.head(
`https://ghcr.io/v2/${image}/manifests/${tag}`,
`https://${registry}/v2/${image}/manifests/${tag}`,
{ headers: { Authorization: `Bearer ${token}`, Accept: MANIFEST_ACCEPT }, timeout: 10000 }
)
const digest = res.headers['docker-content-digest'] as string | undefined
@@ -113,6 +114,14 @@ async function getGhcrLatestDigest(image: string, tag: string): Promise<string |
} catch { return null }
}
async function getGhcrLatestDigest(image: string, tag: string): Promise<string | null> {
return getGenericRegistryDigest('ghcr.io', image, tag, process.env.GITHUB_TOKEN)
}
async function getLscrLatestDigest(image: string, tag: string): Promise<string | null> {
return getGenericRegistryDigest('lscr.io', image, tag)
}
router.get('/docker', async (_req, res) => {
const host = process.env.PORTAINER_HOST
if (!host) {
@@ -168,6 +177,7 @@ router.get('/docker', async (_req, res) => {
const { registry, name, tag } = parseImage(rawImage)
const isDockerHub = registry === 'docker.io'
const isGhcr = registry === 'ghcr.io'
const isLscr = registry === 'lscr.io'
let upToDate: boolean | null = null
if (isDockerHub && repoDigest) {
@@ -176,6 +186,9 @@ router.get('/docker', async (_req, res) => {
} else if (isGhcr && repoDigest) {
const latest = await getGhcrLatestDigest(name, tag)
if (latest) upToDate = latest === repoDigest
} else if (isLscr && repoDigest) {
const latest = await getLscrLatestDigest(name, tag)
if (latest) upToDate = latest === repoDigest
}
containers.push({