From 2f5e247cfdf0317881d20bd70e60d3e599ae0c3c Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Wed, 7 Dec 2022 20:13:48 -0800 Subject: [PATCH] fix: don't overwrite user base image (#3329) Fixes https://github.com/bentoml/BentoML/issues/3325 --- src/bentoml/_internal/bento/build_config.py | 4 ++-- src/bentoml/_internal/container/generate.py | 19 +++++++++++-------- .../server/grpc/servicer/v1/__init__.py | 2 ++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/bentoml/_internal/bento/build_config.py b/src/bentoml/_internal/bento/build_config.py index 4dbdbcf964..01db304ece 100644 --- a/src/bentoml/_internal/bento/build_config.py +++ b/src/bentoml/_internal/bento/build_config.py @@ -149,13 +149,13 @@ class DockerOptions: # always omit config values in case of default values got changed in future BentoML releases __omit_if_default__ = False - distro: str = attr.field( + distro: t.Optional[str] = attr.field( default=None, validator=attr.validators.optional( attr.validators.in_(CONTAINER_SUPPORTED_DISTROS) ), ) - python_version: str = attr.field( + python_version: t.Optional[str] = attr.field( converter=_convert_python_version, default=None, validator=attr.validators.optional( diff --git a/src/bentoml/_internal/container/generate.py b/src/bentoml/_internal/container/generate.py index 738f9e508b..b3b0fcbb70 100644 --- a/src/bentoml/_internal/container/generate.py +++ b/src/bentoml/_internal/container/generate.py @@ -58,24 +58,27 @@ def get_templates_variables( """ Returns a dictionary of variables to be used in BentoML base templates. """ - spec = DistroSpec.from_options(docker, conda) conda_python_version = conda.get_python_version(bento_fs) if conda_python_version is None: conda_python_version = docker.python_version - python_version = docker.python_version - if docker.distro in ("ubi8"): - # ubi8 base images uses "py38" instead of "py3.8" in its image tag - python_version = python_version.replace(".", "") - base_image = spec.image.format(spec_version=python_version) - if docker.cuda_version is not None: - base_image = spec.image.format(spec_version=docker.cuda_version) if docker.base_image is not None: base_image = docker.base_image logger.info( "BentoML will not install Python to custom base images; ensure the base image '%s' has Python installed.", base_image, ) + else: + spec = DistroSpec.from_options(docker, conda) + python_version = docker.python_version + assert docker.distro is not None and python_version is not None + if docker.distro in ("ubi8"): + # ubi8 base images uses "py38" instead of "py3.8" in its image tag + python_version = python_version.replace(".", "") + base_image = spec.image.format(spec_version=python_version) + if docker.cuda_version is not None: + base_image = spec.image.format(spec_version=docker.cuda_version) + # bento__env default_env = { "uid_gid": BENTO_UID_GID, diff --git a/src/bentoml/_internal/server/grpc/servicer/v1/__init__.py b/src/bentoml/_internal/server/grpc/servicer/v1/__init__.py index 224f2b9878..49ad48b0bc 100644 --- a/src/bentoml/_internal/server/grpc/servicer/v1/__init__.py +++ b/src/bentoml/_internal/server/grpc/servicer/v1/__init__.py @@ -7,6 +7,7 @@ from typing import TYPE_CHECKING import anyio + from .....utils import LazyLoader from ......exceptions import InvalidArgument from ......exceptions import BentoMLException @@ -22,6 +23,7 @@ import grpc from google.protobuf import struct_pb2 + from ......grpc.v1 import service_pb2 as pb from ......grpc.v1 import service_pb2_grpc as services from ......grpc.types import BentoServicerContext