mirror of
				https://github.com/clearml/clearml-agent
				synced 2025-06-26 18:16:15 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									a535f93cd6
								
							
						
					
					
						commit
						3ed63e2154
					
				@ -388,13 +388,6 @@
 | 
			
		||||
    #                 }
 | 
			
		||||
    #             },
 | 
			
		||||
    #             {
 | 
			
		||||
    #                 "image": "better_container:tag",
 | 
			
		||||
    #                 "arguments": "",
 | 
			
		||||
    #                 "match": {
 | 
			
		||||
    #                     "container": "replace_me_please"
 | 
			
		||||
    #                 }
 | 
			
		||||
    #             },
 | 
			
		||||
    #             {
 | 
			
		||||
    #                 "image": "another_container:tag",
 | 
			
		||||
    #                 "arguments": "",
 | 
			
		||||
    #                 "match": {
 | 
			
		||||
 | 
			
		||||
@ -109,15 +109,15 @@ def resolve_default_container(session, task_id, container_config):
 | 
			
		||||
                    match.get('script.binary', None), entry))
 | 
			
		||||
                continue
 | 
			
		||||
 | 
			
		||||
        if match.get('container', None):
 | 
			
		||||
            # noinspection PyBroadException
 | 
			
		||||
            try:
 | 
			
		||||
                if not re.search(match.get('container', None), requested_container.get('image', '')):
 | 
			
		||||
                    continue
 | 
			
		||||
            except Exception:
 | 
			
		||||
                print('Failed parsing regular expression \"{}\" in rule: {}'.format(
 | 
			
		||||
                    match.get('container', None), entry))
 | 
			
		||||
                continue
 | 
			
		||||
        # if match.get('image', None):
 | 
			
		||||
        #     # noinspection PyBroadException
 | 
			
		||||
        #     try:
 | 
			
		||||
        #         if not re.search(match.get('image', None), requested_container.get('image', '')):
 | 
			
		||||
        #             continue
 | 
			
		||||
        #     except Exception:
 | 
			
		||||
        #         print('Failed parsing regular expression \"{}\" in rule: {}'.format(
 | 
			
		||||
        #             match.get('image', None), entry))
 | 
			
		||||
        #         continue
 | 
			
		||||
 | 
			
		||||
        matched = True
 | 
			
		||||
        for req_section in ['script.requirements.pip', 'script.requirements.conda']:
 | 
			
		||||
@ -156,8 +156,8 @@ def resolve_default_container(session, task_id, container_config):
 | 
			
		||||
            break
 | 
			
		||||
 | 
			
		||||
        if matched:
 | 
			
		||||
            if not container_config.get('container'):
 | 
			
		||||
                container_config['container'] = entry.get('image', None)
 | 
			
		||||
            if not container_config.get('image'):
 | 
			
		||||
                container_config['image'] = entry.get('image', None)
 | 
			
		||||
            if not container_config.get('arguments'):
 | 
			
		||||
                container_config['arguments'] = entry.get('arguments', None)
 | 
			
		||||
                container_config['arguments'] = shlex.split(str(container_config.get('arguments') or '').strip())
 | 
			
		||||
 | 
			
		||||
@ -372,16 +372,19 @@ def get_task_container(session, task_id):
 | 
			
		||||
            container = {}
 | 
			
		||||
    else:
 | 
			
		||||
        response = get_task(session, task_id, only_fields=["execution.docker_cmd"])
 | 
			
		||||
        task_docker_cmd_parts = shlex.split(str(response.execution.docker_cmd or '').strip())
 | 
			
		||||
        try:
 | 
			
		||||
            container = dict(
 | 
			
		||||
                container=task_docker_cmd_parts[0],
 | 
			
		||||
                arguments=task_docker_cmd_parts[1:] if len(task_docker_cmd_parts[0]) > 1 else ''
 | 
			
		||||
            )
 | 
			
		||||
        except (ValueError, TypeError):
 | 
			
		||||
            container = {}
 | 
			
		||||
        container = {}
 | 
			
		||||
        if response.execution:
 | 
			
		||||
            task_docker_cmd_parts = shlex.split(str(response.execution.docker_cmd or '').strip())
 | 
			
		||||
            if task_docker_cmd_parts:
 | 
			
		||||
                try:
 | 
			
		||||
                    container = dict(
 | 
			
		||||
                        image=task_docker_cmd_parts[0],
 | 
			
		||||
                        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)
 | 
			
		||||
 | 
			
		||||
    return container
 | 
			
		||||
 | 
			
		||||
@ -242,8 +242,6 @@ agent {
 | 
			
		||||
        #                 # no repository matching required
 | 
			
		||||
        #                 repository: ""
 | 
			
		||||
        #             }
 | 
			
		||||
        #             # no container image matching required (allow to replace one requested container with another)
 | 
			
		||||
        #             container: ""
 | 
			
		||||
        #             # no repository matching required
 | 
			
		||||
        #             project: ""
 | 
			
		||||
        #         }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user