From 2169ebe9bc74e3d89ceba5dda8f8e1b85f08efa5 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 20 Jul 2023 12:07:52 +0800 Subject: [PATCH] feat: convenient option to rollout new bento (#4051) * feat: convenient option to rollout new bento Signed-off-by: Frost Ming * remove unused code Signed-off-by: Frost Ming * fix: update Signed-off-by: Frost Ming --------- Signed-off-by: Frost Ming --- src/bentoml/_internal/cloud/deployment.py | 9 +++++++- src/bentoml/_internal/cloud/schemas.py | 1 + src/bentoml_cli/deployment.py | 25 ++++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/bentoml/_internal/cloud/deployment.py b/src/bentoml/_internal/cloud/deployment.py index 1850cbbc4c1..ba043f80843 100644 --- a/src/bentoml/_internal/cloud/deployment.py +++ b/src/bentoml/_internal/cloud/deployment.py @@ -175,7 +175,10 @@ def update( context: str | None = None, labels: dict[str, str] | None = None, canary_rules: t.List[DeploymentTargetCanaryRule] | None = None, + latest_bento: bool = False, ) -> DeploymentSchema: + from bentoml import get as get_bento + if mode is None: mode = DeploymentMode.Function if type is None: @@ -197,8 +200,12 @@ def update( if bento is None: # NOTE: bento.repository.name is the bento.name, and bento.name is the bento.version # from bentocloud to bentoml.Tag concept - bento = f"{deployment_target.bento.repository.name}:{deployment_target.bento.name}" + bento = deployment_target.bento.repository.name bento = Tag.from_taglike(bento) + if latest_bento and bento.version is None or bento.version == "latest": + bento = get_bento(bento).tag + elif bento.version is None: + bento.version = deployment_target.bento.name updated_config = bentoml_cattr.unstructure(deployment_target.config) if hpa_conf is not None: diff --git a/src/bentoml/_internal/cloud/schemas.py b/src/bentoml/_internal/cloud/schemas.py index a44384cd2b4..d31b303fe24 100644 --- a/src/bentoml/_internal/cloud/schemas.py +++ b/src/bentoml/_internal/cloud/schemas.py @@ -557,6 +557,7 @@ class DeploymentTargetConfig: runners: t.Optional[t.Dict[str, DeploymentTargetRunnerConfig]] = attr.field( default=None ) + access_control: t.Optional[str] = attr.field(default=None) enable_ingress: t.Optional[bool] = attr.field(default=None) # false for enables enable_stealing_traffic_debug_mode: t.Optional[bool] = attr.field(default=None) enable_debug_mode: t.Optional[bool] = attr.field(default=None) diff --git a/src/bentoml_cli/deployment.py b/src/bentoml_cli/deployment.py index 62d72cd6d34..3cd475f7e72 100644 --- a/src/bentoml_cli/deployment.py +++ b/src/bentoml_cli/deployment.py @@ -99,12 +99,16 @@ def create( # type: ignore type=click.File(), help="JSON file path for the deployment configuration", ) + @click.option("-n", "--name", type=click.STRING, help="Deployment name") + @click.option("--bento", type=click.STRING, help="Bento tag") @click.option( "--context", type=click.STRING, default=None, help="Yatai context name." ) @output_option def update( # type: ignore - file: str, + file: str | None, + name: str | None, + bento: str | None, context: str, output: t.Literal["json", "default"], ) -> DeploymentSchema: @@ -114,10 +118,21 @@ def update( # type: ignore A deployment can be updated using a json file with needed configurations. The json file has the exact format as the one on BentoCloud Deployment UI. """ - res = client.deployment.update_from_file( - path_or_stream=file, - context=context, - ) + if file is not None: + if name is not None: + click.echo("Reading from file, ignoring --name", err=True) + res = client.deployment.update_from_file( + path_or_stream=file, + context=context, + ) + elif name is not None: + res = client.deployment.update( + name, bento=bento, context=context, latest_bento=True + ) + else: + raise click.BadArgumentUsage( + "Either --file or --name is required for update command" + ) if output == "default": console.print(res) elif output == "json":