Skip to content

Commit

Permalink
fix(docker): reduce ECR Public max results to 1000 (#17946)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunet committed Sep 27, 2022
1 parent c8c0fad commit e29d851
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
52 changes: 52 additions & 0 deletions lib/modules/datasource/docker/index.spec.ts
Expand Up @@ -1194,6 +1194,58 @@ describe('modules/datasource/docker/index', () => {
});
});

it('uses lower tag limit for ECR Public deps', async () => {
httpMock
.scope('https://public.ecr.aws')
.get('/v2/amazonlinux/amazonlinux/tags/list?n=1000')
.reply(401, '', {
'www-authenticate':
'Bearer realm="https://public.ecr.aws/token",service="public.ecr.aws",scope="aws"',
})
.get('/token?service=public.ecr.aws&scope=aws')
.reply(200, { token: 'test' });
httpMock
.scope('https://public.ecr.aws', {
reqheaders: {
authorization: 'Bearer test',
},
})
// The tag limit parameter `n` needs to be limited to 1000 for ECR Public
// See https://docs.aws.amazon.com/AmazonECRPublic/latest/APIReference/API_DescribeRepositories.html#ecrpublic-DescribeRepositories-request-maxResults
.get('/v2/amazonlinux/amazonlinux/tags/list?n=1000')
.reply(200, { tags: ['some'] }, {});

httpMock
.scope('https://public.ecr.aws')
.get('/v2/')
.reply(401, '', {
'www-authenticate':
'Bearer realm="https://public.ecr.aws/token",service="public.ecr.aws",scope="aws"',
})
.get(
'/token?service=public.ecr.aws&scope=repository:amazonlinux/amazonlinux:pull'
)
.reply(200, { token: 'test' });
httpMock
.scope('https://public.ecr.aws', {
reqheaders: {
authorization: 'Bearer test',
},
})
.get('/v2/amazonlinux/amazonlinux/manifests/some')
.reply(200);

expect(
await getPkgReleases({
datasource: DockerDatasource.id,
depName: 'public.ecr.aws/amazonlinux/amazonlinux',
})
).toEqual({
registryUrl: 'https://public.ecr.aws',
releases: [],
});
});

describe('when making requests that interact with an ECR proxy', () => {
it('resolves requests to ECR proxy', async () => {
httpMock
Expand Down
7 changes: 6 additions & 1 deletion lib/modules/datasource/docker/index.ts
Expand Up @@ -49,6 +49,7 @@ import {
export const DOCKER_HUB = 'https://index.docker.io';

export const ecrRegex = regEx(/\d+\.dkr\.ecr\.([-a-z0-9]+)\.amazonaws\.com/);
export const ecrPublicRegex = regEx(/public\.ecr\.aws/);

function isDockerHost(host: string): boolean {
const regex = regEx(/(?:^|\.)docker\.io$/);
Expand Down Expand Up @@ -818,7 +819,11 @@ export class DockerDatasource extends Datasource {
let tags: string[] = [];
// AWS ECR limits the maximum number of results to 1000
// See https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_DescribeRepositories.html#ECR-DescribeRepositories-request-maxResults
const limit = ecrRegex.test(registryHost) ? 1000 : 10000;
// See https://docs.aws.amazon.com/AmazonECRPublic/latest/APIReference/API_DescribeRepositories.html#ecrpublic-DescribeRepositories-request-maxResults
const limit =
ecrRegex.test(registryHost) || ecrPublicRegex.test(registryHost)
? 1000
: 10000;
let url:
| string
| null = `${registryHost}/${dockerRepository}/tags/list?n=${limit}`;
Expand Down

0 comments on commit e29d851

Please sign in to comment.