mirror of
https://github.com/clearml/clearml-agent
synced 2025-03-03 18:52:22 +00:00
Add build --force-docker command line argument to the to allow ignoring task container data
This commit is contained in:
parent
73625bf00f
commit
938fcc4530
@ -1801,6 +1801,7 @@ class Worker(ServiceCommandSection):
|
|||||||
docker=None,
|
docker=None,
|
||||||
entry_point=None,
|
entry_point=None,
|
||||||
install_globally=False,
|
install_globally=False,
|
||||||
|
force_docker=False,
|
||||||
**_
|
**_
|
||||||
):
|
):
|
||||||
if not task_id:
|
if not task_id:
|
||||||
@ -1809,7 +1810,7 @@ class Worker(ServiceCommandSection):
|
|||||||
self._session.print_configuration()
|
self._session.print_configuration()
|
||||||
|
|
||||||
if docker is not False and docker is not None:
|
if docker is not False and docker is not None:
|
||||||
return self._build_docker(docker, target, task_id, entry_point)
|
return self._build_docker(docker, target, task_id, entry_point, force_docker=force_docker)
|
||||||
|
|
||||||
current_task = self._session.api_client.tasks.get_by_id(task_id)
|
current_task = self._session.api_client.tasks.get_by_id(task_id)
|
||||||
|
|
||||||
@ -1891,7 +1892,7 @@ class Worker(ServiceCommandSection):
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def _build_docker(self, docker, target, task_id, entry_point=None):
|
def _build_docker(self, docker, target, task_id, entry_point=None, force_docker=False):
|
||||||
|
|
||||||
self.temp_config_path = safe_mkstemp(
|
self.temp_config_path = safe_mkstemp(
|
||||||
suffix=".cfg", prefix=".clearml_agent.", text=True, name_only=True
|
suffix=".cfg", prefix=".clearml_agent.", text=True, name_only=True
|
||||||
@ -1902,21 +1903,25 @@ class Worker(ServiceCommandSection):
|
|||||||
temp_config, docker_image_func = self.get_docker_config_cmd(docker)
|
temp_config, docker_image_func = self.get_docker_config_cmd(docker)
|
||||||
self.dump_config(self.temp_config_path, config=temp_config)
|
self.dump_config(self.temp_config_path, config=temp_config)
|
||||||
self.docker_image_func = docker_image_func
|
self.docker_image_func = docker_image_func
|
||||||
# noinspection PyBroadException
|
|
||||||
try:
|
|
||||||
task_container = get_task_container(self._session, task_id)
|
|
||||||
except Exception:
|
|
||||||
task_container = {}
|
|
||||||
|
|
||||||
if task_container.get('image'):
|
|
||||||
docker_image = task_container.get('image')
|
|
||||||
docker_arguments = task_container.get('arguments')
|
|
||||||
docker_setup_script = task_container.get('setup_shell_script')
|
|
||||||
else:
|
|
||||||
docker_image = self._docker_image
|
docker_image = self._docker_image
|
||||||
docker_arguments = self._docker_arguments
|
docker_arguments = self._docker_arguments
|
||||||
docker_setup_script = None
|
docker_setup_script = None
|
||||||
|
|
||||||
|
if force_docker:
|
||||||
|
print('Ignoring any task container info, using docker image {}'.format(docker_image))
|
||||||
|
else:
|
||||||
|
# noinspection PyBroadException
|
||||||
|
try:
|
||||||
|
task_container = get_task_container(self._session, task_id)
|
||||||
|
if task_container.get('image'):
|
||||||
|
docker_image = task_container.get('image')
|
||||||
|
print('Ignoring default docker image, using task docker image {}'.format(docker_image))
|
||||||
|
docker_arguments = task_container.get('arguments')
|
||||||
|
docker_setup_script = task_container.get('setup_shell_script')
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
print('Building Task {} inside docker image: {} {} setup_script={}\n'.format(
|
print('Building Task {} inside docker image: {} {} setup_script={}\n'.format(
|
||||||
task_id, docker_image, docker_arguments or '', docker_setup_script or ''))
|
task_id, docker_image, docker_arguments or '', docker_setup_script or ''))
|
||||||
full_docker_cmd = self.docker_image_func(
|
full_docker_cmd = self.docker_image_func(
|
||||||
|
@ -204,6 +204,13 @@ COMMANDS = {
|
|||||||
'nargs': '*',
|
'nargs': '*',
|
||||||
'default': False,
|
'default': False,
|
||||||
},
|
},
|
||||||
|
'--force-docker': {
|
||||||
|
'help': 'Force using the agent-specified docker image (either explicitly in the --docker argument or'
|
||||||
|
'using the agent\'s default docker image). If provided, the agent will not use any docker'
|
||||||
|
'container information stored on the task itself (default False)',
|
||||||
|
'default': False,
|
||||||
|
'action': 'store_true',
|
||||||
|
},
|
||||||
'--python-version': {
|
'--python-version': {
|
||||||
'help': 'Virtual environment python version to use',
|
'help': 'Virtual environment python version to use',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user