Skip to content
Snippets Groups Projects
Unverified Commit b277dfe7 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

fix(docker): caching of null lookup responses (#6534)

parent cf508a3c
Branches
Tags
No related merge requests found
...@@ -336,12 +336,13 @@ export async function getDigest( ...@@ -336,12 +336,13 @@ export async function getDigest(
); );
logger.debug(`getDigest(${registry}, ${repository}, ${newValue})`); logger.debug(`getDigest(${registry}, ${repository}, ${newValue})`);
const newTag = newValue || 'latest'; const newTag = newValue || 'latest';
const cacheNamespace = 'datasource-docker-digest';
const cacheKey = `${registry}:${repository}:${newTag}`;
let digest = null;
try { try {
const cacheNamespace = 'datasource-docker-digest';
const cacheKey = `${registry}:${repository}:${newTag}`;
const cachedResult = await globalCache.get(cacheNamespace, cacheKey); const cachedResult = await globalCache.get(cacheNamespace, cacheKey);
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
const manifestResponse = await getManifestResponse( const manifestResponse = await getManifestResponse(
...@@ -349,14 +350,10 @@ export async function getDigest( ...@@ -349,14 +350,10 @@ export async function getDigest(
repository, repository,
newTag newTag
); );
if (!manifestResponse) { if (manifestResponse) {
return null; digest = extractDigestFromResponse(manifestResponse) || null;
logger.debug({ digest }, 'Got docker digest');
} }
const digest = extractDigestFromResponse(manifestResponse);
logger.debug({ digest }, 'Got docker digest');
const cacheMinutes = 30;
await globalCache.set(cacheNamespace, cacheKey, digest, cacheMinutes);
return digest;
} catch (err) /* istanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
if (err instanceof DatasourceError) { if (err instanceof DatasourceError) {
throw err; throw err;
...@@ -369,8 +366,10 @@ export async function getDigest( ...@@ -369,8 +366,10 @@ export async function getDigest(
}, },
'Unknown Error looking up docker image digest' 'Unknown Error looking up docker image digest'
); );
return null;
} }
const cacheMinutes = 30;
await globalCache.set(cacheNamespace, cacheKey, null, cacheMinutes);
return digest;
} }
async function getTags( async function getTags(
...@@ -386,7 +385,7 @@ async function getTags( ...@@ -386,7 +385,7 @@ async function getTags(
cacheKey cacheKey
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
// AWS ECR limits the maximum number of results to 1000 // AWS ECR limits the maximum number of results to 1000
...@@ -486,7 +485,7 @@ async function getLabels( ...@@ -486,7 +485,7 @@ async function getLabels(
cacheKey cacheKey
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment