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(docker): caching of null lookup responses #6534

Merged
merged 1 commit into from Jun 17, 2020
Merged
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
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