Skip to content

Commit

Permalink
fix: allow building bento without build config file (#5175)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored Jan 9, 2025
1 parent b8351fe commit 387e4f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/bentoml/bentos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions src/bentoml_cli/bentos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 387e4f9

Please sign in to comment.