Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow building bento without build config file #5175

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading