Add agent.disable_task_docker_override configuration option to disable docker override specified in executing tasks

This commit is contained in:
allegroai 2022-12-07 22:07:11 +02:00
parent 6be75abc86
commit 5d517c91b5
2 changed files with 22 additions and 6 deletions

View File

@ -332,4 +332,9 @@
# the agent will catch the exception, log it and continue running.
# Set this to `true` to propagate exceptions and crash the agent.
# crash_on_exception: true
# Disable task docker override. If true, the agent will use the default docker image and ignore any docker image
# and arguments specified in the task's container section (setup shell script from the task container section will
# be used in any case, of specified).
disable_task_docker_override: false
}

View File

@ -737,7 +737,7 @@ class Worker(ServiceCommandSection):
pass
def run_one_task(self, queue, task_id, worker_args, docker=None, task_session=None):
# type: (Text, Text, WorkerParams, Optional[Text]) -> int
# type: (Text, Text, WorkerParams, Optional[Text], Optional[Session]) -> int
"""
Run one task pulled from queue.
:param queue: ID of queue that task was pulled from
@ -782,10 +782,18 @@ class Worker(ServiceCommandSection):
except Exception:
task_container = {}
default_docker = not bool(task_container.get('image'))
docker_image = task_container.get('image') or self._docker_image
docker_arguments = task_container.get(
'arguments', self._docker_arguments if default_docker else None)
default_docker = (
self._session.config.get('agent.disable_task_docker_override', False)
or not bool(task_container.get('image'))
)
if default_docker:
docker_image = self._docker_image
docker_arguments = self._docker_arguments
else:
docker_image = task_container.get('image') or self._docker_image
docker_arguments = task_container.get(
'arguments', self._docker_arguments if default_docker else None)
docker_setup_script = task_container.get('setup_shell_script')
self.send_logs(
@ -2079,7 +2087,10 @@ class Worker(ServiceCommandSection):
# noinspection PyBroadException
try:
task_container = get_task_container(self._session, task_id)
if task_container.get('image'):
if (
task_container.get('image')
and not self._session.config.get('agent.disable_task_docker_override', False)
):
docker_image = task_container.get('image')
print('Ignoring default docker image, using task docker image {}'.format(docker_image))
docker_arguments = task_container.get('arguments')