diff --git a/pyproject.toml b/pyproject.toml index c27c4d3a0..8e3950ae4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/truss/cli/cli.py b/truss/cli/cli.py index 25fabe1d7..74f46b2ee 100644 --- a/truss/cli/cli.py +++ b/truss/cli/cli.py @@ -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) @@ -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. @@ -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() @@ -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, @@ -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() diff --git a/truss/contexts/image_builder/serving_image_builder.py b/truss/contexts/image_builder/serving_image_builder.py index 4a6f32eed..5adce5a38 100644 --- a/truss/contexts/image_builder/serving_image_builder.py +++ b/truss/contexts/image_builder/serving_image_builder.py @@ -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" ) diff --git a/truss/truss_handle.py b/truss/truss_handle.py index e21caaa31..3b4bea8ec 100644 --- a/truss/truss_handle.py +++ b/truss/truss_handle.py @@ -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, @@ -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]] @@ -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 diff --git a/truss/util/path.py b/truss/util/path.py index 7e302cdb4..47d4efa84 100644 --- a/truss/util/path.py +++ b/truss/util/path.py @@ -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) @@ -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: