Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Commit

Permalink
fix: copy models to bento directory (#210)
Browse files Browse the repository at this point in the history
* chore: switch to PDM

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

* automated release workflow

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

* ignore certain patterns

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

* fix lint errors

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

* fix: copy models to bento dir

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

---------

Signed-off-by: Frost Ming <me@frostming.com>
Co-authored-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
frostming and aarnphm committed Jul 22, 2023
1 parent fdb8fae commit e1b572a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
6 changes: 3 additions & 3 deletions bentoctl/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

logger = logging.getLogger(__name__)
try:
from bentoml_cli.utils import validate_docker_tag
from bentoml_cli.utils import validate_container_tag
except ImportError:
logger.warning(
"'bentoml._internal.utils.docker.validate_tag' not imported. "
"Validation dissabled."
)
validate_docker_tag = None
validate_container_tag = None


CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
Expand Down Expand Up @@ -143,7 +143,7 @@ def generate(deployment_config_file, values_only, save_path):
"--docker-image-tag",
help="Name and optionally a tag (format: 'name:tag'), defaults to bento tag.",
required=False,
callback=validate_docker_tag,
callback=validate_container_tag,
multiple=True,
)
@click.option(
Expand Down
28 changes: 22 additions & 6 deletions bentoctl/deployment_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
import logging
import os
import typing as t
from contextlib import contextmanager
from pathlib import Path

import bentoml
import cerberus
import fs
import fs.mirror
import yaml
from bentoml import Bento
from bentoml.exceptions import NotFound
from bentoml.models import get as get_model

from bentoctl.exceptions import (
BentoNotFound,
Expand Down Expand Up @@ -241,6 +244,18 @@ def generate(self, destination_dir=os.curdir, values_only=False):

return generated_files

@contextmanager
def _prepare_bento_dir(self) -> t.Generator[str, None, None]:
assert self.bento is not None
with fs.open_fs("temp://") as temp_fs, fs.open_fs(self.bento.path) as bento_fs:
fs.mirror.mirror(bento_fs, temp_fs)
models_fs = temp_fs.makedirs("models", recreate=True)
for model_info in self.bento.info.models:
model = get_model(model_info.tag)
model_fs = models_fs.makedirs(model_info.tag.path())
fs.mirror.mirror(model.path, model_fs)
yield temp_fs.getsyspath("/")

def create_deployable(self, destination_dir=os.curdir) -> str:
"""
Creates the deployable in the destination_dir and returns
Expand All @@ -249,12 +264,13 @@ def create_deployable(self, destination_dir=os.curdir) -> str:
# NOTE: In the case of debug mode, we want to keep the deployable
# for debugging purpose. So by setting overwrite_deployable to false,
# we don't delete the deployable after the build.
return self.operator.create_deployable(
bento_path=self.bento.path,
destination_dir=destination_dir,
bento_metadata=get_bento_metadata(self.bento.path),
overwrite_deployable=not is_debug_mode(),
)
with self._prepare_bento_dir() as bento_path:
return self.operator.create_deployable(
bento_path=bento_path,
destination_dir=destination_dir,
bento_metadata=get_bento_metadata(bento_path),
overwrite_deployable=not is_debug_mode(),
)

def create_repository(self):
(
Expand Down
16 changes: 9 additions & 7 deletions bentoctl/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import OrderedDict

import docker
from bentoml._internal.utils import buildx
from bentoml import container
from rich.live import Live

from bentoctl.console import console
Expand Down Expand Up @@ -78,12 +78,12 @@ def generate_deployable_container(
console.print(
f"In debug mode. Intermediate bento saved to [b]{dist_dir}[/b]"
)
env = {"DOCKER_BUILDKIT": "1", "DOCKER_SCAN_SUGGEST": "false"}
buildx_args = {
"subprocess_env": env,
"cwd": deployment_config.create_deployable(destination_dir=str(dist_dir)),
"context_path": deployment_config.create_deployable(
destination_dir=str(dist_dir)
),
"file": DOCKERFILE_PATH,
"tags": tags,
"tag": tags,
"add_host": None,
"allow": allow,
"build_args": build_args,
Expand Down Expand Up @@ -112,10 +112,12 @@ def generate_deployable_container(
"target": target,
"ulimit": None,
}
buildx_args = {k: v or None for k, v in buildx_args.items()}

# run health check whether buildx is install locally
buildx.health()
buildx.build(**buildx_args)
container.health("buildx")
backend = container.get_backend("buildx")
backend.build(**buildx_args)


def tag_docker_image(image_name, image_tag):
Expand Down

0 comments on commit e1b572a

Please sign in to comment.