Skip to content

Commit b3b659f

Browse files
authored
fix: allow usage like bentoml deploy service:MyService (#5181)
* fix: allow usage like bentoml deploy service:MyService Signed-off-by: Frost Ming <[email protected]>
1 parent e8e9011 commit b3b659f

File tree

1 file changed

+43
-28
lines changed

1 file changed

+43
-28
lines changed

src/bentoml/_internal/cloud/deployment.py

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,16 @@ def ensure_bento(
336336
_bento_store: BentoStore = Provide[BentoMLContainer.bento_store],
337337
_client: RestApiClient = Provide[BentoMLContainer.rest_api_client],
338338
) -> Bento | BentoManifestSchema:
339+
from bentoml.bentos import build_bentofile
340+
339341
from .bento import BentoAPI
340342

343+
if not project_path and not bento:
344+
raise BentoMLException(
345+
"Creating a deployment needs a target; project path or bento is necessary"
346+
)
341347
bento_api = BentoAPI(_client)
342348
if project_path:
343-
from bentoml.bentos import build_bentofile
344-
345349
bento_obj = build_bentofile(
346350
build_ctx=project_path, bare=bare, _bento_store=_bento_store, reload=reload
347351
)
@@ -350,37 +354,48 @@ def ensure_bento(
350354
if push:
351355
bento_api.push(bento=bento_obj, bare=bare)
352356
return bento_obj
353-
elif bento:
354-
bento = Tag.from_taglike(bento)
355-
try:
356-
bento_obj = _bento_store.get(bento)
357-
except NotFound:
358-
bento_obj = None
357+
assert bento is not None
358+
bento_tag = Tag.from_taglike(bento)
359+
try:
360+
bento_obj = _bento_store.get(bento_tag)
361+
except NotFound:
362+
bento_obj = None
363+
364+
# try to get from bentocloud
365+
try:
366+
bento_schema = bento_api.get(name=bento_tag.name, version=bento_tag.version)
367+
except NotFound:
368+
bento_schema = None
369+
370+
if bento_obj is not None:
371+
# push to bentocloud
372+
if push:
373+
bento_api.push(bento=bento_obj, bare=bare)
374+
return bento_obj
375+
if bento_schema is not None:
376+
assert bento_schema.manifest is not None
377+
if cli:
378+
rich.print(
379+
f"[bold blue]Using bento [green]{bento_tag}[/] from bentocloud to deploy"
380+
)
381+
bento_schema.manifest.version = bento_tag.version
382+
return bento_schema.manifest
359383

360-
# try to get from bentocloud
384+
# bento is a service definition
385+
if isinstance(bento, str):
361386
try:
362-
bento_schema = bento_api.get(name=bento.name, version=bento.version)
363-
except NotFound:
364-
bento_schema = None
365-
366-
if bento_obj is not None:
367-
# push to bentocloud
387+
bento_obj = build_bentofile(
388+
service=bento, bare=bare, _bento_store=_bento_store, reload=reload
389+
)
390+
except BentoMLException:
391+
pass
392+
else:
393+
if cli:
394+
rich.print(f":bento: Built bento [green]{bento_obj.info.tag}[/]")
368395
if push:
369396
bento_api.push(bento=bento_obj, bare=bare)
370397
return bento_obj
371-
if bento_schema is not None:
372-
assert bento_schema.manifest is not None
373-
if cli:
374-
rich.print(
375-
f"[bold blue]Using bento [green]{bento.name}:{bento.version}[/] from bentocloud to deploy"
376-
)
377-
bento_schema.manifest.version = bento.version
378-
return bento_schema.manifest
379-
raise NotFound(f"bento {bento} not found in both local and cloud")
380-
else:
381-
raise BentoMLException(
382-
"Create a deployment needs a target; project path or bento is necessary"
383-
)
398+
raise NotFound(f"Bento {bento} is not found in both local and bentocloud")
384399

385400

386401
@attr.define

0 commit comments

Comments
 (0)