From 34d26700cf32ff7a32cdf93179773b10db75ec0a Mon Sep 17 00:00:00 2001 From: Andreas Hippler Date: Tue, 28 Feb 2023 20:29:28 +0100 Subject: [PATCH] fix: support docker /library retry with abortOnError (#20652) Co-authored-by: Michael Kriese --- lib/modules/datasource/docker/index.spec.ts | 48 +++++++++++---------- lib/modules/datasource/docker/index.ts | 9 ++-- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/lib/modules/datasource/docker/index.spec.ts b/lib/modules/datasource/docker/index.spec.ts index 30b17f3afe7d20..e19389b4bb8f1e 100644 --- a/lib/modules/datasource/docker/index.spec.ts +++ b/lib/modules/datasource/docker/index.spec.ts @@ -1193,28 +1193,32 @@ describe('modules/datasource/docker/index', () => { await expect(getPkgReleases(config)).rejects.toThrow(EXTERNAL_HOST_ERROR); }); - it('jfrog artifactory - retry tags for official images by injecting `/library` after repository and before image', async () => { - const tags = ['18.0.0']; - httpMock - .scope('https://org.jfrog.io/v2') - .get('/virtual-mirror/node/tags/list?n=10000') - .reply(200, '', {}) - .get('/virtual-mirror/node/tags/list?n=10000') - .reply(404, '', { 'x-jfrog-version': 'Artifactory/7.42.2 74202900' }) - .get('/virtual-mirror/library/node/tags/list?n=10000') - .reply(200, '', {}) - .get('/virtual-mirror/library/node/tags/list?n=10000') - .reply(200, { tags }, {}) - .get('/') - .reply(200, '', {}) - .get('/virtual-mirror/node/manifests/18.0.0') - .reply(200, '', {}); - const res = await getPkgReleases({ - datasource: DockerDatasource.id, - depName: 'org.jfrog.io/virtual-mirror/node', - }); - expect(res?.releases).toHaveLength(1); - }); + it.each([[true], [false]])( + 'jfrog artifactory - retry tags for official images by injecting `/library` after repository and before image, abortOnError=%p', + async (abortOnError) => { + hostRules.find.mockReturnValue({ abortOnError }); + const tags = ['18.0.0']; + httpMock + .scope('https://org.jfrog.io/v2') + .get('/virtual-mirror/node/tags/list?n=10000') + .reply(200, '', {}) + .get('/virtual-mirror/node/tags/list?n=10000') + .reply(404, '', { 'x-jfrog-version': 'Artifactory/7.42.2 74202900' }) + .get('/virtual-mirror/library/node/tags/list?n=10000') + .reply(200, '', {}) + .get('/virtual-mirror/library/node/tags/list?n=10000') + .reply(200, { tags }, {}) + .get('/') + .reply(200, '', {}) + .get('/virtual-mirror/node/manifests/18.0.0') + .reply(200, '', {}); + const res = await getPkgReleases({ + datasource: DockerDatasource.id, + depName: 'org.jfrog.io/virtual-mirror/node', + }); + expect(res?.releases).toHaveLength(1); + } + ); it('uses lower tag limit for ECR deps', async () => { httpMock diff --git a/lib/modules/datasource/docker/index.ts b/lib/modules/datasource/docker/index.ts index 4e8127e60426ae..83bcd6dabfb865 100644 --- a/lib/modules/datasource/docker/index.ts +++ b/lib/modules/datasource/docker/index.ts @@ -909,10 +909,9 @@ export class DockerDatasource extends Datasource { tags = await this.getDockerApiTags(registryHost, dockerRepository); } return tags; - } catch (err) /* istanbul ignore next */ { - if (err instanceof ExternalHostError) { - throw err; - } + } catch (_err) /* istanbul ignore next */ { + const err = _err instanceof ExternalHostError ? _err.err : _err; + if ( (err.statusCode === 404 || err.message === PAGE_NOT_FOUND_ERROR) && !dockerRepository.includes('/') @@ -974,7 +973,7 @@ export class DockerDatasource extends Datasource { if (isDockerHost(registryHost)) { logger.info({ err }, 'Docker Hub lookup failure'); } - throw err; + throw _err; } }