Don't return Docker-Content-Digest header on HEAD

Buildkit seems to get confused by this and thinks we're telling it
that the digest of the empty string is the digest of the actual
content, and it rejects the response.

Change-Id: I5416694d861c5391fa0aebcebfd83d7c1b0a4e4d
This commit is contained in:
James E. Blair 2020-05-04 10:32:59 -07:00
parent 6467e48623
commit 7ba90a1cd4
1 changed files with 12 additions and 3 deletions

View File

@ -292,8 +292,14 @@ class RegistryAPI:
self.log.error('Manifest %s %s not found', repository, ref)
return self.not_found()
res.headers['Content-Type'] = json.loads(manifest)['mediaType']
if method == 'HEAD':
# Buildkit gets confused if the Docker-Content-Digest
# header is present in a HEAD response. It seems to
# assume that it's the digest of the returned (null)
# data.
return {}
res.headers['Docker-Content-Digest'] = ref
return (method == 'GET' and manifest or {})
return manifest
manifest = self.storage.get_manifest(namespace, repository, ref)
if manifest is None:
manifest = {}
@ -309,11 +315,14 @@ class RegistryAPI:
'Blob %s %s not found', namespace, manifest[ct])
return self.not_found()
res.headers['Content-Type'] = ct
res.headers['Docker-Content-Digest'] = manifest[ct]
hasher = hashlib.sha256()
hasher.update(data)
self.log.debug('Retrieved sha256 %s', hasher.hexdigest())
return (method == 'GET' and data or {})
if method == 'HEAD':
# See comment above about Buildkit.
return {}
res.headers['Docker-Content-Digest'] = manifest[ct]
return data
self.log.error('Manifest %s %s not found', repository, ref)
return self.not_found()