From 96c467e14691eb3e956d3b21c05fb724c240fe97 Mon Sep 17 00:00:00 2001 From: Vincent Chen <62143443+mao3267@users.noreply.github.com> Date: Wed, 6 Nov 2024 04:20:55 +0800 Subject: [PATCH] docs: add copy command examples and description (#5782) 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 0e66eadd95..6d992ddb72 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.