Skip to content

Commit

Permalink
fix(docker): caching of null lookup responses (#6534)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jun 17, 2020
1 parent cf508a3 commit b277dfe
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/datasource/docker/index.ts
Expand Up @@ -336,27 +336,24 @@ export async function getDigest(
);
logger.debug(`getDigest(${registry}, ${repository}, ${newValue})`);
const newTag = newValue || 'latest';
const cacheNamespace = 'datasource-docker-digest';
const cacheKey = `${registry}:${repository}:${newTag}`;
let digest = null;
try {
const cacheNamespace = 'datasource-docker-digest';
const cacheKey = `${registry}:${repository}:${newTag}`;
const cachedResult = await globalCache.get(cacheNamespace, cacheKey);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
const manifestResponse = await getManifestResponse(
registry,
repository,
newTag
);
if (!manifestResponse) {
return null;
if (manifestResponse) {
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 */ {
if (err instanceof DatasourceError) {
throw err;
Expand All @@ -369,8 +366,10 @@ export async function getDigest(
},
'Unknown Error looking up docker image digest'
);
return null;
}
const cacheMinutes = 30;
await globalCache.set(cacheNamespace, cacheKey, null, cacheMinutes);
return digest;
}

async function getTags(
Expand All @@ -386,7 +385,7 @@ async function getTags(
cacheKey
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
// AWS ECR limits the maximum number of results to 1000
Expand Down Expand Up @@ -486,7 +485,7 @@ async function getLabels(
cacheKey
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
try {
Expand Down

0 comments on commit b277dfe

Please sign in to comment.