diff --git a/lib/datasource/docker/common.ts b/lib/datasource/docker/common.ts new file mode 100644 index 0000000000000000000000000000000000000000..ca1cf0ec1d13c1f35032e7594b72eda712ec528a --- /dev/null +++ b/lib/datasource/docker/common.ts @@ -0,0 +1,4 @@ +export const sourceLabels: string[] = [ + 'org.opencontainers.image.source', + 'org.label-schema.vcs-url', +]; diff --git a/lib/datasource/docker/index.ts b/lib/datasource/docker/index.ts index 5cc024bbc3404b3de803ced1ffe320c5486c6bc7..cce8d732ab38437ef7f49f7592e2e5b553d176cd 100644 --- a/lib/datasource/docker/index.ts +++ b/lib/datasource/docker/index.ts @@ -27,7 +27,8 @@ import { id as dockerVersioningId, } from '../../versioning/docker'; import type { GetReleasesConfig, ReleaseResult } from '../types'; -import { MediaType, RegistryRepository } from './types'; +import { sourceLabels } from './common'; +import { Image, ImageList, MediaType, RegistryRepository } from './types'; export const ecrRegex = regEx(/\d+\.dkr\.ecr\.([-a-z0-9]+)\.amazonaws\.com/); @@ -384,7 +385,7 @@ async function getConfigDigest( if (!manifestResponse) { return null; } - const manifest = JSON.parse(manifestResponse.body); + const manifest = JSON.parse(manifestResponse.body) as ImageList | Image; if (manifest.schemaVersion !== 2) { logger.debug( { registry, dockerRepository, tag }, @@ -408,8 +409,11 @@ async function getConfigDigest( ); } - if (manifest.mediaType === MediaType.manifestV2) { - return manifest.config?.digest || null; + if ( + manifest.mediaType === MediaType.manifestV2 && + is.string(manifest.config?.digest) + ) { + return manifest.config?.digest; } logger.debug({ manifest }, 'Invalid manifest - returning'); @@ -609,7 +613,7 @@ async function getDockerApiTags( let page = 1; let foundMaxResultsError = false; do { - let res; + let res: HttpResponse<{ tags: string[] }>; try { res = await http.getJson<{ tags: string[] }>(url, { headers, @@ -814,8 +818,13 @@ export async function getReleases({ const latestTag = tags.includes('latest') ? 'latest' : findLatestStable(tags); const labels = await getLabels(registryHost, dockerRepository, latestTag); - if (labels && 'org.opencontainers.image.source' in labels) { - ret.sourceUrl = labels['org.opencontainers.image.source']; + if (labels) { + for (const label of sourceLabels) { + if (is.nonEmptyString(labels[label])) { + ret.sourceUrl = labels[label]; + break; + } + } } return ret; } diff --git a/lib/datasource/docker/readme.md b/lib/datasource/docker/readme.md index fac24ca3072660b36c1cd1b572ca2bf7ecc910ca..3a2a29ba984e4580d68d6ac770243690d8ae2ab5 100644 --- a/lib/datasource/docker/readme.md +++ b/lib/datasource/docker/readme.md @@ -1,5 +1,5 @@ This datasource identifies an image's source repository according to the [pre-defined annotation keys of the OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/main/annotations.md). -This datasource looks for the metadata of the **latest stable** image found on the Docker registry and uses the value of the label `org.opencontainers.image.source` as the `sourceUrl`. +This datasource looks for the metadata of the **latest stable** image found on the Docker registry and uses the value of the label `org.opencontainers.image.source` and `org.label-schema.vcs-url` as the `sourceUrl`. -The [Label Schema](https://label-schema.org/) is superseded by OCI annotations, therefore this datasource does not support the `org.label-schema.vcs-url` label. +The [Label Schema](https://label-schema.org/) is superseded by OCI annotations, therefore `org.opencontainers.image.source` label should be preferred.