From cc38007b04acfba42fe3262f4a6b849170093757 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Tue, 6 Dec 2022 19:06:31 -0800 Subject: [PATCH] chore: provides shim for bentoctl (#3322) this shim should only be used by bentoctl. The shim will be here until bentoctl uses public API. --- src/bentoml/_internal/bento/gen.py | 39 +++++++++++++++++++++ src/bentoml/_internal/container/base.py | 1 + src/bentoml/_internal/container/generate.py | 2 +- src/bentoml/_internal/utils/buildx.py | 38 ++++++++++++++++++++ src/bentoml_cli/utils.py | 10 ++++++ 5 files changed, 89 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 00000000000..333abfa9b93 --- /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/base.py b/src/bentoml/_internal/container/base.py index 7bd22b5d7bf..5a2d0c6ef61 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/container/generate.py b/src/bentoml/_internal/container/generate.py index 7180b14439f..738f9e508ba 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 00000000000..008852ccd42 --- /dev/null +++ b/src/bentoml/_internal/utils/buildx.py @@ -0,0 +1,38 @@ +""" +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") + 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) diff --git a/src/bentoml_cli/utils.py b/src/bentoml_cli/utils.py index 9eb7ee4ccf8..7a9c14383a8 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