Skip to content

Commit

Permalink
fix: support docker /library retry with abortOnError (#20652)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
ahippler and viceice authored Feb 28, 2023
1 parent e579663 commit 34d2670
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
48 changes: 26 additions & 22 deletions lib/modules/datasource/docker/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions lib/modules/datasource/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')
Expand Down Expand Up @@ -974,7 +973,7 @@ export class DockerDatasource extends Datasource {
if (isDockerHost(registryHost)) {
logger.info({ err }, 'Docker Hub lookup failure');
}
throw err;
throw _err;
}
}

Expand Down

0 comments on commit 34d2670

Please sign in to comment.