Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
371f1cbf
Unverified
Commit
371f1cbf
authored
7 years ago
by
Rhys Arkins
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: docker registry cache (#1210)
Use got’s built-in caching with in-memory map. Closes #1028
parent
4e7830e8
Loading
Loading
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/manager/docker/registry.js
+7
-6
7 additions, 6 deletions
lib/manager/docker/registry.js
with
7 additions
and
6 deletions
lib/manager/docker/registry.js
+
7
−
6
View file @
371f1cbf
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment