From 39a72063c819f1cf89f6724f69c644000d4cb465 Mon Sep 17 00:00:00 2001 From: Matthew Cherry Date: Thu, 18 Jul 2024 11:23:22 +0000 Subject: [PATCH 1/3] Check for singe layeer turbo registry images --- pipeline/console/container/build.py | 13 ++++++++++++- pipeline/console/container/push.py | 23 ++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/pipeline/console/container/build.py b/pipeline/console/container/build.py index 4f850447..15497700 100644 --- a/pipeline/console/container/build.py +++ b/pipeline/console/container/build.py @@ -25,7 +25,10 @@ def build_container(namespace: Namespace): pipeline_config = PipelineConfig.parse_obj(pipeline_config_yaml) - if pipeline_config.extras and pipeline_config.extras.get("turbo_registry", False): + turbo_registry = pipeline_config.extras and pipeline_config.extras.get( + "turbo_registry", False + ) + if turbo_registry: template = docker_templates.turbo_registry_template if not pipeline_config.runtime: @@ -83,6 +86,14 @@ def build_container(namespace: Namespace): docker_client = docker.from_env() new_container = docker_client.images.get(docker_image_id) + if turbo_registry: + if len(new_container.attrs["RootFS"]["Layers"]) > 1: + _print( + f"Turbo registry image built with multiple layers, this will cause issues with cold start optimization. Please contact Mystic support at support@mystic.ai", # noqa + "ERROR", + ) + raise Exception("Failed to build") + created_image_full_id = new_container.id.split(":")[1] created_image_short_id = created_image_full_id[:12] diff --git a/pipeline/console/container/push.py b/pipeline/console/container/push.py index efec1f92..031fe737 100644 --- a/pipeline/console/container/push.py +++ b/pipeline/console/container/push.py @@ -87,7 +87,10 @@ def push_container(namespace: Namespace): docker_client: docker.DockerClient = docker.from_env(timeout=600) registry_params = {} - if pipeline_config.extras and pipeline_config.extras.get("turbo_registry", False): + turbo_registry = pipeline_config.extras and pipeline_config.extras.get( + "turbo_registry", False + ) + if turbo_registry: registry_params["turbo_registry"] = "yes" registry_info = http.get(endpoint="/v4/registry", params=registry_params) @@ -148,7 +151,10 @@ def push_container(namespace: Namespace): pipeline_name = true_pipeline_name _push_docker_image( - docker_client=docker_client, image=image_to_push_reg, upload_token=upload_token + docker_client=docker_client, + image=image_to_push_reg, + upload_token=upload_token, + turbo_registry=turbo_registry, ) new_deployment_request = http.post( @@ -183,8 +189,19 @@ def push_container(namespace: Namespace): def _push_docker_image( - docker_client: docker.DockerClient, image: str, upload_token: str + docker_client: docker.DockerClient, + image: str, + upload_token: str, + turbo_registry: bool, ): + inspect = docker_client.images.get(image) + if turbo_registry: + if len(inspect.attrs["RootFS"]["Layers"]) > 1: + _print( + f"Turbo registry image contains multiple layers, this will cause issues with cold start optimization. Please contact Mystic support at support@mystic.ai", # noqa + "ERROR", + ) + raise Exception("Failed to push") resp = docker_client.images.push( image, stream=True, From 4d6d0f49a4ae2bcfd706efffa6c0789b3eeef769 Mon Sep 17 00:00:00 2001 From: Matthew Cherry Date: Thu, 18 Jul 2024 11:30:15 +0000 Subject: [PATCH 2/3] Refactor --- pipeline/console/container/push.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pipeline/console/container/push.py b/pipeline/console/container/push.py index 031fe737..9f53a296 100644 --- a/pipeline/console/container/push.py +++ b/pipeline/console/container/push.py @@ -103,6 +103,14 @@ def push_container(namespace: Namespace): image = docker_client.images.get(pipeline_name) image_hash = image.id.split(":")[1] + if turbo_registry: + if len(image.attrs["RootFS"]["Layers"]) > 1: + _print( + f"Turbo registry image contains multiple layers, this will cause issues with cold start optimization. Please contact Mystic support at support@mystic.ai", # noqa + "ERROR", + ) + raise Exception("Failed to push") + hash_tag = image_hash[:12] image_to_push = pipeline_name + ":" + hash_tag image_to_push_reg = upload_registry + "/" + image_to_push @@ -154,7 +162,6 @@ def push_container(namespace: Namespace): docker_client=docker_client, image=image_to_push_reg, upload_token=upload_token, - turbo_registry=turbo_registry, ) new_deployment_request = http.post( @@ -192,16 +199,7 @@ def _push_docker_image( docker_client: docker.DockerClient, image: str, upload_token: str, - turbo_registry: bool, ): - inspect = docker_client.images.get(image) - if turbo_registry: - if len(inspect.attrs["RootFS"]["Layers"]) > 1: - _print( - f"Turbo registry image contains multiple layers, this will cause issues with cold start optimization. Please contact Mystic support at support@mystic.ai", # noqa - "ERROR", - ) - raise Exception("Failed to push") resp = docker_client.images.push( image, stream=True, From 5a889f50cfc0880e77784139a3152e1d5fa5876c Mon Sep 17 00:00:00 2001 From: Matthew Cherry Date: Thu, 18 Jul 2024 11:31:18 +0000 Subject: [PATCH 3/3] VB --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3aa0f6f8..bc930ea0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pipeline-ai" -version = "2.4.0" +version = "2.4.1" description = "Pipelines for machine learning workloads." authors = [ "Paul Hetherington ",