Skip to content

Commit

Permalink
feat: convenient option to rollout new bento (#4051)
Browse files Browse the repository at this point in the history
* feat: convenient option to rollout new bento

Signed-off-by: Frost Ming <me@frostming.com>

* remove unused code

Signed-off-by: Frost Ming <me@frostming.com>

* fix: update

Signed-off-by: Frost Ming <me@frostming.com>

---------

Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed Jul 20, 2023
1 parent fd1fb72 commit 2169ebe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/bentoml/_internal/cloud/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/bentoml/_internal/cloud/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 20 additions & 5 deletions src/bentoml_cli/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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":
Expand Down

0 comments on commit 2169ebe

Please sign in to comment.