Skip to content

Commit

Permalink
feat: add variable to skip getting labels from docker hub (renovatebo…
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelzoellner authored and bryannaegele committed Jul 8, 2024
1 parent d3ea83a commit 68d7388
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/usage/self-hosted-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ You can set the config file Renovate should read with the `RENOVATE_CONFIG_FILE`

The process that runs Renovate must have the correct permissions to delete the config file.

## `RENOVATE_X_DOCKER_HUB_DISABLE_LABEL_LOOKUP`

If set to any value, Renovate will skip attempting to get release labels (e.g. gitRef, sourceUrl) from manifest annotations for `https://index.docker.io`.

Due to the missing label information like sourceUrl, Renovate will not be able to perform certain actions dependent on these information for the images.

This includes the following:

- Generating changelogs
- Applying package rules dependent on the labels
- Including the sourceUrls in PR bodies

## `RENOVATE_X_DOCKER_HUB_TAGS`

If set to any value, Renovate will use the Docker Hub API (`https://hub.docker.com`) to fetch tags instead of the normal Docker API for images pulled from `https://index.docker.io`.
Expand Down
83 changes: 83 additions & 0 deletions lib/modules/datasource/docker/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2665,5 +2665,88 @@ describe('modules/datasource/docker/index', () => {
},
);
});

it('uses annotations for docker hub', async () => {
httpMock
.scope('https://index.docker.io/v2')
.get('/')
.reply(200)
.get('/renovate/renovate/manifests/37.405.1-full')
.reply(200, {
schemaVersion: 2,
mediaType: 'application/vnd.oci.image.manifest.v1+json',
config: {
digest:
'sha256:a3e34dca3519abb558a58384414cc69b6afbbb80e3992064f3e1c24e069c9168',
mediaType: 'application/vnd.oci.image.config.v1+json',
},
annotations: {
'org.opencontainers.image.source':
'https://github.com/renovatebot/renovate',
'org.opencontainers.image.revision':
'e11f9d9882395deaf5fbbb81b3327cb8c2ef069c',
},
});

expect(
await ds.getLabels(
'https://index.docker.io',
'renovate/renovate',
'37.405.1-full',
),
).toEqual({
'org.opencontainers.image.source':
'https://github.com/renovatebot/renovate',
'org.opencontainers.image.revision':
'e11f9d9882395deaf5fbbb81b3327cb8c2ef069c',
});
});

it('skips docker hub labels', async () => {
process.env.RENOVATE_X_DOCKER_HUB_DISABLE_LABEL_LOOKUP = 'true';

httpMock.scope('https://index.docker.io/v2');

expect(
await ds.getLabels(
'https://index.docker.io',
'renovate/renovate',
'37.405.1-full',
),
).toEqual({});
});

it('does not skip non docker hub registry labels', async () => {
process.env.RENOVATE_X_DOCKER_HUB_DISABLE_LABEL_LOOKUP = 'true';

httpMock
.scope('https://ghcr.io/v2')
.get('/')
.reply(200)
.get('/node/manifests/2-alpine')
.reply(200, {
schemaVersion: 2,
mediaType: 'application/vnd.oci.image.manifest.v1+json',
config: {
digest: 'some-config-digest',
mediaType: 'application/vnd.oci.image.config.v1+json',
},
annotations: {
'org.opencontainers.image.source':
'https://github.com/renovatebot/renovate',
'org.opencontainers.image.revision':
'ab7ddb5e3c5c3b402acd7c3679d4e415f8092dde',
},
});

expect(await ds.getLabels('https://ghcr.io', 'node', '2-alpine')).toEqual(
{
'org.opencontainers.image.source':
'https://github.com/renovatebot/renovate',
'org.opencontainers.image.revision':
'ab7ddb5e3c5c3b402acd7c3679d4e415f8092dde',
},
);
});
});
});
10 changes: 10 additions & 0 deletions lib/modules/datasource/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,16 @@ export class DockerDatasource extends Datasource {
tag: string,
): Promise<Record<string, string> | undefined> {
logger.debug(`getLabels(${registryHost}, ${dockerRepository}, ${tag})`);
// Skip Docker Hub image if RENOVATE_X_DOCKER_HUB_DISABLE_LABEL_LOOKUP is set
if (
process.env.RENOVATE_X_DOCKER_HUB_DISABLE_LABEL_LOOKUP &&
registryHost === 'https://index.docker.io'
) {
logger.debug(
'Docker Hub image - skipping label lookup due to RENOVATE_X_DOCKER_HUB_DISABLE_LABEL_LOOKUP',
);
return {};
}
// Docker Hub library images don't have labels we need
if (
registryHost === 'https://index.docker.io' &&
Expand Down

0 comments on commit 68d7388

Please sign in to comment.