New RunLLM response generated: >>>*# Question* Ho...
# runllm-flyte-trial
j
New RunLLM response generated: >>>*# Question* Hola I am running a workflow which should use custom image which specify but it using flyte default base image what is the reason can you please help this is my workflow from flytekit import task, workflow #from flytekitplugins.pod import PodTemplate from flytekit import workflow, task, PodTemplate from kubernetes.client import V1PodSpec, V1Container, V1SecurityContext, V1ResourceRequirements, V1VolumeMount, V1SecurityContext import subprocess from flytekitplugins.pod.task import Pod, PodFunctionTask from flytekit import task, workflow, dynamic from flytekit import PodTemplate, Resources import time import os def get_hardcoded_pod_spec() -> V1PodSpec: custom_image = "amorapprendido/flyte-gcld-dock-kube:v2" container = V1Container( name="custom-container", image=custom_image, ) pod_spec = V1PodSpec( containers=[container], restart_policy="OnFailure", security_context=V1SecurityContext(privileged=True) ) return pod_spec @task( task_config=Pod(pod_spec=get_hardcoded_pod_spec(), primary_container_name="custom-container") ) def hardcoded_pod_task() -> str: print("Hello from the task!") time.sleep(190) print("sleep complete") # Running the gsutil command and capturing the output # result = subprocess.run( # ['docker', 'images'], # check=True, # Ensures the command raises an error if it fails # capture_output=True, # Captures stdout and stderr # text=True # Returns output as a string # ) # Print the captured output # print("Subprocess output:", result.stdout.strip()) return "This is a hardcoded task running in a custom container!" @workflow def main_hardcoded_pod_workflow() -> str: return hardcoded_pod_task() # Answer The issue you're encountering is likely due to the way Flyte handles the
container_image
parameter in the task decorator. According to Flyte documentation, specifying the
container_image
directly in the task decorator is necessary to ensure that the custom image is used. Here's how you can modify your task to ensure it uses the custom image: 1. Specify
container_image
in the task decorator
: Add the
container_image
parameter to the task decorator to explicitly set the custom image.
>>```
from flytekit import task, workflow from flytekitplugins.pod.task import Pod from kubernetes.client import V1PodSpec, V1Container, V1SecurityContext import time def get_hardcoded_pod_spec() -> V1PodSpec: custom_image = "amorapprendido/flyte-gcld-dock-kube:v2" container = V1Container( name="custom-container", image=custom_image, ) pod_spec = V1PodSpec( containers=[container], restart_policy="OnFailure", security_context=V1SecurityContext(privileged=True) ) return pod_spec @task( task_config=Pod(pod_spec=get_hardcoded_pod_spec(), primary_container_name="custom-container"), container_image="amorapprendido/flyte-gcld-dock-kube:v2" ) def hardcoded_pod_task() -> str: print("Hello from the task!") time.sleep(190) print("sleep complete") return "This is a hardcoded task running in a custom container!" @workflow def main_hardcoded_pod_workflow() -> str: return hardcoded_pod_task() ``` By adding
container_image="amorapprendido/flyte-gcld-dock-kube:v2"
to the task decorator, you ensure that Flyte uses your specified custom image instead of the default Flyte image. Would you like more details on this or any other aspect of Flyte? Sources: - Flyte Documentation on Multiple Containers Slack Link https://.slack.com/archives/CP2HDHKE1/p1727469293.362139 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.