Skip to content

Commit

Permalink
fix: with_defaults for docker option and show diff report for bento m…
Browse files Browse the repository at this point in the history
…anifest comparison (#4996)

* fix: with_defaults for docker option

Signed-off-by: Frost Ming <[email protected]>

* fix: compare bento with pretty diff

Signed-off-by: Frost Ming <[email protected]>

---------

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Sep 24, 2024
1 parent 0aa4afc commit 6778331
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/bentoml/_internal/bento/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def __attrs_post_init__(self):
)

def with_defaults(
self, default_envs: list[dict[str, str]] | None = None
self, default_envs: list[BentoEnvSchema] | None = None
) -> DockerOptions:
# Convert from user provided options to actual build options with default values
defaults: t.Dict[str, t.Any] = {}
Expand All @@ -223,7 +223,7 @@ def with_defaults(
defaults["python_version"] = python_version

if self.env is None and default_envs:
defaults["env"] = {e["name"]: e.get("value", "") for e in default_envs}
defaults["env"] = {e.name: e.value for e in default_envs}

return attr.evolve(self, **defaults)

Expand Down
33 changes: 23 additions & 10 deletions src/bentoml/_internal/cloud/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ def watch(self, bento_dir: str) -> None:
from ..bento.build_config import BentoPathSpec
from .bento import BentoAPI

bento_dir = os.path.abspath(bento_dir)
build_config = get_bento_build_config(bento_dir)
deployment_api = DeploymentAPI(self._client)
bento_api = BentoAPI(self._client)
Expand Down Expand Up @@ -812,18 +813,32 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
assert isinstance(bento_info, Bento)
target = self._refetch_target(False)

def is_bento_changed(bento_info: Bento) -> bool:
if target is None or target.bento is None:
return True
bento_manifest = bento_info.get_manifest()
if target.bento.manifest == bento_manifest:
return False
try:
from deepdiff import DeepDiff
except ModuleNotFoundError:
pass
else:
diff = DeepDiff(
target.bento.manifest, bento_manifest, ignore_order=True
)
console.print(f"[blue]{diff.pretty()}[/]")
return True

spinner = Spinner(console=console)
needs_update = is_bento_changed(bento_info)
try:
spinner.start()
upload_id = spinner.transmission_progress.add_task(
"Dummy upload task", visible=False
)
while True:
if (
target is None
or target.bento is None
or target.bento.manifest != bento_info.get_manifest()
):
if needs_update:
console.print("✨ [green bold]Bento change detected[/]")
spinner.update("🔄 Pushing Bento to BentoCloud")
bento_api._do_push_bento(bento_info, upload_id, bare=True) # type: ignore
Expand All @@ -841,6 +856,7 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
requirements_hash = self._init_deployment_files(
bento_dir, spinner=spinner
)
needs_update = False
elif not requirements_hash:
requirements_hash = self._init_deployment_files(
bento_dir, spinner=spinner
Expand All @@ -861,12 +877,9 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
_client=self._client,
)
assert isinstance(bento_info, Bento)
if (
target is None
or target.bento is None
or target.bento.manifest != bento_info.get_manifest()
):
if is_bento_changed(bento_info):
# stop log tail and reset the deployment
needs_update = True
break

build_config = get_bento_build_config(bento_dir)
Expand Down

0 comments on commit 6778331

Please sign in to comment.