New RunLLM response generated: >>>*# Question* I ...
# runllm-flyte-trial
j
New RunLLM response generated: >>>*# Question* I wondered if there is a way to define the docker image of as task as an parameter in a workflow. Or even better to define the pod_template (we also have a sidecar container that we want to specify) of a task on workflow level. Background is that we want to say: please use this version of the docker image (which has the software version that we want to test) in this specific run. Next run we want to execute another docker image (version of our software). What I tried is this, but this seems not to work: # Answer To define the Docker image of a task as a parameter in a workflow, you can use a custom class derived from
ContainerTask
that includes the Docker image tag as an input. This allows you to override the default image when launching the workflow. For specifying the
pod_template
at the workflow level, you can use the
pod_template
argument in the
@task
decorator. Here's an example of how to achieve this: 1. Custom ContainerTask with Docker Image Parameter:
Copy code
from flytekit import ContainerTask, workflow, kwtypes, Resources
   from typing import Optional, Any

   class CustomContainerTask(ContainerTask):
       def __init__(
           self,
           requests: Optional[Resources] = None,
           limits: Optional[Resources] = None,
           docker_image_tag: str = "latest",
           **kwargs: Any,
       ):
           super().__init__(
               name="custom_container_task",
               input_data_dir="/var/inputs",
               output_data_dir="/var/outputs",
               inputs=kwtypes(file1=str, file2=str),
               image=f"your_registry_url:{docker_image_tag}",
               requests=requests,
               limits=limits,
               command=["/bin/sh", "-c"],
               arguments=[" ".join(kwargs.get("arguments", []))],
               **kwargs,
           )

   @workflow
   def wf(docker_image_tag: str):
       task = CustomContainerTask(docker_image_tag=docker_image_tag)
       task(file1="input1.txt", file2="input2.txt")
2. Using
pod_template
in Task
:
Copy code
from flytekit import task, workflow, Resources
   from flytekitplugins.pod import Pod
   from kubernetes.client.models import V1PodSpec, V1Container

   pod_template = Pod(
       pod_spec=V1PodSpec(
           containers=[
               V1Container(
                   name="main",
                   image="your_image:latest",
                   args=["--help"]
               ),
               V1Container(
                   name="sidecar",
                   image="sidecar_image:latest",
                   args=["--sidecar"]
               ),
           ]
       )
   )

   @task(pod_template=pod_template, requests=Resources(cpu="2", mem="4Gi"))
   def my_task():
       print("Running task with custom pod template")

   @workflow
   def wf():
       my_task()
>>
For more details, refer to the Flytekit documentation and Flyte discussion. Would you like more detail on any specific part? Sources: - Flytekit Kubernetes Pod Plugin - Flyte Discussion on ContainerTask Slack Link https://flyte-org.slack.com/archives/CP2HDHKE1/p1726058835.217219 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.