diff --git a/src/bentoml/_internal/cloud/deployment.py b/src/bentoml/_internal/cloud/deployment.py index 4b5fc43e843..81e0ab66cfd 100644 --- a/src/bentoml/_internal/cloud/deployment.py +++ b/src/bentoml/_internal/cloud/deployment.py @@ -699,7 +699,7 @@ def _init_deployment_files( for fn in files: full_path = os.path.join(root, fn) rel_path = os.path.relpath(full_path, bento_dir) - if not bento_spec.includes(full_path) and rel_path != "bentofile.yaml": + if not bento_spec.includes(rel_path) and rel_path != "bentofile.yaml": continue if rel_path == REQUIREMENTS_TXT: continue @@ -735,9 +735,10 @@ def watch(self, bento_dir: str) -> None: def watch_filter(change: watchfiles.Change, path: str) -> bool: if not default_filter(change, path): return False - if os.path.relpath(path, bento_dir) in ("bentofile.yaml", REQUIREMENTS_TXT): + rel_path = os.path.relpath(path, bento_dir) + if rel_path in ("bentofile.yaml", REQUIREMENTS_TXT): return True - return bento_spec.includes(path) + return bento_spec.includes(rel_path) console = Console(highlight=False) bento_info = ensure_bento( @@ -1169,19 +1170,32 @@ def get(self, name: str, cluster: str | None = None) -> Deployment: res = self._client.v2.get_deployment(name, cluster) return self._generate_deployment_info_(res, res.urls) - def terminate(self, name: str, cluster: str | None = None) -> Deployment: + def terminate( + self, name: str, cluster: str | None = None, wait: bool = False + ) -> Deployment: """ Terminate a deployment. Args: name: The name of the deployment. cluster: The name of the cluster. + wait: Whether to wait for the deployment to be terminated. Returns: The DeploymentInfo object. """ res = self._client.v2.terminate_deployment(name, cluster) - return self._generate_deployment_info_(res, res.urls) + deployment = self._generate_deployment_info_(res, res.urls) + if wait: + console = rich.get_console() + status = deployment.get_status(False).status + with console.status( + f"Waiting for deployment to terminate, current_status: [green]{status}[/]" + ): + while status != DeploymentStatus.Terminated.value: + time.sleep(1) + status = deployment.get_status(True).status + return deployment def delete(self, name: str, cluster: str | None = None) -> None: """ diff --git a/src/bentoml/deployment.py b/src/bentoml/deployment.py index 5db21025343..abe592d80cf 100644 --- a/src/bentoml/deployment.py +++ b/src/bentoml/deployment.py @@ -268,9 +268,10 @@ def get( def terminate( name: str, cluster: str | None = None, + wait: bool = False, _cloud_client: BentoCloudClient = Provide[BentoMLContainer.bentocloud_client], ) -> Deployment: - return _cloud_client.deployment.terminate(name=name, cluster=cluster) + return _cloud_client.deployment.terminate(name=name, cluster=cluster, wait=wait) @inject diff --git a/src/bentoml_cli/deployment.py b/src/bentoml_cli/deployment.py index 3024942fd63..e75314c8ab9 100644 --- a/src/bentoml_cli/deployment.py +++ b/src/bentoml_cli/deployment.py @@ -692,11 +692,12 @@ def get( # type: ignore type=click.STRING, required=True, ) +@click.option("--wait", is_flag=True, help="Wait for the deployment to be terminated") def terminate( # type: ignore - name: str, cluster: str | None + name: str, cluster: str | None, wait: bool ) -> None: """Terminate a deployment on BentoCloud.""" - bentoml.deployment.terminate(name, cluster=cluster) + bentoml.deployment.terminate(name, cluster=cluster, wait=wait) rich.print(f"Deployment [green]'{name}'[/] terminated successfully.")