In TrueFoundry workflow you can pass the dockerfile path in the task config, this is useful when you want to install a binary and use it in your python function task like using a jq command, etc.
In this guide, we will see how to write a Python function task with a dockerfile. In this example, we will take a string as an input and then will calculate the SHA56 hash from the input. We will be passing the
Before you proceed with the guide, make sure you have the following:
TrueFoundry CLI: Set up and configure the TrueFoundry CLI tool on your local machine by following the Setup for CLI guide.
Workspace: To deploy your workflow, you’ll need a workspace. If you don’t have one, you can create it using this guide: Creating a Workspace or seek assistance from your cluster administrator.
Create a workflow.py where we will write the code for our workflow and place it in the project root directory with your Dockerfile.Your directory structure will then appear as follows:
Copy
Ask AI
.├── workflow.py└── Dockerfile
Dockerfile
Copy
Ask AI
# Use an official Python runtime as a parent imageFROM python:3.10-slim# Install jq binaryRUN apt-get update && apt-get install -y jq# Set the working directoryWORKDIR /appRUN pip install truefoundry[workflow]==0.4.8# Copy the current directory contents into the containerCOPY . /app# Set the default command to run PythonCMD ["python"]
workflow.py
Copy
Ask AI
from truefoundry.workflow import task, workflow, PythonTaskConfig, TaskDockerFileBuildfrom truefoundry.deploy import Resourcestask_config = PythonTaskConfig( image=TaskDockerFileBuild( dockerfile_path="Dockerfile", ), resources=Resources(cpu_request=0.45))@task(task_config=task_config)def run_jq(input_json: str) -> str: import subprocess # Run the jq binary using Python's subprocess module process = subprocess.run( ["jq", "."], # jq command to pretty-print JSON input=input_json, text=True, capture_output=True, ) return process.stdout@workflowdef my_workflow(input_json: str) -> str: return run_jq(input_json=input_json)
As you can see, we have given the dockerfile_path argument in PythonTaskConfig where the path to the docker file is used as its value.
Now run the below command in the terminal to deploy your workflow, replace <workfspace-fqn> with the workspace fqn which you can find on the UI.