Skip to content

Commit

Permalink
feat: envd builder with copy commands
Browse files Browse the repository at this point in the history
Signed-off-by: mao3267 <chenvincent610@gmail.com>
  • Loading branch information
mao3267 committed Sep 27, 2024
1 parent 4e1ea68 commit e151ccf
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions plugins/flytekit-envd/flytekitplugins/envd/image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,46 @@ def build():
else:
envd_config += ' io.copy(source="./", target="/root")\n'

if image_spec.copy:

def add_envd_copy_command(src_path: pathlib.Path, envd_config: str) -> str:
envd_version = metadata.version("envd")
if Version(envd_version) <= Version("0.3.37"):
if src_path.is_dir():
envd_config += (
f' io.copy(host_path="{src_path.as_posix()}", envd_path="/root/{src_path.as_posix()}/")\n'
)
else:
envd_config += (
f' io.copy(source="{src_path.as_posix()}", target="/root/{src_path.parent.as_posix()}/")\n'
)
else:
if src_path.is_dir():
envd_config += (
f' io.copy(host_path="{src_path.as_posix()}", envd_path="/root/{src_path.as_posix()}/")\n'
)
else:
envd_config += (
f' io.copy(source="{src_path.as_posix()}", target="/root/{src_path.parent.as_posix()}/")\n'
)
return envd_config

for src in image_spec.copy:
src_path = pathlib.Path(src)

if src_path.is_absolute() or ".." in src_path.parts:
raise ValueError("Absolute paths or paths with '..' are not allowed in COPY command.")

dst_path = pathlib.Path(cfg_path).parent / src_path
dst_path.parent.mkdir(parents=True, exist_ok=True)

if src_path.is_dir():
shutil.copytree(src_path, dst_path, dirs_exist_ok=True)
else:
shutil.copy(src_path, dst_path)

envd_config = add_envd_copy_command(src_path, envd_config)

with open(cfg_path, "w+") as f:
f.write(envd_config)

Expand Down

0 comments on commit e151ccf

Please sign in to comment.