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:
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:
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:
The script prints Sum of [3, 2] = 5, and sum.txt contains 5.
2. Build the runtime image¶
Create a Dockerfile:
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:
Validate and execute locally:
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:
Create a README.md describing the workflow and its example inputs. Keep
generated files out of Git by creating a .gitignore containing:
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¶
- Sign in to AntFlow and open your project from Projects.
- Select the Git reference containing
sum.cwland open the Sum integers process. - Set Operands to the integers
3and2. - Select a launcher that can pull and run your image, then submit the job.
- Open the job details, inspect the logs, and retrieve the
sum_fileresult.
The result should contain 5. Submit another job with different integers
to see how one process produces separate executions and results.
What's next¶
- Run a workflow through the API: submit this calculator from a script.
- CWL reference: add input-form annotations and resource declarations to your workflow.
- Use a secret input: add a vault-backed credential input.