Build and Run Workflows

Building and Using Workflows

This page provides an explanation of how Commands, Pipelines, and Services workflows are built as container images encapsulating your custom code, how your workflow containers are published to the CTO.ai registry, and how you can run these workflows—both locally and on the CTO.ai platform.

If you’re new to using workflows on the CTO.ai platform, we recommend checking out our Workflows Overview document before you begin.

Build a Workflow (ops build)

The ops.yml file is what actually defines your workflow and how it is run, bringing together all the components in a number of important ways:

  • When you build your workflow, the Dockerfile in your working directory is used to build a new container image that encapsulates your workflow. Any dependencies that your custom workflow code needs to run should be installed in the container image using the appropriate package managers.
  • The name and version used to tag the new container image are taken from the name key specified in the ops.yml file.
  • When you run your workflow, the shell command specified under the run key (in your ops.yml) is executed in a container built from your Dockerfile.

From within a workflow’s directory (which contains the ops.yml file, the Dockerfile, and other supporting code), we can build the container image that will run our workflow:

The CLI will use the Dockerfile to build the container image for your workflow, with output that looks something like this:

The container image built by our CLI will have a fully-qualified tag applied, including the registry URL, your CTO.ai team, and the individual workflow’s name and build version. The fully-qualified tag has the format [Registry URL]/[Team Name]/[Image Name], where:

  • Registry URL is the CTO.ai Registry: registry.cto.ai
  • Team Name is the name of your team on the CTO.ai platform that is active in the current CLI context.
  • Image Name is the name and version of the container image, as specified in your ops.yml file.

Run a Workflow Locally (ops run)

After the container image that encapsulates our workflow has been built, you can run it locally with the ops run command:

We can run our workflow by specifying the name or path of the workflow to run. If you are within the workflow’s directory (which contains the ops.yml file), you can pass . as the path argument to run the local workflow:

To make it easier to build and test your workflow iteratively, you can also pass the -b flag to ops run to rebuild your workflow container before running it locally:

Using the -b flag will cause the CLI to first build your workflow container before running it, as if you had run an ops build command beforehand.

Publish a Workflow (ops publish)

To run your workflow on the CTO.ai platform, to share it with your team, or to make it accessible to the world via our public registry, you can use the ops publish command:

We can publish our workflow by specifying the path of the workflow to upload. If you are within the workflow’s directory (which contains the ops.yml file, you can pass . as the path argument to publish the current workflow:

For ops.yml configs that define multiple workflows, you can also pass the names of individual workflows you with to publish, using the -o/--ops option. Passing workflow names to the --ops flag will also cause your workflow container image to be rebuilt before publishing.

When you run the ops publish command, it will prompt you for a changelog message, unless you pass one to the command using the -c/--changelog flag.

The output of this operation (example above) should show that the container image has been uploaded to the CTO.ai platform, and it includes the URL you can use to access your workflow’s registry page.

Run a Workflow in the Cloud (ops run)

To run a workflow that you have published to the CTO.ai platform, you can use the ops run command with the name of the Command to run passed as the only argument:

Names that match both a local and cloud workflow will cause the CLI to prompt you to choose where your workflow should be run:

Screenshot showing the `ops run example-command` shell command and its output. When you run this command, if multiple workflows match a name, you will be prompted to select which workflow should be run.
Screenshot showing the `ops run example-command` shell command and its output. When you run this command, if multiple workflows match a name, you will be prompted to select which workflow should be run.

Use the arrow keys to select the workflow to run, then press your $inline[key,↵] (Enter) key to execute it:

Screenshot showing the output of executing `ops run example-command` after the user has selected which workflow to run. The result includes interactive prompting (according to the code defining the workflow) and output for the user.
Screenshot showing the output of executing `ops run example-command` after the user has selected which workflow to run. The result includes interactive prompting (according to the code defining the workflow) and output for the user.

Trigger a Workflow Non-Interactively (ops start)

To trigger a workflow to run on the CTO.ai platform—without any interactivity for the user who initiates—you can use the ops start command:

Run ops start with the name of the workflow you wish to run passed as the only argument:

The only output you should see in response to using the ops start command should include the resulting status of the action and a link to view the logs for this run of your workflow:

Remember that the ops start command can’t be used to run workflows interactively. For example, when we use ops start to run a Commands workflow that expects user input, we can see on the CTO.ai dashboard that the Commands workflow gets stuck indefinitely while waiting for a response to the first prompt:

Screenshot of the CTO.ai Dashboard showing a workflow run from a Command that expects user input, which is stuck waiting indefinitely.
Screenshot of the CTO.ai Dashboard showing a workflow run from a Command that expects user input, which is stuck waiting indefinitely.

You should use ops run instead to trigger your ChatOps-style workflows that expect user input (such as Commands workflows).