Skip to content

Commit

Permalink
fix(entrypoint): backward compatibility with yatai<1.0.0 (#2953)
Browse files Browse the repository at this point in the history
tested with yatai v0.4.6-e40c427
  • Loading branch information
bojiang committed Aug 30, 2022
1 parent 3de0c9a commit 03a2b31
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
9 changes: 8 additions & 1 deletion bentoml/_internal/bento/docker/entrypoint.sh
Expand Up @@ -10,8 +10,15 @@ _is_sourced() {
}

_main() {
# for backwards compatibility with the yatai<1.0.0, adapting the old "yatai" command to the new "start" command
if [ "${#}" -gt 0 ] && [ "${1}" = 'python' ] && [ "${2}" = '-m' ] && ([ "${3}" = 'bentoml._internal.server.cli.runner' ] || [ "${3}" = "bentoml._internal.server.cli.api_server" ]); then
if [ "${3}" = 'bentoml._internal.server.cli.runner' ]; then
set -- bentoml start-runner-server "${@:4}"
elif [ "${3}" = 'bentoml._internal.server.cli.api_server' ]; then
set -- bentoml start-http-server "${@:4}"
fi
# if no arg or first arg looks like a flag
if [ -z "$@" ] || [ "${1:0:1}" = '-' ]; then
elif [ -z "$@" ] || [ "${1:0:1}" = '-' ]; then
if [[ -v BENTOML_SERVE_COMPONENT ]]; then
echo "\$BENTOML_SERVE_COMPONENT is set! Calling 'bentoml start-*' instead"
if [ "${BENTOML_SERVE_COMPONENT}" = 'http_server' ]; then
Expand Down
52 changes: 49 additions & 3 deletions bentoml_cli/start.py
@@ -1,7 +1,9 @@
from __future__ import annotations

import sys
import json
import logging
from urllib.parse import urlparse

import click

Expand All @@ -19,8 +21,22 @@ def add_start_command(cli: click.Group) -> None:
"--remote-runner",
type=click.STRING,
multiple=True,
envvar="BENTOML_SERVE_REMOTE_RUNNER",
help="list of runners map",
)
@click.option(
"--runner-map",
type=click.STRING,
envvar="BENTOML_SERVE_RUNNER_MAP",
help="JSON string of runners map",
help="[Deprecated] use --remote-runner instead. "
"JSON string of runners map. For backword compatibility for yatai < 1.0.0",
)
@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",
Expand Down Expand Up @@ -96,6 +112,8 @@ def add_start_command(cli: click.Group) -> None:
def start_http_server( # type: ignore (unused warning)
bento: str,
remote_runner: list[str] | None,
runner_map: str | None,
bind: str | None,
port: int,
host: str,
backlog: int,
Expand All @@ -114,11 +132,25 @@ def start_http_server( # type: ignore (unused warning)

from bentoml.start import start_http_server

runner_map = dict([s.split("=", maxsplit=2) for s in remote_runner or []])
if remote_runner:
runner_map_dict = dict(
[s.split("=", maxsplit=2) for s in remote_runner or []]
)
elif runner_map:
runner_map_dict = json.loads(runner_map)
else:
runner_map_dict = {}

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

logger.info(" Using remote runners: %s", runner_map)
start_http_server(
bento,
runner_map=runner_map,
runner_map=runner_map_dict,
working_dir=working_dir,
port=port,
host=host,
Expand All @@ -141,6 +173,13 @@ def start_http_server( # type: ignore (unused warning)
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,
Expand Down Expand Up @@ -173,6 +212,7 @@ def start_http_server( # type: ignore (unused warning)
def start_runner_server( # type: ignore (unused warning)
bento: str,
runner_name: str,
bind: str | None,
port: int,
host: str,
backlog: int,
Expand All @@ -184,6 +224,12 @@ def start_runner_server( # type: ignore (unused warning)

from bentoml.start import start_runner_server

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(
bento,
runner_name=runner_name,
Expand Down

0 comments on commit 03a2b31

Please sign in to comment.