diff --git a/lib/datasource/docker.js b/lib/datasource/docker.js index 9993a75c52a88894aa204a86c9e49ae019570cd8..3ea57311d792e5d49e164e0fe4be2cded181bba1 100644 --- a/lib/datasource/docker.js +++ b/lib/datasource/docker.js @@ -1,6 +1,7 @@ const dockerRegistryClient = require('docker-registry-client'); const got = require('got'); const URL = require('url'); +const is = require('@sindresorhus/is'); const parseLinkHeader = require('parse-link-header'); const wwwAuthenticate = require('www-authenticate'); const { isVersion, sortVersions } = require('../versioning/docker'); @@ -11,8 +12,11 @@ module.exports = { getPkgReleases, }; -function massageRegistry(input) { +function massageRegistry(config, input) { let registry = input; + if (!registry && !is.empty(config.registryUrls)) { + [registry] = config.registryUrls; + } if (!registry || registry === 'docker.io') { registry = 'index.docker.io'; // eslint-disable-line no-param-reassign } @@ -101,7 +105,7 @@ function extractDigestFromResponse(manifestResponse) { async function getDigest(config, newValue) { const { dockerRegistry, depName, tagSuffix } = config; logger.debug(`getDigest(${dockerRegistry}, ${depName}, ${newValue})`); - const massagedRegistry = massageRegistry(dockerRegistry); + const massagedRegistry = massageRegistry(config, dockerRegistry); const repository = getRepository(depName, dockerRegistry); let newTag = newValue; if (tagSuffix) { @@ -260,11 +264,11 @@ async function getTags(registry, repository) { } } -async function getPkgReleases(purl) { +async function getPkgReleases(purl, config = {}) { const { fullname, qualifiers } = purl; const { registry, suffix } = qualifiers; logger.debug({ fullname, registry, suffix }, 'docker.getDependencies()'); - const massagedRegistry = massageRegistry(registry); + const massagedRegistry = massageRegistry(config, registry); const repository = getRepository(fullname, registry); const tags = await getTags(massagedRegistry, repository); if (!tags) { diff --git a/test/datasource/__snapshots__/docker.spec.js.snap b/test/datasource/__snapshots__/docker.spec.js.snap index 9fbe83df5fe433c7c8084bb9419d0665a577cce9..83117c9278ac8cd624dcb64a30dd065d03fee598 100644 --- a/test/datasource/__snapshots__/docker.spec.js.snap +++ b/test/datasource/__snapshots__/docker.spec.js.snap @@ -217,3 +217,43 @@ Object { ], } `; + +exports[`api/docker getPkgReleases uses custom registry 1`] = ` +[MockFunction] { + "calls": Array [ + Array [ + "https://https://registry.company.com/v2/", + Object { + "throwHttpErrors": false, + }, + ], + Array [ + "https://https://registry.company.com/v2/library/node/tags/list?n=10000", + Object { + "headers": Object {}, + "json": true, + "timeout": 10000, + }, + ], + ], + "results": Array [ + Object { + "isThrow": false, + "value": Object { + "headers": Object {}, + }, + }, + Object { + "isThrow": false, + "value": Object { + "body": Object { + "tags": Array [ + "1.0.0", + ], + }, + "headers": Object {}, + }, + }, + ], +} +`; diff --git a/test/datasource/docker.spec.js b/test/datasource/docker.spec.js index 4dea4ad03fcb31680a87856148f5d53fed866dee..f283d23740a193d70cdc28d7ef9d484a82bfa5af 100644 --- a/test/datasource/docker.spec.js +++ b/test/datasource/docker.spec.js @@ -210,6 +210,25 @@ describe('api/docker', () => { }); expect(res2.releases).toHaveLength(1); }); + it('uses custom registry', async () => { + const tags = ['1.0.0']; + got.mockReturnValueOnce({ + headers: {}, + }); + got.mockReturnValueOnce({ headers: {}, body: { tags } }); + const config = { + registryUrls: ['https://registry.company.com'], + }; + const res = await docker.getPkgReleases( + { + fullname: 'node', + qualifiers: {}, + }, + config + ); + expect(res.releases).toHaveLength(1); + expect(got).toMatchSnapshot(); + }); it('adds library/ prefix for Docker Hub (implicit)', async () => { const tags = ['1.0.0']; got.mockReturnValueOnce({