jolly-florist-66728
09/11/2024, 12:47 PMContainerTask 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:
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:
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()jolly-florist-66728
09/11/2024, 12:47 PM>>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.