Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docker): add support for querying tags from ECR #4244

Merged
merged 1 commit into from
Aug 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/datasource/docker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ async function getTags(registry, repository) {
if (cachedResult) {
return cachedResult;
}
let url = `${registry}/v2/${repository}/tags/list?n=10000`;
// 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 ecrRegex = /\d+\.dkr\.ecr\.[-a-z0-9]+\.amazonaws\.com/;
const limit = ecrRegex.test(registry) ? 1000 : 10000;
let url = `${registry}/v2/${repository}/tags/list?n=${limit}`;
const headers = await getAuthHeaders(registry, repository);
if (!headers) {
logger.debug('Failed to get authHeaders for getTags lookup');
Expand Down
45 changes: 45 additions & 0 deletions test/datasource/__snapshots__/docker.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,48 @@ Array [
],
]
`;

exports[`api/docker getPkgReleases uses lower tag limit for ECR deps 1`] = `
[MockFunction] {
"calls": Array [
Array [
"https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/",
Object {
"throwHttpErrors": false,
},
],
Array [
"https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/node/tags/list?n=1000",
Object {
"headers": Object {},
"json": true,
},
],
Array [
"https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/",
Object {
"throwHttpErrors": false,
},
],
],
"results": Array [
Object {
"type": "return",
"value": Object {
"headers": Object {},
},
},
Object {
"type": "return",
"value": Object {
"body": Object {},
"headers": Object {},
},
},
Object {
"type": "return",
"value": undefined,
},
],
}
`;
14 changes: 14 additions & 0 deletions test/datasource/docker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ describe('api/docker', () => {
expect(res.releases).toHaveLength(1);
expect(got).toMatchSnapshot();
});
it('uses lower tag limit for ECR deps', async () => {
got.mockReturnValueOnce({ headers: {} });
got.mockReturnValueOnce({ headers: {}, body: {} });
await getPkgReleases({
datasource: 'docker',
depName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
});
// The tag limit parameter `n` needs to be limited to 1000 for ECR
// See https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_DescribeRepositories.html#ECR-DescribeRepositories-request-maxResults
expect(got.mock.calls[1][0]).toEqual(
'https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/node/tags/list?n=1000'
);
expect(got).toMatchSnapshot();
});
it('adds library/ prefix for Docker Hub (implicit)', async () => {
const tags = ['1.0.0'];
got.mockReturnValueOnce({
Expand Down