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(datasource/docker): better reuse of lookupName for getDigest #27724

Merged
merged 2 commits into from Mar 5, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/modules/datasource/docker/index.spec.ts
Expand Up @@ -491,14 +491,16 @@ describe('modules/datasource/docker/index', () => {
.scope(gcrUrl)
.get('/')
.reply(200)
.head('/some-project/some-package/manifests/some-tag')
.head('/google.com/some-project/some-package/manifests/some-tag')
.reply(200, '', { 'docker-content-digest': 'some-digest' });

hostRules.find.mockReturnValue({});
const res = await getDigest(
{
datasource: 'docker',
packageName: 'eu.gcr.io/some-project/some-package',
registryUrl: 'https://eu.gcr.io',
lookupName: 'google.com/some-project/some-package',
packageName: 'eu.gcr.io/google.com/some-project/some-package',
},
'some-tag',
);
Expand Down
19 changes: 14 additions & 5 deletions lib/modules/datasource/docker/index.ts
Expand Up @@ -788,13 +788,22 @@ export class DockerDatasource extends Datasource {
},
})
override async getDigest(
{ registryUrl, packageName, currentDigest }: DigestConfig,
{ registryUrl, lookupName, packageName, currentDigest }: DigestConfig,
newValue?: string,
): Promise<string | null> {
const { registryHost, dockerRepository } = getRegistryRepository(
packageName,
registryUrl!,
);
let registryHost: string;
let dockerRepository: string;
if (registryUrl && lookupName) {
// Reuse the resolved values from getReleases()
registryHost = registryUrl;
dockerRepository = lookupName;
} else {
// Resolve values independently
({ registryHost, dockerRepository } = getRegistryRepository(
packageName,
registryUrl!,
));
}
logger.debug(
// TODO: types (#22198)
`getDigest(${registryHost}, ${dockerRepository}, ${newValue})`,
Expand Down
19 changes: 11 additions & 8 deletions lib/modules/datasource/index.ts
Expand Up @@ -398,15 +398,18 @@ function getDigestConfig(
datasource: DatasourceApi,
config: GetDigestInputConfig,
): DigestConfig {
const { currentValue, currentDigest } = config;
const { lookupName, currentValue, currentDigest } = config;
const packageName = config.replacementName ?? config.packageName;
const [registryUrl] = resolveRegistryUrls(
datasource,
config.defaultRegistryUrls,
config.registryUrls,
config.additionalRegistryUrls,
);
return { packageName, registryUrl, currentValue, currentDigest };
// Prefer registryUrl from getReleases() lookup if it has been passed
const registryUrl =
config.registryUrl ??
resolveRegistryUrls(
datasource,
config.defaultRegistryUrls,
config.registryUrls,
config.additionalRegistryUrls,
)[0];
return { lookupName, packageName, registryUrl, currentValue, currentDigest };
}

export function getDigest(
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/datasource/types.ts
Expand Up @@ -9,6 +9,8 @@ export interface GetDigestInputConfig {
packageName: string;
defaultRegistryUrls?: string[];
registryUrls?: string[] | null;
registryUrl?: string;
lookupName?: string;
additionalRegistryUrls?: string[];
currentValue?: string;
currentDigest?: string;
Expand All @@ -17,6 +19,7 @@ export interface GetDigestInputConfig {

export interface DigestConfig {
packageName: string;
lookupName?: string;
registryUrl?: string;
currentValue?: string;
currentDigest?: string;
Expand Down
3 changes: 2 additions & 1 deletion lib/workers/repository/process/lookup/index.ts
Expand Up @@ -500,7 +500,8 @@ export async function lookupUpdates(
if (config.pinDigests === true || config.currentDigest) {
const getDigestConfig: GetDigestInputConfig = {
...config,
packageName: res.lookupName ?? config.packageName,
registryUrl: update.registryUrl ?? res.registryUrl,
lookupName: res.lookupName,
};
// TODO #22198
update.newDigest ??=
Expand Down