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

feat: add variable to skip getting labels from docker hub #29624

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions docs/usage/self-hosted-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ 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_DISABLE_DOCKER_HUB_LABELS`
rarkins marked this conversation as resolved.
Show resolved Hide resolved

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`.
viceice marked this conversation as resolved.
Show resolved Hide resolved

## `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_DISABLE_DOCKER_HUB_LABELS = '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_DISABLE_DOCKER_HUB_LABELS = '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_DISABLE_DOCKER_HUB_LABELS is set
if (
process.env.RENOVATE_X_DISABLE_DOCKER_HUB_LABELS &&
registryHost === 'https://index.docker.io'
) {
logger.debug(
'Docker Hub image - skipping label lookup due to RENOVATE_X_DISABLE_DOCKER_HUB_LABELS',
);
return {};
}
// Docker Hub library images don't have labels we need
if (
registryHost === 'https://index.docker.io' &&
Expand Down