Skip to content

Commit

Permalink
fix: trigger reset when system package changes
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Oct 16, 2024
1 parent 026771b commit cee4059
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/bentoml/_internal/cloud/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def list_files(self) -> DeploymentFileListSchema:

def _init_deployment_files(
self, bento_dir: str, spinner: Spinner, timeout: int = 600
) -> str:
) -> tuple[str, str]:
from ..bento.build_config import BentoPathSpec

check_interval = 5
Expand Down Expand Up @@ -770,9 +770,11 @@ def _init_deployment_files(
if requirements_md5 != pod_files.get(REQUIREMENTS_TXT, ""):
upload_files.append((REQUIREMENTS_TXT, requirements_content))
setup_script = _build_setup_script(bento_dir, build_config)
upload_files.append(("setup.sh", setup_script))
setup_md5 = hashlib.md5(setup_script).hexdigest()
if setup_md5 != pod_files.get("setup.sh", ""):
upload_files.append(("setup.sh", setup_script))
self.upload_files(upload_files, console=console)
return requirements_md5
return requirements_md5, setup_md5

def watch(self, bento_dir: str) -> None:
import watchfiles
Expand All @@ -788,7 +790,7 @@ def watch(self, bento_dir: str) -> None:
build_config.include, build_config.exclude, bento_dir
)
requirements_hash: str | None = None

setup_md5: str | None = None
default_filter = watchfiles.filters.DefaultFilter()
is_editable = is_editable_bentoml()
bentoml_project = str(Path(source_locations("bentoml")).parent.parent)
Expand All @@ -806,6 +808,7 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
return rel_path in (
"bentofile.yaml",
REQUIREMENTS_TXT,
"setup.sh",
) or bento_spec.includes(rel_path)

console = Console(highlight=False)
Expand Down Expand Up @@ -833,7 +836,8 @@ def is_bento_changed(bento_info: Bento) -> bool:
return True

spinner = Spinner(console=console)
needs_update = is_bento_changed(bento_info)
bento_changed = is_bento_changed(bento_info)
needs_update = False
spinner.log(f"💻 View Dashboard: {self.admin_console}")
endpoint_url: str | None = None
try:
Expand All @@ -842,10 +846,11 @@ def is_bento_changed(bento_info: Bento) -> bool:
"Dummy upload task", visible=False
)
while True:
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
if needs_update or bento_changed:
if bento_changed:
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
spinner.update("🔄 Updating deployment with new configuration")
update_config = DeploymentConfigParameters(
bento=str(bento_info.tag),
Expand All @@ -857,12 +862,12 @@ def is_bento_changed(bento_info: Bento) -> bool:
update_config.verify()
self = deployment_api.update(update_config)
target = self._refetch_target(False)
requirements_hash = self._init_deployment_files(
requirements_hash, setup_md5 = self._init_deployment_files(
bento_dir, spinner=spinner
)
needs_update = False
elif not requirements_hash:
requirements_hash = self._init_deployment_files(
needs_update = bento_changed = False
elif not requirements_hash or not setup_md5:
requirements_hash, setup_md5 = self._init_deployment_files(
bento_dir, spinner=spinner
)
if endpoint_url is None:
Expand Down Expand Up @@ -892,7 +897,7 @@ def is_bento_changed(bento_info: Bento) -> bool:
assert isinstance(bento_info, Bento)
if is_bento_changed(bento_info):
# stop log tail and reset the deployment
needs_update = True
bento_changed = True
break

build_config = get_bento_build_config(bento_dir)
Expand All @@ -917,7 +922,14 @@ def is_bento_changed(bento_info: Bento) -> bool:
upload_files.append((rel_path, open(path, "rb").read()))
else:
delete_files.append(rel_path)

setup_script = _build_setup_script(bento_dir, build_config)
if (
new_hash := hashlib.md5(setup_script).hexdigest()
!= setup_md5
):
setup_md5 = new_hash
needs_update = True
break
requirements_content = _build_requirements_txt(
bento_dir, build_config
)
Expand Down

0 comments on commit cee4059

Please sign in to comment.