Skip to content

Commit

Permalink
fix: set default bento server host to localhost in dev mode (#2137)
Browse files Browse the repository at this point in the history
* set default dev server host to localhost

* increase max cli help message width

* fix sklearn module name

* bento build message
  • Loading branch information
parano committed Dec 22, 2021
1 parent 5fd8823 commit 30edb7b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 32 deletions.
2 changes: 1 addition & 1 deletion bentoml/_internal/bento/docker/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN ./env/docker/init.sh user_setup_script
# copy over all remaining bento files
COPY --chown=bentoml:bentoml . ./

# Default port for BentoML Service
# Default port for BentoServer
EXPOSE 5000

USER bentoml
Expand Down
54 changes: 29 additions & 25 deletions bentoml/_internal/cli/bento_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import typing as t
import logging

import click
Expand All @@ -7,16 +8,13 @@

logger = logging.getLogger(__name__)

DEFAULT_DEV_SERVER_HOST = "127.0.0.1"
DEFAULT_RELAOD_DELAY = 0.25


def add_serve_command(cli) -> None:
@cli.command()
@click.argument("bento", type=click.STRING)
@click.option(
"--working-dir",
type=click.Path(),
help="Look for Service in the specified directory",
default=".",
)
@click.option(
"--production",
type=click.BOOL,
Expand All @@ -28,18 +26,17 @@ def add_serve_command(cli) -> None:
@click.option(
"--port",
type=click.INT,
default=BentoServerContainer.config.port.get(),
default=BentoServerContainer.service_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=BentoServerContainer.config.host.get(),
help="The host to bind for the REST api server",
default=None,
help="The host to bind for the REST api server [defaults: 127.0.0.1(dev), 0.0.0.0(production)]",
envvar="BENTOML_HOST",
show_default=True,
)
@click.option(
"--backlog",
Expand All @@ -52,35 +49,42 @@ def add_serve_command(cli) -> None:
"--reload",
type=click.BOOL,
is_flag=True,
help="Reload Service when code changes detected, this is only available in development mode.",
help="Reload Service when code changes detected, this is only available in development mode",
default=False,
show_default=True,
)
@click.option(
"--reload-delay",
type=click.FLOAT,
help="Delay in seconds between each check if the Service needs to be reloaded. Default is 0.25.",
help="Delay in seconds between each check if the Service needs to be reloaded",
show_default=True,
default=DEFAULT_RELAOD_DELAY,
)
@click.option(
"--working-dir",
type=click.Path(),
help="When loading from source code, specify the directory to find the Service instance",
default=".",
show_default=True,
default=0.25,
)
@click.option(
"--run-with-ngrok", # legacy option
"--ngrok",
is_flag=True,
default=False,
help="Use ngrok to relay traffic on a public endpoint to the local BentoServer, this is only available in development mode.",
help="Use ngrok to relay traffic on a public endpoint to the local BentoServer, only available in dev mode",
show_default=True,
)
def serve(
bento,
working_dir,
port,
host,
backlog,
reload,
reload_delay,
run_with_ngrok,
production,
bento: str,
production: bool,
port: int,
host: t.Optional[str],
backlog: int,
reload: bool,
reload_delay: float,
working_dir: str,
run_with_ngrok: bool,
) -> None:
"""Start BentoServer from BENTO
Expand Down Expand Up @@ -118,7 +122,7 @@ def serve(
bento,
working_dir=working_dir,
port=port,
host=host,
host=BentoServerContainer.service_host if host is None else host,
backlog=backlog,
)
else:
Expand All @@ -129,7 +133,7 @@ def serve(
working_dir=working_dir,
with_ngrok=run_with_ngrok,
port=port,
host=host,
host=DEFAULT_DEV_SERVER_HOST if host is None else host,
reload=reload,
reload_delay=reload_delay,
)
14 changes: 11 additions & 3 deletions bentoml/_internal/cli/click_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,30 @@ class BentoMLCommandGroup(click.Group):

@staticmethod
def bentoml_common_params(func):
"""Must update NUMBER_OF_COMMON_PARAMS above when adding or removing common CLI
parameters here
"""

@click.option(
"-q",
"--quiet",
is_flag=True,
default=False,
help="Hide all warnings and info logs",
help="Suppress all warnings and info logs",
)
@click.option(
"--verbose",
"--debug",
is_flag=True,
default=False,
help="Show debug logs when running the command",
help="Generate debug information",
)
@click.option(
"--do-not-track",
is_flag=True,
default=False,
envvar="BENTOML_DO_NOT_TRACK",
help="Do not track usage when running this command",
help="Do not send usage info",
)
@click.option(
"--config",
Expand Down Expand Up @@ -155,6 +159,10 @@ def wrapper(*args, **kwargs):
return wrapper

def command(self, *args, **kwargs):
if "context_settings" not in kwargs:
kwargs["context_settings"] = {}
kwargs["context_settings"]["max_content_width"] = 120

def wrapper(func):
# add common parameters to command
func = BentoMLCommandGroup.bentoml_common_params(func)
Expand Down
2 changes: 1 addition & 1 deletion bentoml/_internal/configuration/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def access_control_options(
config.workers,
)
service_port = config.port
service_host = providers.Static[str]("0.0.0.0")
service_host = config.host
forward_host = providers.Static[str]("localhost")
forward_port = providers.SingletonFactory[int](get_free_port)
prometheus_lock = providers.SingletonFactory["SyncLock"](multiprocessing.Lock)
Expand Down
2 changes: 1 addition & 1 deletion bentoml/_internal/frameworks/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def save(

_model = Model.create(
name,
module=__name__,
module=MODULE_NAME,
metadata=metadata,
context=context,
)
Expand Down
13 changes: 12 additions & 1 deletion bentoml/bentos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from simple_di import inject
from simple_di import Provide

from .exceptions import InvalidArgument
from bentoml.exceptions import InvalidArgument

from ._internal.bento import Bento
from ._internal.types import Tag
from ._internal.utils import resolve_user_filepath
Expand Down Expand Up @@ -197,6 +198,16 @@ def build_bentofile(
build_ctx=build_ctx,
model_store=_model_store,
).save(_bento_store)
logger.info(
"""
██████╗░███████╗███╗░░██╗████████╗░█████╗░███╗░░░███╗██╗░░░░░
██╔══██╗██╔════╝████╗░██║╚══██╔══╝██╔══██╗████╗░████║██║░░░░░
██████╦╝█████╗░░██╔██╗██║░░░██║░░░██║░░██║██╔████╔██║██║░░░░░
██╔══██╗██╔══╝░░██║╚████║░░░██║░░░██║░░██║██║╚██╔╝██║██║░░░░░
██████╦╝███████╗██║░╚███║░░░██║░░░╚█████╔╝██║░╚═╝░██║███████╗
╚═════╝░╚══════╝╚═╝░░╚══╝░░░╚═╝░░░░╚════╝░╚═╝░░░░░╚═╝╚══════╝
"""
)
logger.info('Successfully built %s at "%s"', bento, bento.path)
return bento

Expand Down

0 comments on commit 30edb7b

Please sign in to comment.