From 154449a954baa6c17d11a3c7d1ea2320a04d0de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wawrzy=C5=84ski?= Date: Mon, 5 Feb 2024 14:23:02 +0100 Subject: [PATCH] Add workaround to prevent deleting temp directory before docker build image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adam WawrzyƄski --- bentoctl/deployment_config.py | 5 ++++- bentoctl/docker_utils.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bentoctl/deployment_config.py b/bentoctl/deployment_config.py index 6e2b2a4..fc0c97d 100644 --- a/bentoctl/deployment_config.py +++ b/bentoctl/deployment_config.py @@ -1,6 +1,7 @@ import copy import logging import os +import shutil import typing as t from contextlib import contextmanager from pathlib import Path @@ -254,7 +255,9 @@ def _prepare_bento_dir(self) -> t.Generator[str, None, None]: model = get_model(model_info.tag) model_fs = models_fs.makedirs(model_info.tag.path()) fs.mirror.mirror(model.path, model_fs) - yield temp_fs.getsyspath("/") + new_temp_dir = temp_fs.getsyspath("/")[:-1] + "-copy" + shutil.copytree(temp_fs.getsyspath("/"), new_temp_dir) + yield new_temp_dir def create_deployable(self, destination_dir=os.curdir) -> str: """ diff --git a/bentoctl/docker_utils.py b/bentoctl/docker_utils.py index d78ecc0..1406e40 100644 --- a/bentoctl/docker_utils.py +++ b/bentoctl/docker_utils.py @@ -1,5 +1,6 @@ from __future__ import annotations +import shutil import typing as t from collections import OrderedDict @@ -118,6 +119,7 @@ def generate_deployable_container( container.health("buildx") backend = container.get_backend("buildx") backend.build(**buildx_args) + shutil.rmtree(buildx_args["context_path"]) def tag_docker_image(image_name, image_tag):