nutritious-rocket-28038
08/28/2025, 7:26 PMfrom flytekit import ContainerTask, kwtypes, FlyteDirectory
produce_data = ContainerTask(
name="produce_data",
image="alpine:3.18",
command=["sh", "-c"],
arguments=[
# Important: write to the output path that Flyte provides
"mkdir -p /var/flyte/output/results && echo 'hello' > /var/flyte/output/results/hello.txt"
],
output_data_dir="/var/flyte/output", # :white_check_mark: ensures Flyte watches this dir
outputs=kwtypes(results=FlyteDirectory),
)
ancient-wolf-19325
08/28/2025, 7:26 PMancient-wolf-19325
08/28/2025, 7:27 PMnutritious-rocket-28038
08/29/2025, 12:30 AMancient-wolf-19325
08/29/2025, 12:30 AMancient-wolf-19325
08/29/2025, 12:30 AMfrom flytekit import task, workflow, ImageSpec
from flytekit.types.directory import FlyteDirectory
image_spec = ImageSpec(
base_image="alpine:3.18",
packages=["flytekit"], # Ensure flytekit is installed in the image
)
@task(container_image=image_spec)
def produce_data() -> FlyteDirectory:
import os
out_dir = "/tmp/results"
os.makedirs(out_dir, exist_ok=True)
with open(os.path.join(out_dir, "hello.txt"), "w") as f:
f.write("hello")
return FlyteDirectory(path=out_dir)
This approach avoids the limitations of raw ContainerTask output handling for FlyteDirectory, as Flytekit manages the data movement. See issue #3632 for more discussion.
Would you like a full workflow example or more details on customizing the image?
Sources:
- Issue #3632: workaround using Python task and ImageSpec 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.nutritious-rocket-28038
08/29/2025, 12:31 AMancient-wolf-19325
08/29/2025, 12:31 AMancient-wolf-19325
08/29/2025, 12:32 AMnutritious-rocket-28038
08/29/2025, 12:34 AMancient-wolf-19325
08/29/2025, 12:34 AMancient-wolf-19325
08/29/2025, 12:34 AM