From c5bd3a37cd1c54217e881f4e7bcb6c6aeea346d6 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Tue, 6 Dec 2022 18:10:41 -0800 Subject: [PATCH 1/3] chore: bentoctl shim Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> --- src/bentoml/_internal/bento/gen.py | 39 +++++++++++++++++++++ src/bentoml/_internal/container/generate.py | 2 +- src/bentoml/_internal/utils/buildx.py | 34 ++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/bentoml/_internal/bento/gen.py create mode 100644 src/bentoml/_internal/utils/buildx.py diff --git a/src/bentoml/_internal/bento/gen.py b/src/bentoml/_internal/bento/gen.py new file mode 100644 index 0000000000..333abfa9b9 --- /dev/null +++ b/src/bentoml/_internal/bento/gen.py @@ -0,0 +1,39 @@ +""" +This module is shim for bentoctl. NOT FOR DIRECT USE. +""" +from __future__ import annotations + +import logging +import warnings +from typing import TYPE_CHECKING + +import fs + +from ..container.generate import generate_containerfile + +if TYPE_CHECKING: + from .build_config import DockerOptions + +__all__ = ["generate_dockerfile"] + +logger = logging.getLogger(__name__) + +warnings.warn( + "%s is deprecated. Make sure to use 'bentoml.container.build' and 'bentoml.container.health' instead." + % __name__, + DeprecationWarning, + stacklevel=4, +) + + +def generate_dockerfile(docker: DockerOptions, context_path: str, *, use_conda: bool): + from ..bento import Bento + + bento = Bento.from_fs(fs.open_fs(context_path)) + logger.debug("'use_conda' is deprecated and will not be used.") + return generate_containerfile( + docker, + bento.path, + conda=bento.info.conda, + bento_fs=bento._fs, + ) diff --git a/src/bentoml/_internal/container/generate.py b/src/bentoml/_internal/container/generate.py index 7180b14439..738f9e508b 100644 --- a/src/bentoml/_internal/container/generate.py +++ b/src/bentoml/_internal/container/generate.py @@ -113,7 +113,7 @@ def generate_containerfile( .. note:: - You should use ``construct_dockerfile`` instead of this function. + You should use ``construct_containerfile`` instead of this function. Returns: str: The rendered Dockerfile string. diff --git a/src/bentoml/_internal/utils/buildx.py b/src/bentoml/_internal/utils/buildx.py new file mode 100644 index 0000000000..fe13f2c2b6 --- /dev/null +++ b/src/bentoml/_internal/utils/buildx.py @@ -0,0 +1,34 @@ +""" +This module is shim for bentoctl. NOT FOR DIRECT USE. +Make sure to use 'bentoml.container.build' and 'bentoml.container.health' instead. +""" + +from __future__ import annotations + +import typing as t +import warnings + +from ..container import health as _internal_container_health +from ..container import get_backend + +__all__ = ["build", "health"] + +_buildx_backend = get_backend("buildx") + +warnings.warn( + "%s is deprecated. Make sure to use 'bentoml.container.build' and 'bentoml.container.health' instead." + % __name__, + DeprecationWarning, + stacklevel=4, +) + + +def health(): + return _internal_container_health("buildx") + + +def build(**kwargs: t.Any): + # subprocess_env from bentoctl will be handle by buildx, so it is safe to pop this out. + kwargs.pop("subprocess_env") + context_path = kwargs.pop("cwd", None) + _buildx_backend.build(context_path=context_path, **kwargs) From 412036a79ce67ba1708211ea6f4412f601161148 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Tue, 6 Dec 2022 18:29:42 -0800 Subject: [PATCH 2/3] chore: handle args correctly and dispatch list type Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> --- src/bentoml/_internal/container/base.py | 1 + src/bentoml/_internal/utils/buildx.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/bentoml/_internal/container/base.py b/src/bentoml/_internal/container/base.py index 7bd22b5d7b..5a2d0c6ef6 100644 --- a/src/bentoml/_internal/container/base.py +++ b/src/bentoml/_internal/container/base.py @@ -49,6 +49,7 @@ def construct_args(self, args: t.Any, opt: str = ""): @construct_args.register(type(None)) @construct_args.register(tuple) + @construct_args.register(list) def _(self, args: ArgType, opt: str = ""): if args is not None: self.extend( diff --git a/src/bentoml/_internal/utils/buildx.py b/src/bentoml/_internal/utils/buildx.py index fe13f2c2b6..008852ccd4 100644 --- a/src/bentoml/_internal/utils/buildx.py +++ b/src/bentoml/_internal/utils/buildx.py @@ -30,5 +30,9 @@ def health(): def build(**kwargs: t.Any): # subprocess_env from bentoctl will be handle by buildx, so it is safe to pop this out. kwargs.pop("subprocess_env") + kwargs["tag"] = kwargs.pop("tags") context_path = kwargs.pop("cwd", None) + for key, value in kwargs.items(): + if not value: + kwargs[key] = None _buildx_backend.build(context_path=context_path, **kwargs) From 6a4250fd2736c1572919e95cbd7d609c3818a2f7 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Tue, 6 Dec 2022 18:35:38 -0800 Subject: [PATCH 3/3] chore: add shim for bentoml_cli Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> --- src/bentoml_cli/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bentoml_cli/utils.py b/src/bentoml_cli/utils.py index 9eb7ee4ccf..7a9c14383a 100644 --- a/src/bentoml_cli/utils.py +++ b/src/bentoml_cli/utils.py @@ -114,6 +114,16 @@ def validate_container_tag( raise BentoMLException(f"Invalid tag type. Got {type(tag)}") +# NOTE: shim for bentoctl +def validate_docker_tag( + ctx: Context, param: Parameter, tag: str | tuple[str] | None +) -> str | tuple[str] | None: + logger.warning( + "'validate_docker_tag' is now deprecated, use 'validate_container_tag' instead." + ) + return validate_container_tag(ctx, param, tag) + + class BentoMLCommandGroup(click.Group): """ Click command class customized for BentoML CLI, allow specifying a default