Skip to content

Commit

Permalink
Merge commit '95de11a' into bola/build-configure-script
Browse files Browse the repository at this point in the history
  • Loading branch information
bolasim committed Mar 1, 2024
2 parents 54b9726 + 95de11a commit 82a2e3f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "truss"
version = "0.10.0rc0"
version = "0.10.0rc1"
description = "A seamless bridge from model development to model delivery"
license = "MIT"
readme = "README.md"
Expand Down
17 changes: 13 additions & 4 deletions truss/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from truss.remote.remote_cli import inquire_model_name, inquire_remote_name
from truss.remote.remote_factory import USER_TRUSSRC_PATH, RemoteFactory
from truss.truss_config import Build, ModelServer
from truss.truss_handle import TrussHandle

logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -166,8 +167,14 @@ def build(target_directory: str, build_dir: Path, tag) -> None:
@click.option(
"--attach", is_flag=True, default=False, help="Flag for attaching the process"
)
@click.option(
"--cache/--no-cache",
is_flag=True,
default=True,
help="Flag for caching build or not",
)
@error_handling
def run(target_directory: str, build_dir: Path, tag, port, attach) -> None:
def run(target_directory: str, build_dir: Path, tag, port, attach, cache) -> None:
"""
Runs the docker image for a Truss.
Expand All @@ -183,7 +190,9 @@ def run(target_directory: str, build_dir: Path, tag, port, attach) -> None:
click.confirm(
f"Container already exists at {urls}. Are you sure you want to continue?"
)
tr.docker_run(build_dir=build_dir, tag=tag, local_port=port, detach=not attach)
tr.docker_run(
build_dir=build_dir, tag=tag, local_port=port, detach=not attach, cache=cache
)


@truss_cli.command()
Expand Down Expand Up @@ -446,7 +455,7 @@ def predict(
def push(
target_directory: str,
remote: str,
model_name: str,
model_name: Optional[str],
publish: bool = False,
trusted: bool = False,
promote: bool = False,
Expand Down Expand Up @@ -584,7 +593,7 @@ def cleanup() -> None:
truss.build.cleanup()


def _get_truss_from_directory(target_directory: Optional[str] = None):
def _get_truss_from_directory(target_directory: Optional[str] = None) -> TrussHandle:
"""Gets Truss from directory. If none, use the current directory"""
if target_directory is None:
target_directory = os.getcwd()
Expand Down
5 changes: 3 additions & 2 deletions truss/contexts/image_builder/serving_image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,11 @@ def prepare_image_build_dir(
data_dir = build_dir / config.data_dir # type: ignore[operator]

def copy_into_build_dir(from_path: Path, path_in_build_dir: str):
copy_tree_or_file(from_path, build_dir / path_in_build_dir) # type: ignore[operator]
# using default ignore patterns ignores the `build` dir in truss
copy_tree_or_file(from_path, build_dir / path_in_build_dir, ignore_files=False) # type: ignore[operator]

# Copy truss package from the context builder image to build dir
copy_into_build_dir(TRUSS_PACKAGE_DIR, "./truss")
copy_into_build_dir(TRUSS_PACKAGE_DIR, "truss/")
copy_into_build_dir(
TRUSS_PACKAGE_DIR.parent / "pyproject.toml", "./pyproject.toml"
)
Expand Down
5 changes: 3 additions & 2 deletions truss/truss_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def docker_run(
patch_ping_url: Optional[str] = None,
wait_for_server_ready: bool = True,
network: Optional[str] = None,
cache: bool = True,
):
"""
Builds a docker image and runs it as a container. For control trusses,
Expand All @@ -185,7 +186,7 @@ def docker_run(
container = container_if_patched
else:
image = self.build_serving_docker_image(
build_dir=build_dir, tag=tag, network=network
build_dir=build_dir, tag=tag, network=network, cache=cache
)
secrets_mount_dir_path = _prepare_secrets_mount_dir()
publish_ports = [[local_port, INFERENCE_SERVER_PORT]]
Expand Down Expand Up @@ -854,7 +855,7 @@ def _build_image(
network: Optional[str] = None,
):
image = _docker_image_from_labels(labels=labels)
if image is not None:
if cache and image is not None:
return image

build_dir_path = Path(build_dir) if build_dir is not None else None
Expand Down
17 changes: 12 additions & 5 deletions truss/util/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
FIXED_TRUSS_IGNORE_PATH = Path(__file__).parent / ".truss_ignore"


def copy_tree_path(src: Path, dest: Path, ignore_patterns: List[str] = []) -> None:
def copy_tree_path(
src: Path, dest: Path, ignore_patterns: List[str] = [], ignore_files: bool = True
) -> None:
"""Copy a directory tree, ignoring files specified in .truss_ignore."""
patterns = load_trussignore_patterns()
patterns.extend(ignore_patterns)
if ignore_files:
patterns = load_trussignore_patterns()
patterns.extend(ignore_patterns)
else:
patterns = []

if not dest.exists():
dest.mkdir(parents=True)
Expand All @@ -40,11 +45,13 @@ def copy_file_path(src: Path, dest: Path) -> Tuple[str, str]:
return copy_file(str(src), str(dest), verbose=False)


def copy_tree_or_file(src: Path, dest: Path) -> Union[List[str], Tuple[str, str]]:
def copy_tree_or_file(
src: Path, dest: Path, ignore_files: bool = True
) -> Union[List[str], Tuple[str, str]]:
if src.is_file():
return copy_file_path(src, dest)

return copy_tree_path(src, dest) # type: ignore
return copy_tree_path(src, dest, ignore_files=ignore_files) # type: ignore


def remove_tree_path(target: Path) -> None:
Expand Down

0 comments on commit 82a2e3f

Please sign in to comment.