From 542aae75b51a241c7d6be0239be689a6c981b4d2 Mon Sep 17 00:00:00 2001 From: mao3267 Date: Fri, 27 Sep 2024 10:09:29 +0800 Subject: [PATCH] docs: add copy command examples and description Signed-off-by: mao3267 --- .../customizing_dependencies/imagespec.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/user_guide/customizing_dependencies/imagespec.md b/docs/user_guide/customizing_dependencies/imagespec.md index d9bf8f24bf..c2d2a833ac 100644 --- a/docs/user_guide/customizing_dependencies/imagespec.md +++ b/docs/user_guide/customizing_dependencies/imagespec.md @@ -175,6 +175,26 @@ image_spec = ImageSpec( ) ``` +## Copy additional files or directories +You can specify files or directories to be copied into the container `/root`, allowing users to access the required files. The directory structure will match the relative path. Since Docker only supports relative paths, absolute paths and paths outside the current working directory (e.g., paths with "../") are not allowed. + +```py +from flytekit.image_spec import ImageSpec +from flytekit import task, workflow + +image_spec = ImageSpec( + name="image_with_copy", + registry="localhost:30000", + builder="default", + copy=["files/input.txt"], +) + +@task(container_image=image_spec) +def my_task() -> str: + with open("/root/files/input.txt", "r") as f: + return f.read() +``` + ## Define ImageSpec in a YAML File You can override the container image by providing an ImageSpec YAML file to the `pyflyte run` or `pyflyte register` command.