Fix docker container backwards compatibility for API <2.13

Fix default docker match rules resolver (used incorrect field "container" instead of "image")
Remove "container" (image) match rule option from default docker image resolver
This commit is contained in:
allegroai 2023-07-04 14:37:18 +03:00
parent a535f93cd6
commit 3ed63e2154
4 changed files with 23 additions and 29 deletions

View File

@ -388,13 +388,6 @@
# } # }
# }, # },
# { # {
# "image": "better_container:tag",
# "arguments": "",
# "match": {
# "container": "replace_me_please"
# }
# },
# {
# "image": "another_container:tag", # "image": "another_container:tag",
# "arguments": "", # "arguments": "",
# "match": { # "match": {

View File

@ -109,15 +109,15 @@ def resolve_default_container(session, task_id, container_config):
match.get('script.binary', None), entry)) match.get('script.binary', None), entry))
continue continue
if match.get('container', None): # if match.get('image', None):
# noinspection PyBroadException # # noinspection PyBroadException
try: # try:
if not re.search(match.get('container', None), requested_container.get('image', '')): # if not re.search(match.get('image', None), requested_container.get('image', '')):
continue # continue
except Exception: # except Exception:
print('Failed parsing regular expression \"{}\" in rule: {}'.format( # print('Failed parsing regular expression \"{}\" in rule: {}'.format(
match.get('container', None), entry)) # match.get('image', None), entry))
continue # continue
matched = True matched = True
for req_section in ['script.requirements.pip', 'script.requirements.conda']: for req_section in ['script.requirements.pip', 'script.requirements.conda']:
@ -156,8 +156,8 @@ def resolve_default_container(session, task_id, container_config):
break break
if matched: if matched:
if not container_config.get('container'): if not container_config.get('image'):
container_config['container'] = entry.get('image', None) container_config['image'] = entry.get('image', None)
if not container_config.get('arguments'): if not container_config.get('arguments'):
container_config['arguments'] = entry.get('arguments', None) container_config['arguments'] = entry.get('arguments', None)
container_config['arguments'] = shlex.split(str(container_config.get('arguments') or '').strip()) container_config['arguments'] = shlex.split(str(container_config.get('arguments') or '').strip())

View File

@ -372,16 +372,19 @@ def get_task_container(session, task_id):
container = {} container = {}
else: else:
response = get_task(session, task_id, only_fields=["execution.docker_cmd"]) response = get_task(session, task_id, only_fields=["execution.docker_cmd"])
task_docker_cmd_parts = shlex.split(str(response.execution.docker_cmd or '').strip()) container = {}
try: if response.execution:
container = dict( task_docker_cmd_parts = shlex.split(str(response.execution.docker_cmd or '').strip())
container=task_docker_cmd_parts[0], if task_docker_cmd_parts:
arguments=task_docker_cmd_parts[1:] if len(task_docker_cmd_parts[0]) > 1 else '' try:
) container = dict(
except (ValueError, TypeError): image=task_docker_cmd_parts[0],
container = {} arguments=task_docker_cmd_parts[1:] if len(task_docker_cmd_parts[0]) > 1 else ''
)
except (ValueError, TypeError):
pass
if (not container or not container.get('container')) and session.check_min_api_version("2.13"): if (not container or not container.get('image')) and session.check_min_api_version("2.13"):
container = resolve_default_container(session=session, task_id=task_id, container_config=container) container = resolve_default_container(session=session, task_id=task_id, container_config=container)
return container return container

View File

@ -242,8 +242,6 @@ agent {
# # no repository matching required # # no repository matching required
# repository: "" # repository: ""
# } # }
# # no container image matching required (allow to replace one requested container with another)
# container: ""
# # no repository matching required # # no repository matching required
# project: "" # project: ""
# } # }