From 9209fade5ed521f8c88627d9b5c7158b26f7f33d Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Wed, 26 May 2021 12:19:22 +0200 Subject: [PATCH] fix(docker): exclude path from registry (#10144) --- lib/datasource/docker/common.spec.ts | 12 ++++++------ lib/datasource/docker/common.ts | 13 +++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/datasource/docker/common.spec.ts b/lib/datasource/docker/common.spec.ts index ba2f579280..84f0729209 100644 --- a/lib/datasource/docker/common.spec.ts +++ b/lib/datasource/docker/common.spec.ts @@ -43,8 +43,8 @@ describe(getName(), () => { ); expect(res).toMatchInlineSnapshot(` Object { - "dockerRepository": "image", - "registryHost": "https://my.local.registry/prefix", + "dockerRepository": "prefix/image", + "registryHost": "https://my.local.registry", } `); }); @@ -55,8 +55,8 @@ describe(getName(), () => { ); expect(res).toMatchInlineSnapshot(` Object { - "dockerRepository": "image", - "registryHost": "http://my.local.registry/prefix", + "dockerRepository": "prefix/image", + "registryHost": "http://my.local.registry", } `); }); @@ -67,8 +67,8 @@ describe(getName(), () => { ); expect(res).toMatchInlineSnapshot(` Object { - "dockerRepository": "image", - "registryHost": "https://my.local.registry/prefix", + "dockerRepository": "prefix/image", + "registryHost": "https://my.local.registry", } `); }); diff --git a/lib/datasource/docker/common.ts b/lib/datasource/docker/common.ts index 11189b1d1a..14d9d1468e 100644 --- a/lib/datasource/docker/common.ts +++ b/lib/datasource/docker/common.ts @@ -9,7 +9,11 @@ import * as packageCache from '../../util/cache/package'; import * as hostRules from '../../util/host-rules'; import { Http, HttpResponse } from '../../util/http'; import type { OutgoingHttpHeaders } from '../../util/http/types'; -import { ensureTrailingSlash, trimTrailingSlash } from '../../util/url'; +import { + ensureTrailingSlash, + parseUrl, + trimTrailingSlash, +} from '../../util/url'; import { MediaType, RegistryRepository } from './types'; export const id = 'docker'; @@ -165,9 +169,14 @@ export function getRegistryRepository( if (!/^https?:\/\//.test(registryHost)) { registryHost = `https://${registryHost}`; } + let dockerRepository = lookupName.replace(registryEndingWithSlash, ''); + const fullUrl = `${registryHost}/${dockerRepository}`; + const { origin, pathname } = parseUrl(fullUrl); + registryHost = origin; + dockerRepository = pathname.substring(1); return { registryHost, - dockerRepository: lookupName.replace(registryEndingWithSlash, ''), + dockerRepository, }; } } -- GitLab