Getting started with Argo Workflows + CUE
The CUE Central Registry provides a well-known location for well-known schemas, including those for the YAML workflow files used by Argo Workflows. This guide shows you how to get started defining your Argo workflows in CUE using a curated module from the schema library.
Initialize your local CUE module
CUE that uses schemas and modules from the Central Registry needs to exist within its own CUE module.
$ cue mod init cue.exampleYou can choose any module name you like, and change it later. It makes sense for your CUE module to exist at the root of a source code repository. The commands in this guide work in any setup.
Create an Argo workflow
Declare an Argo workflow in CUE. This one comes from Argo’s examples:
package cicd
import argoworkflows "cue.dev/x/argo/workflows"
workflows: example: argoworkflows.#Workflow & {
// This template demonstrates a steps template and how to control sequential vs. parallel steps.
// In this example, the hello1 completes before the hello2a, and hello2b steps, which run in parallel.
apiVersion: "argoproj.io/v1alpha1"
kind: "Workflow"
metadata: generateName: "steps-"
spec: {
entrypoint: "hello-hello-hello"
templates: [{
name: "hello-hello-hello"
steps: [[{
name: "hello1"
template: "print-message"
arguments: parameters: [{name: "message", value: "hello1"}]
}], [{
name: "hello2a"
template: "print-message"
arguments: parameters: [{name: "message", value: "hello2a"}]
}, {
name: "hello2b"
template: "print-message"
arguments: parameters: [{name: "message", value: "hello2b"}]
}],
]
}, {
name: "print-message"
inputs: parameters: [{name: "message"}]
container: {
image: "busybox"
command: ["echo"]
args: ["{{inputs.parameters.message}}"]
}
}]
}
}
workflows struct.The import at the top references the appropriate curated module for the workflow.
Its path is currently temporary, but only while its proper location is being decided.
The temporary path isn’t a problem: once a schema is published to the Central Registry, it is always available at that location.
When versions are published at the curated module’s final location, use the cue refactor imports command to update your CUE.
Tidy your local CUE module
$ cue mod tidyTidying a module is part of using curated modules from the
Central Registry.
Always use
cue mod tidy
when you use a curated module for the first time.
If you see an error message mentioning “too many requests” then login to the Central Registry and re-run this command. The Central Registry allows more requests from authenticated users.
Validate your workflow
$ cue vet -cBecause cue vet doesn’t display any errors, you know that the curated schema has validated your workflow.
Export your workflow as YAML
$ cue export --outfile workflow.yml -e workflows.exampleIf you chose to export the workflows.example shown above,
your validated YAML workflow will look like this:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: steps-
spec:
entrypoint: hello-hello-hello
templates:
- name: hello-hello-hello
steps:
- - name: hello1
template: print-message
arguments:
parameters:
- name: message
value: hello1
- - name: hello2a
template: print-message
arguments:
parameters:
- name: message
value: hello2a
- name: hello2b
template: print-message
arguments:
parameters:
- name: message
value: hello2b
- name: print-message
inputs:
parameters:
- name: message
container:
image: busybox
command:
- echo
args:
- '{{inputs.parameters.message}}'Run your workflow
You can now trigger the Argo workflow using your validated YAML workflow file.
The cue.mod directory needs to be stored in your source code repository,
along with your workflow.cue and workflow.yml files.
Whenever you update your CUE workflow, re-run the cue export command shown
above, and then record any changes to these files and directories.