ImageSpec
During the development cycle you will want to be able to run your workflows both locally on your machine and remotely on Union.ai, so you will need to ensure that the required dependencies are installed in both environments.
Here we will explain how to set up the dependencies for your workflow to run remotely on Union.ai. For information on how to make your dependencies available locally, see Local dependencies.
When a workflow is deployed to Union.ai, each task is set up to run in its own container in the Kubernetes cluster.
You specify the dependencies as part of the definition of the container image to be used for each task using the ImageSpec class.
For example::
import union
image_spec = union.ImageSpec(
name="say-hello-image",
requirements="uv.lock",
)
@union.task(container_image=image_spec)
def say_hello(name: str) -> str:
return f"Hello, {name}!"
@union.workflow
def hello_world_wf(name: str = "world") -> str:
greeting = say_hello(name=name)
return greetingHere, the ImageSpec class is used to specify the container image to be used for the say_hello task.
-
The
nameparameter specifies the name of the image. This name will be used to identify the image in the container registry. -
The
requirementsparameter specifies the path to a file (relative to the directory in which theunion runorunion registercommand is invoked) that specifies the dependencies to be installed in the image. The file may be:- A
requirements.txtfile. - A
uv.lockfile generated by theuv synccommand. - A
poetry.lockfile generated by thepoetry installcommand. - A
pyproject.tomlfile.
- A
When you execute the union run or union register command, Union.ai will build the container image defined in ImageSpec block
(as well as registering the tasks and workflows defined in your code).
Union.ai cloud image builder
Union.ai Serverless will build the image using its ImageBuilder service in the cloud
and registered the image in Union.ai’s own container registry.
From there it will be pulled and installed in the task container when it spins up.
All this is done transparently and does not require any set up by the user.
In Union.ai Serverless images defined by ImageSpec are always built using the Union.ai cloud image builder.
In Union.ai BYOC, you can optionally build images from the ImageSpec on your local machine by specifying builder="envd" in the ImageSpec.
See
Local image builder in the BYOC documentation for more details.