feat: docker registry cache ()

Use got’s built-in caching with in-memory map.

Closes 
pull/1211/head v10.20.0
Rhys Arkins 2017-11-22 13:25:07 +01:00 committed by GitHub
parent 4e7830e831
commit 371f1cbf3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions
lib/manager/docker

View File

@ -5,6 +5,8 @@ module.exports = {
getTags,
};
const map = new Map();
async function getDigest(name, tag = 'latest') {
const repository = name.includes('/') ? name : `library/${name}`;
try {
@ -12,7 +14,7 @@ async function getDigest(name, tag = 'latest') {
repository
}:pull`;
logger.debug(`Obtaining docker registry token for ${repository}`);
const { token } = (await got(authUrl, { json: true })).body;
const { token } = (await got(authUrl, { cache: map, json: true })).body;
if (!token) {
logger.warn('Failed to obtain docker registry token');
return null;
@ -23,9 +25,8 @@ async function getDigest(name, tag = 'latest') {
Authorization: `Bearer ${token}`,
Accept: 'application/vnd.docker.distribution.manifest.v2+json',
};
const digest = (await got(url, { json: true, headers })).headers[
'docker-content-digest'
];
const digest = (await got(url, { cache: map, json: true, headers }))
.headers['docker-content-digest'];
logger.debug({ digest }, 'Got docker digest');
return digest;
} catch (err) {
@ -41,7 +42,7 @@ async function getTags(name) {
repository
}:pull`;
logger.debug(`Obtaining docker registry token for ${repository}`);
const { token } = (await got(authUrl, { json: true })).body;
const { token } = (await got(authUrl, { cache: map, json: true })).body;
if (!token) {
logger.warn('Failed to obtain docker registry token');
return null;
@ -52,7 +53,7 @@ async function getTags(name) {
Authorization: `Bearer ${token}`,
Accept: 'application/vnd.docker.distribution.manifest.v2+json',
};
const res = await got(url, { json: true, headers });
const res = await got(url, { cache: map, json: true, headers });
logger.debug({ tags: res.body.tags }, 'Got docker tags');
return res.body.tags;
} catch (err) {