From b7e267f6ac078cab0530c3e8f71527a2b48c044c Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Fri, 11 Feb 2022 05:59:29 +0100 Subject: [PATCH] feat(datasource/docker): support legacy `org.label-schema.vcs-url` label (#14139) --- lib/datasource/docker/common.ts | 4 ++++ lib/datasource/docker/index.ts | 23 ++++++++++++++++------- lib/datasource/docker/readme.md | 4 ++-- 3 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 lib/datasource/docker/common.ts diff --git a/lib/datasource/docker/common.ts b/lib/datasource/docker/common.ts new file mode 100644 index 0000000000..ca1cf0ec1d --- /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 5cc024bbc3..cce8d732ab 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 fac24ca307..3a2a29ba98 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. -- GitLab