Skip to content

Commit

Permalink
Retrive image manifest hash
Browse files Browse the repository at this point in the history
Since at least Docker registry 2.6.0 the image digest and the manifest
digest differ. The Grocker result file give the digest to allow checking
it during the pull process. With the new registry this always fail.

For private registry, we now retrieve the manifest digest using the http
API to fix this issue.
  • Loading branch information
Fabien Bochu committed Aug 21, 2017
1 parent 69c3d48 commit ca3721c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ChangeLog
----------------

- Support of pip trusted host config in wheel builder.
- Retrieve image manifest digest from registry.


5.2 (2017-07-18)
Expand Down
5 changes: 4 additions & 1 deletion src/grocker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ def build(release, build_dependencies, build_image, push, **kwargs):
else:
logger.info('Pushing image...')
image = builders.docker_push_image(docker_client, image_name)
collect['hash'] = [x.split('@')[1] for x in image.attrs['RepoDigests']][0]
collect['hash'] = (
builders.get_manifest_digest(image_name)
or [x.split('@')[1] for x in image.attrs['RepoDigests']][0]
)

if kwargs['result_file']:
helpers.dump_yaml(kwargs['result_file'], collect)
Expand Down
3 changes: 2 additions & 1 deletion src/grocker/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .build import build_runner_image
from . import naming
from . import op
from .op import docker_push_image, is_prefixed_image
from .op import docker_push_image, get_manifest_digest, is_prefixed_image
from .wheels import compile_wheels


Expand All @@ -16,6 +16,7 @@
'docker_push_image',
'is_prefixed_image',
'compile_wheels',
'get_manifest_digest',
'get_or_build_root_image',
'get_or_build_compiler_image',
]
Expand Down
12 changes: 12 additions & 0 deletions src/grocker/builders/op.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import docker.errors
import docker.utils.json_stream

import requests

from .. import __version__
from .. import helpers
from .. import six
Expand Down Expand Up @@ -88,6 +90,16 @@ def docker_push_image(docker_client, name):
return docker_client.images.get(name)


def get_manifest_digest(name):
registry_repository, tag = name.split(':', 1)
if '.' not in registry_repository: # Docker Hub
return None # Docker HUB API is not documented

registry, repository = registry_repository.split('/', 1)
response = requests.head('https://{}/v2/{}/manifests/{}'.format(registry, repository, tag))
return response.headers['Docker-Content-Digest']


def docker_run_container(docker_client, name, command, volumes=None, environment=None):
logger.info(
'Running %s on image %s (volumes:%s, environment:%s)',
Expand Down

0 comments on commit ca3721c

Please sign in to comment.