From c22d34fe26f5c5c71c47e9e54265e85fdf54d0ec Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 9 Jan 2025 16:20:41 +0800 Subject: [PATCH] fix: allow building bento without build config file Signed-off-by: Frost Ming --- src/bentoml/bentos.py | 15 +++++++++++---- src/bentoml_cli/bentos.py | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/bentoml/bentos.py b/src/bentoml/bentos.py index 941a29a4454..0dcb5f56736 100644 --- a/src/bentoml/bentos.py +++ b/src/bentoml/bentos.py @@ -376,6 +376,7 @@ def build( def build_bentofile( bentofile: str | None = None, *, + service: str | None = None, version: str | None = None, labels: dict[str, str] | None = None, build_ctx: str | None = None, @@ -405,17 +406,23 @@ def build_bentofile( bentofile = resolve_user_filepath(bentofile, None) except FileNotFoundError: raise InvalidArgument(f'bentofile "{bentofile}" not found') + else: + build_config = BentoBuildConfig.from_file(bentofile) else: for filename in DEFAULT_BENTO_BUILD_FILES: try: bentofile = resolve_user_filepath(filename, build_ctx) - break except FileNotFoundError: pass + else: + build_config = BentoBuildConfig.from_file(bentofile) + break else: - raise InvalidArgument("No bentofile found, please provide a bentofile path") - - build_config = BentoBuildConfig.from_file(bentofile) + if service is None: + raise InvalidArgument( + "No build config file found and no service specified" + ) + build_config = BentoBuildConfig(service=service) if labels: if not build_config.labels: diff --git a/src/bentoml_cli/bentos.py b/src/bentoml_cli/bentos.py index be391b84fd9..847fb93cbb7 100644 --- a/src/bentoml_cli/bentos.py +++ b/src/bentoml_cli/bentos.py @@ -417,8 +417,14 @@ def build( # type: ignore (not accessed) key, label_value = label.split("=", 1) labels_dict[key] = label_value + service: str | None = None + if ":" in build_ctx: + service = build_ctx + build_ctx = "." + bento = build_bentofile( bentofile, + service=service, version=version, labels=labels_dict or None, build_ctx=build_ctx,