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

Check and return errors while validating science image. #555

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions servicex_app/servicex/docker_repo_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,29 @@ class DockerRepoAdapter:
def __init__(self, registry_endpoint="https://hub.docker.com"):
self.registry_endpoint = registry_endpoint

def check_image_exists(self, tagged_image: str) -> bool:
def check_image_exists(self, tagged_image: str) -> (bool, str):
"""
Checks that the given Docker image
:param tagged_image: Full Docker image name, e.g. "sslhep/servicex_app:latest".
:return: Whether or not the image exists in the registry.
"""
search_result = re.search("(.+)/(.+):(.+)", tagged_image)
if not search_result or len(search_result.groups()) != 3:
return False
return False, f"Requested transformer docker image is not in the right format: {tagged_image}"

(repo, image, tag) = search_result.groups()

query = f'{self.registry_endpoint}/v2/repositories/{repo}/{image}/tags/{tag}'
r = requests.get(query)

if r.status_code >= 200 and r.status_code < 300:
current_app.logger.info(f"Requested Image: {tagged_image} exists, "
f"last updated {r.json()['last_updated']}")
return True, ""

if r.status_code == 404:
return False
return False, f"Requested transformer docker image doesn't exist: {tagged_image}"

msg = f"Unexpected error in validating transformer docker image ({tagged_image}), status_code: {r.status_code}, msg ({r.content})"
return False, msg

current_app.logger.info(f"Requested Image: {tagged_image} exists, "
f"last updated {r.json()['last_updated']}")
return True
4 changes: 2 additions & 2 deletions servicex_app/servicex/resources/transformation/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def post(self):
request_rec.image = codegen_transformer_image

if config['TRANSFORMER_VALIDATE_DOCKER_IMAGE']:
if not self.docker_repo_adapter.check_image_exists(request_rec.image):
msg = f"Requested transformer docker image doesn't exist: {request_rec.image}"
exists, msg = self.docker_repo_adapter.check_image_exists(request_rec.image)
if not exists:
current_app.logger.error(msg, extra={'requestId': request_id})
return {'message': msg}, 400

Expand Down