Skip to content

Commit

Permalink
feat(datasource/docker): allow override max pages (experimental /self…
Browse files Browse the repository at this point in the history
…-hosted) (#23700)
  • Loading branch information
viceice committed Aug 4, 2023
1 parent 7949a2a commit 2daf10e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/usage/self-hosted-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ If set to "false" (string), Renovate will remove any existing `package-lock.json

If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests.

## `RENOVATE_X_DOCKER_MAX_PAGES`

If set to an integer, Renovate will use this as max page number for docker tags lookup on docker registries, instead of the default 20 pages.
This is useful for registries which ignores the `n` parameter in the query string and only return 50 tags per page.

## `RENOVATE_X_HARD_EXIT`

If set to any value, Renovate will use a "hard" `process.exit()` once all work is done, even if a sub-process is otherwise delaying Node.js from exiting.
Expand Down
36 changes: 36 additions & 0 deletions lib/modules/datasource/docker/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('modules/datasource/docker/index', () => {
password: 'some-password',
});
hostRules.hosts.mockReturnValue([]);
delete process.env.RENOVATE_X_DOCKER_MAX_PAGES;
});

describe('getDigest', () => {
Expand Down Expand Up @@ -1039,6 +1040,41 @@ describe('modules/datasource/docker/index', () => {
expect(res?.releases).toHaveLength(1);
});

it('uses custom max pages', async () => {
process.env.RENOVATE_X_DOCKER_MAX_PAGES = '2';
httpMock
.scope(baseUrl)
.get('/library/node/tags/list?n=10000')
.reply(200, '', {})
.get('/library/node/tags/list?n=10000')
.reply(
200,
{ tags: ['1.0.0'] },
{
link: `<${baseUrl}/library/node/tags/list?n=1&page=1>; rel="next", `,
}
)
.get('/library/node/tags/list?n=1&page=1')
.reply(
200,
{ tags: ['1.0.1'] },
{
link: `<${baseUrl}/library/node/tags/list?n=1&page=2>; rel="next", `,
}
)
.get('/')
.reply(200)
.get('/library/node/manifests/1.0.1')
.reply(200);

const config = {
datasource: DockerDatasource.id,
packageName: 'node',
};
const res = await getPkgReleases(config);
expect(res?.releases).toHaveLength(2);
});

it('uses custom registry in packageName', async () => {
const tags = ['1.0.0'];
httpMock
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/datasource/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ export class DockerDatasource extends Datasource {
return null;
}
let page = 0;
const pages = process.env.RENOVATE_X_DOCKER_MAX_PAGES
? parseInt(process.env.RENOVATE_X_DOCKER_MAX_PAGES, 10)
: 20;
let foundMaxResultsError = false;
do {
let res: HttpResponse<{ tags: string[] }>;
Expand Down Expand Up @@ -594,7 +597,7 @@ export class DockerDatasource extends Datasource {
url = linkHeader?.next ? new URL(linkHeader.next.url, url).href : null;
}
page += 1;
} while (url && page < 20);
} while (url && page < pages);
return tags;
}

Expand Down

0 comments on commit 2daf10e

Please sign in to comment.