Skip to content

Commit

Permalink
fix(datasource/docker): fix getDigest when lookupName different from …
Browse files Browse the repository at this point in the history
…packageName (#27665)
  • Loading branch information
rarkins committed Mar 1, 2024
1 parent 3bd92fa commit 42081a3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/modules/datasource/docker/index.spec.ts
Expand Up @@ -1457,6 +1457,7 @@ describe('modules/datasource/docker/index', () => {
packageName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
}),
).toEqual({
lookupName: 'node',
registryUrl: 'https://123456789.dkr.ecr.us-east-1.amazonaws.com',
releases: [],
});
Expand Down Expand Up @@ -1509,6 +1510,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'public.ecr.aws/amazonlinux/amazonlinux',
}),
).toEqual({
lookupName: 'amazonlinux/amazonlinux',
registryUrl: 'https://public.ecr.aws',
releases: [],
});
Expand Down Expand Up @@ -1567,6 +1569,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'ecr-proxy.company.com/node',
}),
).toEqual({
lookupName: 'node',
registryUrl: 'https://ecr-proxy.company.com',
releases: [],
sourceUrl: 'https://github.com/renovatebot/renovate',
Expand Down Expand Up @@ -2026,6 +2029,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'registry.company.com/node',
});
expect(res).toEqual({
lookupName: 'node',
registryUrl: 'https://registry.company.com',
releases: [
{
Expand Down Expand Up @@ -2081,6 +2085,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'registry.company.com/node',
});
expect(res).toEqual({
lookupName: 'node',
registryUrl: 'https://registry.company.com',
releases: [
{
Expand Down Expand Up @@ -2144,6 +2149,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'registry.company.com/node',
});
expect(res).toEqual({
lookupName: 'node',
registryUrl: 'https://registry.company.com',
releases: [],
sourceUrl: 'https://github.com/renovatebot/renovate',
Expand Down Expand Up @@ -2171,6 +2177,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'registry.company.com/node',
});
expect(res).toEqual({
lookupName: 'node',
registryUrl: 'https://registry.company.com',
releases: [],
});
Expand All @@ -2195,6 +2202,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'registry.company.com/node',
});
expect(res).toEqual({
lookupName: 'node',
registryUrl: 'https://registry.company.com',
releases: [],
});
Expand All @@ -2216,6 +2224,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'registry.company.com/node',
});
expect(res).toEqual({
lookupName: 'node',
registryUrl: 'https://registry.company.com',
releases: [],
});
Expand Down Expand Up @@ -2266,6 +2275,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'registry.company.com/node',
});
expect(res).toEqual({
lookupName: 'node',
registryUrl: 'https://registry.company.com',
releases: [
{
Expand Down Expand Up @@ -2320,6 +2330,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'registry.company.com/node',
});
expect(res).toEqual({
lookupName: 'node',
registryUrl: 'https://registry.company.com',
releases: [
{
Expand Down Expand Up @@ -2350,6 +2361,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'registry.company.com/node',
});
expect(res).toEqual({
lookupName: 'node',
registryUrl: 'https://registry.company.com',
releases: [],
});
Expand Down Expand Up @@ -2404,6 +2416,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'registry.company.com/node',
});
expect(res).toEqual({
lookupName: 'node',
registryUrl: 'https://registry.company.com',
releases: [],
});
Expand Down Expand Up @@ -2463,6 +2476,7 @@ describe('modules/datasource/docker/index', () => {
packageName: 'ghcr.io/visualon/drone-git',
});
expect(res).toEqual({
lookupName: 'visualon/drone-git',
registryUrl: 'https://ghcr.io',
sourceUrl: 'https://github.com/visualon/drone-git',
releases: [{ version: '1.0.0' }],
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/datasource/docker/index.ts
Expand Up @@ -1006,6 +1006,10 @@ export class DockerDatasource extends Datasource {
registryUrl: registryHost,
releases,
};
if (dockerRepository !== packageName) {
// This will be reused later if a getDigest() call is made
ret.lookupName = dockerRepository;
}

const tags = releases.map((release) => release.version);
const latestTag = tags.includes('latest')
Expand Down
1 change: 1 addition & 0 deletions lib/modules/datasource/types.ts
Expand Up @@ -83,6 +83,7 @@ export interface ReleaseResult {
registryUrl?: string;
replacementName?: string;
replacementVersion?: string;
lookupName?: string;
}

export type RegistryStrategy = 'first' | 'hunt' | 'merge';
Expand Down
9 changes: 8 additions & 1 deletion lib/workers/repository/process/lookup/index.ts
Expand Up @@ -4,6 +4,7 @@ import type { ValidationMessage } from '../../../../config/types';
import { CONFIG_VALIDATION } from '../../../../constants/error-messages';
import { logger } from '../../../../logger';
import {
GetDigestInputConfig,
Release,
ReleaseResult,
applyDatasourceFilters,
Expand Down Expand Up @@ -157,6 +158,7 @@ export async function lookupUpdates(
'homepage',
'changelogUrl',
'dependencyUrl',
'lookupName',
]);

const latestVersion = dependency.tags?.latest;
Expand Down Expand Up @@ -496,10 +498,15 @@ export async function lookupUpdates(
// update digest for all
for (const update of res.updates) {
if (config.pinDigests === true || config.currentDigest) {
const getDigestConfig: GetDigestInputConfig = {
...config,
packageName: res.lookupName ?? config.packageName,
};
// TODO #22198
update.newDigest ??=
dependency?.releases.find((r) => r.version === update.newValue)
?.newDigest ?? (await getDigest(config, update.newValue))!;
?.newDigest ??
(await getDigest(getDigestConfig, update.newValue))!;

// If the digest could not be determined, report this as otherwise the
// update will be omitted later on without notice.
Expand Down
1 change: 1 addition & 0 deletions lib/workers/repository/process/lookup/types.ts
Expand Up @@ -59,6 +59,7 @@ export interface UpdateResult {
sourceUrl?: string | null;
currentVersion?: string;
isSingleVersion?: boolean;
lookupName?: string;
skipReason?: SkipReason;
registryUrl?: string;
fixedVersion?: string;
Expand Down

0 comments on commit 42081a3

Please sign in to comment.