Integrate a custom workflow using containers
How toPackage an existing command as a container step and connect it to a factory.
Use a container runner to bring an existing tool or
workflow into a factory without waiting for a purpose-built adapter. Package the
command and its dependencies in an OCI image, add a small entrypoint that speaks
the container protocol, and bind the image's inputs and outputs to your factory.
The image runs through a container backend configured by the deployment.
This walkthrough wraps a Python text transformation. Replace the transformation with your own command once the protocol works. An arbitrary image does not work unchanged: its entrypoint must implement the two protocol phases below.
1. Write the entrypoint
Create entrypoint.py in an empty directory:
#!/usr/bin/env python3
import json
import sys
contract = {
"protocol": 1,
"name": "example/uppercase",
"version": "1.0.0",
"inputs": {
"type": "object",
"properties": {"text": {"type": "string"}},
"required": ["text"],
"additionalProperties": False,
},
"outputs": {
"type": "object",
"properties": {"result": {"type": "string"}},
"required": ["result"],
"additionalProperties": False,
},
}
if len(sys.argv) == 2 and sys.argv[1] == "describe":
print(json.dumps(contract))
elif len(sys.argv) == 2 and sys.argv[1] == "run":
envelope = json.load(sys.stdin)
# Replace this line with your workflow, returning its result as a string.
result = envelope["inputs"]["text"].upper()
print(json.dumps({"protocol": 1, "outputs": {"result": result}}))
else:
print("expected describe or run", file=sys.stderr)
sys.exit(2)
The describe phase prints one JSON contract without reading stdin. The run
phase reads one JSON envelope from stdin and prints one JSON result on stdout.
Keep stdout for that single protocol document; send diagnostic logs to stderr.
The envelope also carries config (the runner's params) and optional run
context. See the specification §6.5 and Appendix B for
configuration, the JSON Schema profile, error results and size limits.
If your workflow invokes another program, capture its stdout rather than letting
it mix with the protocol result. Return a non-zero exit for a failed command; a
structured error result can explain the failure. The entrypoint is responsible
for validating its own value constraints and returning the declared outputs.
A path in an input is just a value: make the files your workflow needs available
inside its execution environment, rather than assuming the host's filesystem is
mounted.
2. Build and publish the image
Create a Dockerfile beside the entrypoint:
FROM python:3.12-slim
COPY entrypoint.py /usr/local/bin/workflow
RUN chmod 0755 /usr/local/bin/workflow
ENTRYPOINT ["/usr/local/bin/workflow"]
Build the image, replacing the example registry and repository with your own:
docker build -t ghcr.io/YOUR-ORG/uppercase:1 .
You can test both phases locally:
docker run --rm ghcr.io/YOUR-ORG/uppercase:1 describe
printf '%s\n' '{"protocol":1,"config":{},"inputs":{"text":"hello"}}' |
docker run --rm -i ghcr.io/YOUR-ORG/uppercase:1 run
The second command prints {"protocol": 1, "outputs": {"result": "HELLO"}}.
Push the image to a registry that dotFactory can access:
docker push ghcr.io/YOUR-ORG/uppercase:1
dotFactory pulls the image from the registry; an image that exists only on your laptop is not available to it. For production, pin the image by digest instead of a mutable tag.
3. Connect it to a factory
Save the following as factory.fct, replacing the image with your published
reference:
runner uppercase:
kind: container
in: open
out: open
config: { image: "ghcr.io/YOUR-ORG/uppercase:1" }
trigger start:
kind: manual
out: { text: text }
step transform:
runner: uppercase
in: { text: start.text }
out: { result: text }
The manual trigger supplies text; the step passes it to the image and exposes
its result to the rest of the graph. in: open and out: open leave the
image's interface unchecked against the runner declaration. For structural
checking, declare typed runner interfaces instead: the runner compares the
image's describe contract with the declared port names and required presence;
the engine enforces DSL types. See The language and the
container reference.
Create a factory and upload the definition as a factory version in the app. dotFactory validates the definition during upload; see Getting started for the steps.
Fire start with hello. When a worker executes the Run, the transform
node should expose result: HELLO. The Runs guide explains how to
inspect its outputs and test a step on its own using Dry run, Describe,
or Run. A dry run resolves the step without running your image.
4. Check access and troubleshoot
Your dotFactory deployment must support container steps and be able to run work. A factory can validate and render even when the required runner is not available; the factory page identifies any missing adapters. If the runner is unavailable, ask your dotFactory administrator. See Adapters for more about runnability.
For a private registry, bind the appropriate source input with its image and
registry credentials; the adapter consumes that input before invoking the
image. Do not put secrets in params: bind them as secret inputs instead. See
Secrets and configuration and the
specification §6.5 for source variants and credentials.
If the image cannot be pulled, check its reference and registry credentials. If Describe fails, check the entrypoint, protocol version and contract. A non-zero exit fails the step; invalid JSON, extra stdout, a wrong protocol version, or missing required outputs can also fail it. Inspect the step's error and logs in the Run before retrying.
Your factories will appear here. Create one and open it beside this guide.