diff --git a/src/domino/cli/cli.py b/src/domino/cli/cli.py index bdc2a899..76c4c5a3 100644 --- a/src/domino/cli/cli.py +++ b/src/domino/cli/cli.py @@ -276,9 +276,14 @@ def cli_create_piece_repository(name, container_registry): default="", help='The base url for this Pieces repository.' ) -def cli_organize_pieces_repository(build_images, source_url): +@click.option( + '--tag-overwrite', + default="", + help='Overwrite tag for release.' +) +def cli_organize_pieces_repository(build_images: bool, source_url: str, tag_overwrite: str): """Organize Pieces repository.""" - pieces_repository.organize_pieces_repository(build_images, source_url) + pieces_repository.organize_pieces_repository(build_images, source_url, tag_overwrite) @click.command() diff --git a/src/domino/cli/utils/pieces_repository.py b/src/domino/cli/utils/pieces_repository.py index 23fdcac2..370a0923 100644 --- a/src/domino/cli/utils/pieces_repository.py +++ b/src/domino/cli/utils/pieces_repository.py @@ -243,11 +243,11 @@ def create_pieces_repository(repository_name: str, container_registry: str) -> N console.print("") -def create_compiled_pieces_metadata(source_url: str = None) -> None: +def create_compiled_pieces_metadata(source_url: str | None = None) -> None: """ Create compiled metadata from Pieces metadata.json files and include input_schema generated from models.py """ - from domino.scripts.load_piece import load_piece_models_from_path, load_piece_class_from_path + from domino.scripts.load_piece import load_piece_models_from_path from domino.utils.metadata_default import metadata_default pieces_path = Path(".") / "pieces" @@ -345,14 +345,14 @@ def create_dependencies_map(save_map_as_file: bool = True) -> None: json.dump(pieces_images_map, outfile, indent=4, cls=SetEncoder) -def build_docker_images() -> None: +def build_docker_images(tag_overwrite: str | None = None) -> None: """ Convenience function to build Docker images from the repository dependencies and publish them to Docker Hub """ from domino.scripts.build_docker_images_pieces import build_images_from_pieces_repository console.print("Building Docker images and generating map file...") - updated_dependencies_map = build_images_from_pieces_repository() + updated_dependencies_map = build_images_from_pieces_repository(tag_overwrite=tag_overwrite) return updated_dependencies_map @@ -384,7 +384,11 @@ def validate_repo_name(repo_name: str) -> None: raise ValueError("Repository name should not contain special characters") -def organize_pieces_repository(build_images: bool, source_url: str) -> None: +def organize_pieces_repository( + build_images: bool, + source_url: str, + tag_overwrite: str | None = None +) -> None: """ Organize Piece's repository for Domino. This will: - validate the folder structure, and create the pieces compiled_metadata.json and dependencies_map.json files @@ -400,9 +404,15 @@ def organize_pieces_repository(build_images: bool, source_url: str) -> None: # Load config with open("config.toml", "rb") as f: repo_config = tomli.load(f) + + # Validate repository name repo_name = repo_config["repository"]["REPOSITORY_NAME"] validate_repo_name(repo_name) + # Tag overwrite + if tag_overwrite: + repo_config["repository"]["VERSION"] = tag_overwrite + # Create compiled metadata from Pieces metadata.json files and add data input schema create_compiled_pieces_metadata(source_url=source_url) @@ -412,7 +422,7 @@ def organize_pieces_repository(build_images: bool, source_url: str) -> None: # Build and publish the images if build_images: - updated_dependencies_map = build_docker_images() + updated_dependencies_map = build_docker_images(tag_overwrite=tag_overwrite) map_file_path = Path(".") / ".domino/dependencies_map.json" with open(map_file_path, "w") as outfile: json.dump(updated_dependencies_map, outfile, indent=4) diff --git a/src/domino/scripts/build_docker_images_pieces.py b/src/domino/scripts/build_docker_images_pieces.py index 4334901e..b20ab69d 100644 --- a/src/domino/scripts/build_docker_images_pieces.py +++ b/src/domino/scripts/build_docker_images_pieces.py @@ -13,7 +13,6 @@ def publish_image(source_image_name: str): client = docker.from_env() - print(f"Publishing docker image: {source_image_name}") print(Style.RESET_ALL + Style.DIM, end='') try: @@ -28,9 +27,10 @@ def publish_image(source_image_name: str): print(response, end='') print(Style.RESET_ALL + Fore.BLUE + f"Finished publishing: {source_image_name}") + def build_image_from_tmp_dockerfile( - source_image_name: str, - path: str = ".", + source_image_name: str, + path: str = ".", dockerfile: str = "Dockerfile-tmp" ): client = docker.from_env() @@ -56,7 +56,7 @@ def build_image_from_tmp_dockerfile( (Path(path) / dockerfile).unlink() -def build_images_from_pieces_repository(): +def build_images_from_pieces_repository(tag_overwrite: str | None = None): """ Each dependencies group will need to have its own Docker image built and published to be used by Domino. This is because the Pieces source code goes baked in the images. @@ -67,14 +67,15 @@ def build_images_from_pieces_repository(): # Get information from config.toml file with open(config_path, "rb") as f: - config_dict = tomli.load(f) - docker_image_repository = config_dict.get("repository").get("REPOSITORY_NAME") - docker_image_version = config_dict.get("repository").get("VERSION") + repo_config = tomli.load(f).get("repository", {}) - #if publish: - github_container_registry_name = f'ghcr.io/{config_dict.get("repository").get("REGISTRY_NAME")}'.lower() - # else: - # github_container_registry_name = f'local' + # Tag overwrite + if tag_overwrite: + repo_config["VERSION"] = tag_overwrite + + docker_image_repository = repo_config.get("REPOSITORY_NAME") + docker_image_version = repo_config.get("VERSION") + github_container_registry_name = f'ghcr.io/{repo_config.get("REGISTRY_NAME")}'.lower() # Load dependencies_map.json file with open(domino_path / "dependencies_map.json", "r") as f: @@ -90,7 +91,7 @@ def build_images_from_pieces_repository(): # If no extra dependency, use base Pod image and just copy the Pieces source code if not any([dependency_dockerfile, dependency_requirements]): pieces_dependencies_map[group]["source_image"] = source_image_name - dockerfile_str = f"""FROM ghcr.io/tauffer-consulting/domino-base-piece:latest + dockerfile_str = """FROM ghcr.io/tauffer-consulting/domino-base-piece:latest COPY config.toml domino/pieces_repository/ COPY pieces domino/pieces_repository/pieces COPY .domino domino/pieces_repository/.domino