diff --git a/lib/datasource/docker/__snapshots__/index.spec.ts.snap b/lib/datasource/docker/__snapshots__/index.spec.ts.snap index 40b5985e56af2d05205d4398c2f2c1369a59f17c..e734330d07d56c1d466b86050139dc175c1b449f 100644 --- a/lib/datasource/docker/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/docker/__snapshots__/index.spec.ts.snap @@ -392,7 +392,21 @@ Object { exports[`datasource/docker/index getRegistryRepository supports registryUrls 1`] = ` Object { - "registry": "my.local.registry/prefix", + "registry": "https://my.local.registry/prefix", + "repository": "image", +} +`; + +exports[`datasource/docker/index getRegistryRepository supports http registryUrls 1`] = ` +Object { + "registry": "http://my.local.registry/prefix", + "repository": "image", +} +`; + +exports[`datasource/docker/index getRegistryRepository supports schemeless registryUrls 1`] = ` +Object { + "registry": "https://my.local.registry/prefix", "repository": "image", } `; diff --git a/lib/datasource/docker/index.spec.ts b/lib/datasource/docker/index.spec.ts index cdcb2dd7ad74bd7cd2ae23ebf111e87ae9286c33..f317cdb58e7faa0b6a7b7689766893997183ef60 100644 --- a/lib/datasource/docker/index.spec.ts +++ b/lib/datasource/docker/index.spec.ts @@ -71,6 +71,20 @@ describe(getName(__filename), () => { ); expect(res).toMatchSnapshot(); }); + it('supports http registryUrls', () => { + const res = docker.getRegistryRepository( + 'my.local.registry/prefix/image', + 'http://my.local.registry/prefix' + ); + expect(res).toMatchSnapshot(); + }); + it('supports schemeless registryUrls', () => { + const res = docker.getRegistryRepository( + 'my.local.registry/prefix/image', + 'my.local.registry/prefix' + ); + expect(res).toMatchSnapshot(); + }); }); describe('getDigest', () => { it('returns null if no token', async () => { diff --git a/lib/datasource/docker/index.ts b/lib/datasource/docker/index.ts index 2939ed344e699fb5d875c49fda622f7bb99d2d65..ff9e4f53363c84b2baf801db8a343728dae0e012 100644 --- a/lib/datasource/docker/index.ts +++ b/lib/datasource/docker/index.ts @@ -11,6 +11,7 @@ import { ExternalHostError } from '../../types/errors/external-host-error'; import * as packageCache from '../../util/cache/package'; import * as hostRules from '../../util/host-rules'; import { Http, HttpResponse } from '../../util/http'; +import { ensureTrailingSlash, trimTrailingSlash } from '../../util/url'; import * as dockerVersioning from '../../versioning/docker'; import type { GetReleasesConfig, ReleaseResult } from '../types'; import { Image, ImageList, MediaType } from './types'; @@ -66,9 +67,14 @@ export function getRegistryRepository( registryUrl: string ): RegistryRepository { if (registryUrl !== defaultRegistryUrls[0]) { - const registry = registryUrl.replace('https://', ''); - const registryEndingWithSlash = registry.replace(/\/?$/, '/'); + const registryEndingWithSlash = ensureTrailingSlash( + registryUrl.replace(/^https?:\/\//, '') + ); if (lookupName.startsWith(registryEndingWithSlash)) { + let registry = trimTrailingSlash(registryUrl); + if (!/^https?:\/\//.test(registry)) { + registry = `https://${registry}`; + } return { registry, repository: lookupName.replace(registryEndingWithSlash, ''),