Skip to content

Commit

Permalink
Check envd version before building images (#2122)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw authored Jan 23, 2024
1 parent cba830e commit 0006b01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 14 additions & 0 deletions flytekit/image_spec/image_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
from abc import abstractmethod
from dataclasses import asdict, dataclass
from functools import lru_cache
from importlib import metadata
from typing import List, Optional, Union

import click
import requests
from packaging.version import Version

from flytekit.exceptions.user import FlyteAssertion

DOCKER_HUB = "docker.io"
_F_IMG_ID = "_F_IMG_ID"
Expand Down Expand Up @@ -206,6 +210,16 @@ def build(cls, image_spec: ImageSpec):
click.secho(f"Image {img_name} not found. Building...", fg="blue")
if image_spec.builder not in cls._REGISTRY:
raise Exception(f"Builder {image_spec.builder} is not registered.")
if image_spec.builder == "envd":
envd_version = metadata.version("envd")
# flytekit v1.10.2+ copies the workflow code to the WorkDir specified in the Dockerfile. However, envd<0.3.39
# overwrites the WorkDir when building the image, resulting in a permission issue when flytekit downloads the file.
if Version(envd_version) < Version("0.3.39"):
raise FlyteAssertion(
f"envd version {envd_version} is not compatible with flytekit>v1.10.2."
f" Please upgrade envd to v0.3.39+."
)

cls._REGISTRY[image_spec.builder].build_image(image_spec)
cls._BUILT_IMAGES.add(img_name)

Expand Down
6 changes: 2 additions & 4 deletions plugins/flytekit-envd/flytekitplugins/envd/image_builder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import os
import pathlib
import shutil
import subprocess
from importlib import metadata

import click
from packaging.version import Version
Expand Down Expand Up @@ -108,9 +108,7 @@ def build():
if image_spec.source_root:
shutil.copytree(image_spec.source_root, pathlib.Path(cfg_path).parent, dirs_exist_ok=True)

version_command = "envd version -s -f json"
envd_version = json.loads(EnvdImageSpecBuilder().execute_command(version_command)[0])["envd"].replace("v", "")

envd_version = metadata.version("envd")
# Indentation is required by envd
if Version(envd_version) <= Version("0.3.37"):
envd_config += ' io.copy(host_path="./", envd_path="/root")'
Expand Down

0 comments on commit 0006b01

Please sign in to comment.