Skip to content
Technical preview. This site is published for review. Everything on it, including the API, tokens and module protocol, is subject to change.
Get started

Get started

A workflow definition is a Starlark program. AutoFlow runs each submission of it as a workflow: a durable execution on autocore that survives restarts and can wait for days. The gRPC API is the entry point today.

What you need

A running AutoFlow with its API listener reachable, its API authentication secret, and a client. The gitlab-caproni rig, GitLab’s local Kubernetes development environment on Caproni, gives you all three: enable its AutoFlow fragment in caproni.local.yaml and bring the rig up.

extends:
  - fragments/caproni.autoflow.yaml
caproni up

scripts/autoflow.sh in the rig checkout then runs the autoflow CLI against that AutoFlow, with the secret and the address taken care of, and scripts/autocorectl.sh runs autocore’s admin tool in its pod. The rig gained AutoFlow with gitlab-caproni!122.

Against any other AutoFlow instance you need:

  • Its API listener address. The default is 127.0.0.1:8153, plaintext unless a certificate and key are configured.
  • The API authentication secret: the file api.listen.authentication_secret_file points to, holding a base64-encoded secret. Every call carries a JWT signed with it.
  • The autoflow CLI, or grpcurl. The CLI ships as kas autoflow in every kas binary, the relay image included, so next to a running Relay nothing has to be built. It can also be built from the AutoFlow repository with go build ./cmd/autoflow.
The API performs no authorization. Whoever holds the API secret can start any workflow in any namespace. Deciding who may start what is the caller’s job, so treat the secret as a root credential.

Write a workflow definition

Save this as workflow.star:

def main(w, name):
    print("starting for", name)
    sleep(5 * time.second)
    print("slept 5 seconds, still here")
    return "hello, " + name

main is the entry point. Its first parameter w is the workflow context; every further parameter is bound from the arguments the caller sends. sleep is durable: the workflow holds no resources while it waits and resumes even if AutoFlow restarts in between. The value main returns is the workflow’s result.

Start it

AutoFlow serves the AutoFlow gRPC service on its API listener: StartWorkflow, GetWorkflow, CancelWorkflow and SendToWorkflowChannel. The API reference describes every request and response field; the source of truth is internal/module/autoflow/rpc/rpc.proto. The API is subject to change: a new shape is proposed in ADR 0011.

From the rig checkout, scripts/autoflow.sh runs the CLI against the rig’s AutoFlow:

scripts/autoflow.sh run -s workflow.star --kwarg 'name="world"'

The output is the CLI’s, described in the next tab. The workflow’s print lines are in AutoFlow’s log:

caproni kubectl -n autoflow logs deploy/autoflow -c app | grep is_script_print
The workflow token, channel token and token binding returned here are an interim design. Expect them to change once GATE is available.

Read the result

Polling GetWorkflow is the only way to observe a workflow: there is no callback and no streaming variant. The request needs the workflow key, the workflow token and the namespace:

scripts/autoflow.sh get <workflow-key> --workflow-token <workflow-token> --wait

The response has state, created_at, updated_at and result. RUNNING is the only non-terminal state. The terminal ones:

StateMeaning
COMPLETEDmain returned. result holds its value, or none_value without a return.
FAILEDThe workflow failed, for example an action returned an error. result is the error.
CANCELEDCancellation was requested and took effect.
TIMED_OUTThe schedule-to-complete timeout elapsed, 30 days unless the caller set one.
SYSTEM_FAILEDAutoFlow could not run the workflow to completion. Not the workflow definition’s fault.

print output does not travel with the result. It goes to AutoFlow’s log at Info level with sensitive values masked. A stream of it to the caller does not exist yet; issue 953 tracks it.

Next steps

Last updated on