Skip to content

Commit

Permalink
fix(cli): add start runner server back (#4479)
Browse files Browse the repository at this point in the history
  • Loading branch information
bojiang committed Feb 3, 2024
1 parent 5db2656 commit e93cb8f
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions src/bentoml_cli/start.py
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
import logging
import os
import sys
Expand Down Expand Up @@ -32,6 +33,13 @@ def add_start_command(cli: click.Group) -> None:
envvar="BENTOML_SERVE_DEPENDS",
help="list of runners map",
)
@click.option(
"--runner-map",
type=click.STRING,
envvar="BENTOML_SERVE_RUNNER_MAP",
help="[Deprecated] use --depends instead. "
"JSON string of runners map. For backword compatibility for yatai < 1.0.0",
)
@click.option(
"--bind",
type=click.STRING,
Expand Down Expand Up @@ -128,6 +136,7 @@ def start_http_server( # type: ignore (unused warning)
bento: str,
service_name: str,
depends: list[str] | None,
runner_map: str | None,
bind: str | None,
port: int,
host: str,
Expand Down Expand Up @@ -158,6 +167,8 @@ def start_http_server( # type: ignore (unused warning)
sys.path.insert(0, working_dir)
if depends:
runner_map_dict = dict([s.split("=", maxsplit=2) for s in depends or []])
elif runner_map:
runner_map_dict = json.loads(runner_map)
else:
runner_map_dict = {}

Expand Down Expand Up @@ -372,3 +383,100 @@ def start_grpc_server( # type: ignore (unused warning)
max_concurrent_streams=max_concurrent_streams,
protocol_version=protocol_version,
)

@cli.command(hidden=True)
@click.argument("bento", type=click.STRING, default=".")
@click.option(
"--runner-name",
type=click.STRING,
required=True,
envvar="BENTOML_SERVE_RUNNER_NAME",
help="specify the runner name to serve",
)
@click.option(
"--bind",
type=click.STRING,
help="[Deprecated] use --host and --port instead."
"Bind address for the server. For backword compatibility for yatai < 1.0.0",
required=False,
)
@click.option(
"--port",
type=click.INT,
default=BentoMLContainer.http.port.get(),
help="The port to listen on for the REST api server",
envvar="BENTOML_PORT",
show_default=True,
)
@click.option(
"--host",
type=click.STRING,
default=BentoMLContainer.http.host.get(),
help="The host to bind for the REST api server [defaults: 127.0.0.1(dev), 0.0.0.0(production)]",
envvar="BENTOML_HOST",
)
@click.option(
"--backlog",
type=click.INT,
default=BentoMLContainer.api_server_config.backlog.get(),
help="The maximum number of pending connections.",
show_default=True,
)
@click.option(
"--working-dir",
type=click.Path(),
help="When loading from source code, specify the directory to find the Service instance",
default=None,
show_default=True,
)
@click.option(
"--timeout",
type=click.INT,
help="Specify the timeout (seconds) for runners",
envvar="BENTOML_TIMEOUT",
)
@add_experimental_docstring
def start_runner_server( # type: ignore (unused warning)
bento: str,
runner_name: str,
bind: str | None,
port: int,
host: str,
backlog: int,
working_dir: str | None,
timeout: int | None,
) -> None:
"""
Start Runner server standalone. Deprecate in 1.2.0
"""
if working_dir is None:
if os.path.isdir(os.path.expanduser(bento)):
working_dir = os.path.expanduser(bento)
else:
working_dir = "."
if sys.path[0] != working_dir:
sys.path.insert(0, working_dir)

if bind is not None:
parsed = urlparse(bind)
assert parsed.scheme == "tcp"
host = parsed.hostname or host
port = parsed.port or port

from bentoml.start import start_runner_server as start_runner_server_impl

if bind is not None:
parsed = urlparse(bind)
assert parsed.scheme == "tcp"
host = parsed.hostname or host
port = parsed.port or port

start_runner_server_impl(
bento,
runner_name=runner_name,
working_dir=working_dir,
timeout=timeout,
port=port,
host=host,
backlog=backlog,
)

0 comments on commit e93cb8f

Please sign in to comment.