Skip to content

Commit

Permalink
Merge pull request #469 from mystic-ai/matthew/check-turbo-layers
Browse files Browse the repository at this point in the history
Single Layer Turbo Validation
  • Loading branch information
MPCherry committed Jul 18, 2024
2 parents 2f8f775 + 5a889f5 commit 4a9e279
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
13 changes: 12 additions & 1 deletion pipeline/console/container/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]

Expand Down
21 changes: 18 additions & 3 deletions pipeline/console/container/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -100,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
Expand Down Expand Up @@ -148,7 +159,9 @@ 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,
)

new_deployment_request = http.post(
Expand Down Expand Up @@ -183,7 +196,9 @@ 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,
):
resp = docker_client.images.push(
image,
Expand Down
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 = "pipeline-ai"
version = "2.4.0"
version = "2.4.1"
description = "Pipelines for machine learning workloads."
authors = [
"Paul Hetherington <ph@mystic.ai>",
Expand Down

0 comments on commit 4a9e279

Please sign in to comment.