Skip to content

Commit

Permalink
fix: enable image spec by default (#5197)
Browse files Browse the repository at this point in the history
* fix: enable image spec by default

Signed-off-by: Frost Ming <[email protected]>

* fix: add no_image switch

Signed-off-by: Frost Ming <[email protected]>

* fix: handle HEAD

Signed-off-by: Frost Ming <[email protected]>

* fix: no editable

Signed-off-by: Frost Ming <[email protected]>

* fix: remove SETUPTOOLS_USE_DISTUTILS

Signed-off-by: Frost Ming <[email protected]>

* fix: resolve user path

Signed-off-by: Frost Ming <[email protected]>

* fix: disable image

Signed-off-by: Frost Ming <[email protected]>

* fix: set env

Signed-off-by: Frost Ming <[email protected]>

* fix: don't enable image for legacy service

Signed-off-by: Frost Ming <[email protected]>

* remove editable

Signed-off-by: Frost Ming <[email protected]>

---------

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Jan 23, 2025
1 parent e802584 commit a6ab447
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"context": "..",
"containerEnv": {
"BENTOML_DEBUG": "True",
"BENTOML_BUNDLE_LOCAL_BUILD": "True",
"SETUPTOOLS_USE_DISTUTILS": "stdlib"
"BENTOML_BUNDLE_LOCAL_BUILD": "True"
},
"runArgs": ["--init"],
"mounts": [
Expand Down
10 changes: 8 additions & 2 deletions src/_bentoml_sdk/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ def system_packages(self, *packages: str) -> t.Self:
return self


def get_image_from_build_config(build_config: BentoBuildConfig) -> Image | None:
def get_image_from_build_config(
build_config: BentoBuildConfig, build_ctx: str
) -> Image | None:
from bentoml._internal.utils.filesystem import resolve_user_filepath

if not build_config.conda.is_empty():
logger.warning(
"conda options are not supported by bento v2, fallback to bento v1"
Expand Down Expand Up @@ -243,7 +247,9 @@ def get_image_from_build_config(build_config: BentoBuildConfig) -> Image | None:
*(f"--find-links {link}" for link in python_options.find_links)
)
if python_options.requirements_txt:
image.requirements_file(python_options.requirements_txt)
image.requirements_file(
resolve_user_filepath(python_options.requirements_txt, build_ctx)
)
if python_options.packages:
image.python_packages(*python_options.packages)
return image
6 changes: 3 additions & 3 deletions src/bentoml/_internal/bento/bento.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ def create(
if build_ctx is None
else os.path.realpath(os.path.expanduser(build_ctx))
)
enable_image = "bento_image" in enabled_features
if not os.path.isdir(build_ctx):
raise InvalidArgument(
f"Bento build context {build_ctx} does not exist or is not a directory."
Expand All @@ -266,6 +265,7 @@ def create(
is_legacy = isinstance(svc, Service)
# Apply default build options
image: Image | None = None
disable_image = "no_image" in enabled_features or is_legacy

if isinstance(svc, Service):
# for < 1.2
Expand All @@ -283,8 +283,8 @@ def create(
build_config.envs.extend(svc.envs)
if svc.image is not None:
image = svc.image
if image is None and enable_image:
image = get_image_from_build_config(build_config)
if image is None and not disable_image:
image = get_image_from_build_config(build_config, build_ctx)
build_config = build_config.with_defaults()
tag = Tag(bento_name, version)
if version is None:
Expand Down
21 changes: 15 additions & 6 deletions src/bentoml/_internal/utils/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,24 @@ def get_local_bentoml_dependency() -> str:
).strip()
except subprocess.CalledProcessError:
branch_name = "main"

try:
remote = subprocess.check_output(
["git", "config", "--get", f"branch.{branch_name}.remote"],
# Precise checkout only returns "HEAD" as branch name
if branch_name == "HEAD":
ref = subprocess.check_output(
["git", "rev-parse", "HEAD"],
cwd=src_dir,
text=True,
).strip()
except subprocess.CalledProcessError:
remote = "origin"
else:
ref = branch_name
try:
remote = subprocess.check_output(
["git", "config", "--get", f"branch.{branch_name}.remote"],
cwd=src_dir,
text=True,
).strip()
except subprocess.CalledProcessError:
remote = "origin"

try:
remote_url = subprocess.check_output(
Expand All @@ -78,4 +87,4 @@ def get_local_bentoml_dependency() -> str:
except subprocess.CalledProcessError:
remote_url = DEFAULT_BENTOML_GIT_URL

return f"git+{remote_url}@{branch_name}"
return f"git+{remote_url}@{ref}"
2 changes: 0 additions & 2 deletions src/bentoml/testing/pytest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def pytest_sessionstart(session: Session) -> None:
session,
("PROMETHEUS_MULTIPROC_DIR", _PYTEST_MULTIPROC_DIR),
("BENTOML_BUNDLE_LOCAL_BUILD", "True"),
("SETUPTOOLS_USE_DISTUTILS", "stdlib"),
("__BENTOML_DEBUG_USAGE", "False"),
("BENTOML_DO_NOT_TRACK", "True"),
)
Expand All @@ -247,7 +246,6 @@ def pytest_sessionfinish(session: Session, exitstatus: int | ExitCode) -> None:
session,
"BENTOML_BUNDLE_LOCAL_BUILD",
"PROMETHEUS_MULTIPROC_DIR",
"SETUPTOOLS_USE_DISTUTILS",
"__BENTOML_DEBUG_USAGE",
"BENTOML_DO_NOT_TRACK",
)
Expand Down
4 changes: 2 additions & 2 deletions src/bentoml/testing/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def run_bento_server_distributed(
path = bento_service.path
with open(os.path.join(path, "bento.yaml"), "r", encoding="utf-8") as f:
bentofile = yaml.safe_load(f)
for runner in bentofile["runners"]:
for runner in bentofile.get("runners", []):
with reserve_free_port(enable_so_reuseport=use_grpc) as port:
runner_map[runner["name"]] = f"tcp://127.0.0.1:{port}"
cmd = [
Expand Down Expand Up @@ -363,7 +363,7 @@ def run_bento_server_distributed(
)
runner_args = [
("--depends", f"{runner['name']}={runner_map[runner['name']]}")
for runner in bentofile["runners"]
for runner in bentofile.get("runners", [])
]
cmd = [
sys.executable,
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/bento_new_sdk/test_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_local_prediction(examples: Path) -> None:


def test_build_and_prediction(examples: Path) -> None:
bento = bentoml.bentos.build(
bento = bentoml.build(
"service.py:Summarization", build_ctx=str(examples / "quickstart")
)

Expand Down

0 comments on commit a6ab447

Please sign in to comment.