Skip to content

Commit

Permalink
fix: Correct digest resolution when the replacementName and replaceme…
Browse files Browse the repository at this point in the history
…ntVersion options are defined (#29164)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
ssegato81 and viceice committed May 22, 2024
1 parent f4eeaaa commit c0089d6
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
89 changes: 89 additions & 0 deletions lib/workers/repository/process/lookup/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4253,6 +4253,95 @@ describe('workers/repository/process/lookup/index', () => {
]);
});

it('handles replacements - Digest configured and validating getDigest funtion call', async () => {
config.packageName = 'openjdk';
config.currentDigest = 'sha256:fedcba0987654321';
config.currentValue = '17.0.0';
//config.pinDigests = true;
config.datasource = DockerDatasource.id;
config.versioning = dockerVersioningId;
// This config is normally set when packageRules are applied
config.replacementName = 'eclipse-temurin';
config.replacementVersion = '19.0.0';
getDockerReleases.mockResolvedValueOnce({
releases: [
{
version: '17.0.0',
},
{
version: '17.0.1',
},
],
lookupName: 'openjdk',
});
getDockerDigest.mockResolvedValueOnce('sha256:abcdef1234567890');
getDockerDigest.mockResolvedValueOnce('sha256:fedcba0987654321');
getDockerDigest.mockResolvedValueOnce('sha256:pin0987654321');

const { updates } = await Result.wrap(
lookup.lookupUpdates(config),
).unwrapOrThrow();

expect(updates).toEqual([
{
bucket: 'non-major',
newDigest: 'sha256:abcdef1234567890',
newMajor: 17,
newMinor: 0,
newValue: '17.0.1',
newVersion: '17.0.1',
updateType: 'patch',
},
{
newDigest: 'sha256:fedcba0987654321',
newName: 'eclipse-temurin',
newValue: '19.0.0',
newVersion: undefined,
updateType: 'replacement',
},
{
newDigest: 'sha256:pin0987654321',
newValue: '17.0.0',
newVersion: undefined,
updateType: 'digest',
},
]);

expect(getDockerDigest).toHaveBeenNthCalledWith(
1,
{
currentDigest: 'sha256:fedcba0987654321',
currentValue: '17.0.0',
lookupName: 'openjdk',
packageName: 'openjdk',
registryUrl: 'https://index.docker.io',
},
'17.0.1',
);
expect(getDockerDigest).toHaveBeenNthCalledWith(
2,
{
currentDigest: undefined,
currentValue: '17.0.0',
lookupName: undefined,
packageName: 'eclipse-temurin',
registryUrl: 'https://index.docker.io',
},
'19.0.0',
);
expect(getDockerDigest).toHaveBeenNthCalledWith(
3,
{
currentDigest: 'sha256:fedcba0987654321',
currentValue: '17.0.0',
lookupName: 'openjdk',
packageName: 'openjdk',
registryUrl: 'https://index.docker.io',
},
'17.0.0',
);
});

it('handles replacements - skips if package and replacement names match', async () => {
config.packageName = 'openjdk';
config.currentValue = undefined;
Expand Down
15 changes: 15 additions & 0 deletions lib/workers/repository/process/lookup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,21 @@ export async function lookupUpdates(
registryUrl: update.registryUrl ?? res.registryUrl,
lookupName: res.lookupName,
};

// #20304 only pass it for replacement updates, otherwise we get wrong or invalid digest
if (update.updateType !== 'replacement') {
delete getDigestConfig.replacementName;
}

// #20304 don't use lookupName and currentDigest when we replace image name
if (
update.updateType === 'replacement' &&
update.newName !== config.packageName
) {
delete getDigestConfig.lookupName;
delete getDigestConfig.currentDigest;
}

// TODO #22198
update.newDigest ??=
dependency?.releases.find((r) => r.version === update.newValue)
Expand Down

0 comments on commit c0089d6

Please sign in to comment.