Skip to content

Create your first workflow

Create a workflow that adds integers and produces a text file, then publish it in GitLab and run it through AntFlow. This exercise uses a Python script, a container image, and a CWL definition; no package generator is required.

Before you start

You need Python 3, Docker or Podman, Git, and cwltool. You also need a GitLab project you can push to, a container registry you can publish to, and an AntFlow instance with a suitable launcher.

With Podman, replace docker with podman in the commands below and add --podman when executing the workflow with cwltool.

Confirm registry access and the project's processing topic with your administrator. Choose the full image reference once, including your registry, repository, and version tag. The interactive commands use Bash; keep using the same terminal:

read -r -p "Full container image reference, including version tag: " IMAGE

For a GitLab project, use the image path shown on its Deploy > Container Registry page and append a version tag such as :1.0.0. The CWL example below has one image placeholder to replace with this exact reference; it does not expand shell variables.

1. Write the processing script

Create a working directory:

mkdir antflow-sum
cd antflow-sum

Create sum.py with the following content:

from argparse import ArgumentParser
from pathlib import Path


def main():
    parser = ArgumentParser(description="Add integers and write their sum")
    parser.add_argument("--operands", type=int, nargs="+", required=True)
    operands = parser.parse_args().operands
    result = sum(operands)
    Path("sum.txt").write_text(f"{result}\n", encoding="utf-8")
    print(f"Sum of {operands} = {result}")


if __name__ == "__main__":
    main()

Test it locally:

python3 sum.py --operands 3 2
cat sum.txt

The script prints Sum of [3, 2] = 5, and sum.txt contains 5.

2. Build the runtime image

Create a Dockerfile:

FROM python:3.12-slim

COPY sum.py /opt/workflow/sum.py

Build and test the image:

docker build --tag "$IMAGE" .
docker run --rm "$IMAGE" \
  python3 /opt/workflow/sum.py --operands 3 2

The container should print the same sum. Its temporary sum.txt is removed with the container; the CWL runner will collect the output in the next step. The script is inside the image, and the CWL will declare its command explicitly rather than depend on a Docker ENTRYPOINT.

3. Describe the workflow in CWL

Create sum.cwl, replacing the dockerPull example with your chosen image reference before validating or running it:

cwlVersion: v1.2
class: Workflow
label: Sum integers
doc: Add a nonempty array of integers and return the sum as a text file.
inputs:
  operands:
    label: Operands
    doc: Integers to add, for example 3 and 2.
    type:
      type: array
      items: int
outputs:
  sum_file:
    type: File
    outputSource: calculate/sum_file
steps:
  calculate:
    in:
      operands: operands
    out: [sum_file]
    run:
      class: CommandLineTool
      baseCommand: [python3, /opt/workflow/sum.py]
      requirements:
        DockerRequirement:
          dockerPull: registry.example.com/my-team/antflow-sum:1.0.0
      inputs:
        operands:
          type:
            type: array
            items: int
          inputBinding:
            prefix: --operands
      outputs:
        sum_file:
          type: File
          outputBinding:
            glob: sum.txt

The workflow exposes one array input and one file output. Its single step runs the script in your image and collects sum.txt from the working directory.

Create inputs.yaml:

operands: [3, 2]

Validate and execute locally:

cwltool --validate sum.cwl
cwltool --outdir outputs sum.cwl inputs.yaml
cat outputs/sum.txt

The output file should contain 5. This tests the full workflow, not just the script. If it fails, fix the definition or image before publishing.

4. Publish the image and package

Authenticate to your registry using its supported login procedure, then push the image:

docker push "$IMAGE"

Create a README.md describing the workflow and its example inputs. Keep generated files out of Git by creating a .gitignore containing:

sum.txt
outputs/
.venv/

Follow Push the package to GitLab to publish sum.py, Dockerfile, sum.cwl, inputs.yaml, the README, and .gitignore. Then make the workflow discoverable using the topic and access rules of your AntFlow instance.

5. Run it through AntFlow

  1. Sign in to AntFlow and open your project from Projects.
  2. Select the Git reference containing sum.cwl and open the Sum integers process.
  3. Set Operands to the integers 3 and 2.
  4. Select a launcher that can pull and run your image, then submit the job.
  5. Open the job details, inspect the logs, and retrieve the sum_file result.

The result should contain 5. Submit another job with different integers to see how one process produces separate executions and results.

What's next