Skip to content

Commit

Permalink
fix(datasource/docker): better reuse of lookupName for getDigest (#27724
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rarkins committed Mar 5, 2024
1 parent 47c8501 commit d5f3d6f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
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

0 comments on commit d5f3d6f

Please sign in to comment.