|
| 1 | +# Cadence Samples Usage Guide |
| 2 | + |
| 3 | +This guide explains how to build, deploy, and use the Cadence samples container for testing workflows. |
| 4 | + |
| 5 | +## Prerequisites: Domain Registration |
| 6 | + |
| 7 | +Before running any samples, you must first register the domain in Cadence. Execute this command in the cadence-frontend pod: |
| 8 | + |
| 9 | +```bash |
| 10 | +# Access the cadence-frontend pod |
| 11 | +kubectl exec -it <cadence-frontend-pod-name> -n cadence -- /bin/bash |
| 12 | + |
| 13 | +# Register the default domain |
| 14 | +cadence --address $(hostname -i):7833 \ |
| 15 | + --transport grpc \ |
| 16 | + --domain default \ |
| 17 | + domain register \ |
| 18 | + --retention 1 |
| 19 | +``` |
| 20 | + |
| 21 | +**Note**: Replace `<cadence-frontend-pod-name>` with your actual cadence-frontend pod name and adjust the namespace if needed. |
| 22 | + |
| 23 | +## Building the Docker Image |
| 24 | + |
| 25 | +Build the samples image with your Cadence host configuration: |
| 26 | + |
| 27 | +```bash |
| 28 | +docker build --build-arg CADENCE_HOST="cadence-frontend.cadence.svc.cluster.local:7833" -t cadence-samples:latest . |
| 29 | +``` |
| 30 | + |
| 31 | +**Important**: Replace `cadence-frontend.cadence.svc.cluster.local:7833` with your actual Cadence frontend service address. |
| 32 | + |
| 33 | +### Examples for Different Environments |
| 34 | + |
| 35 | +```bash |
| 36 | +# Local development |
| 37 | +docker build --build-arg CADENCE_HOST="localhost:7833" -t cadence-samples:latest -f Dockerfile.samples . |
| 38 | + |
| 39 | +# Kubernetes cluster (same namespace) |
| 40 | +docker build --build-arg CADENCE_HOST="cadence-frontend.cadence.svc.cluster.local:7833" -t cadence-samples:latest . |
| 41 | + |
| 42 | +# Different namespace |
| 43 | +docker build --build-arg CADENCE_HOST="cadence-frontend.my-namespace.svc.cluster.local:7833" -t cadence-samples:latest . |
| 44 | +``` |
| 45 | + |
| 46 | +## Upload to Container Registry |
| 47 | + |
| 48 | +Tag and push your image to your container registry: |
| 49 | + |
| 50 | +```bash |
| 51 | +# Tag the image |
| 52 | +docker tag cadence-samples:latest your-registry.com/cadence-samples:latest |
| 53 | + |
| 54 | +# Push to registry |
| 55 | +docker push your-registry.com/cadence-samples:latest |
| 56 | +``` |
| 57 | + |
| 58 | +## Kubernetes Deployment |
| 59 | + |
| 60 | +### Pod Configuration |
| 61 | + |
| 62 | +Edit the provided YAML file: |
| 63 | + |
| 64 | +```yaml |
| 65 | +apiVersion: v1 |
| 66 | +kind: Pod |
| 67 | +metadata: |
| 68 | + name: cadence-samples |
| 69 | + namespace: cadence # Change to your namespace |
| 70 | + labels: |
| 71 | + app: cadence-samples |
| 72 | +spec: |
| 73 | + containers: |
| 74 | + - name: cadence-samples |
| 75 | + image: cadence-samples:latest # Change to your registry image |
| 76 | + imagePullPolicy: IfNotPresent |
| 77 | + command: ["/bin/bash"] |
| 78 | + args: ["-c", "sleep infinity"] |
| 79 | + workingDir: /home/cadence |
| 80 | + env: |
| 81 | + - name: HOME |
| 82 | + value: "/home/cadence" |
| 83 | + resources: |
| 84 | + requests: |
| 85 | + memory: "128Mi" |
| 86 | + cpu: "100m" |
| 87 | + limits: |
| 88 | + memory: "1Gi" |
| 89 | + cpu: "1" |
| 90 | + restartPolicy: Always |
| 91 | + securityContext: |
| 92 | + runAsUser: 1001 |
| 93 | + runAsGroup: 1001 |
| 94 | + fsGroup: 1001 |
| 95 | +``` |
| 96 | +
|
| 97 | +**Required Changes**: |
| 98 | +1. **`namespace`**: Change to your Cadence namespace |
| 99 | +2. **`image`**: Change to your registry image path |
| 100 | + |
| 101 | +### Deploy the Pod |
| 102 | + |
| 103 | +```bash |
| 104 | +kubectl apply -f cadence-samples-pod.yaml |
| 105 | +``` |
| 106 | + |
| 107 | +## Using the Samples |
| 108 | + |
| 109 | +### Step 1: Access the Container |
| 110 | + |
| 111 | +```bash |
| 112 | +kubectl exec -it cadence-samples -n cadence -- /bin/bash |
| 113 | +``` |
| 114 | + |
| 115 | +### Step 2: Run Workflow Examples |
| 116 | + |
| 117 | +#### Terminal 1 - Start the Worker |
| 118 | +```bash |
| 119 | +# Example: Hello World worker |
| 120 | +./bin/helloworld -m worker |
| 121 | +``` |
| 122 | + |
| 123 | +#### Terminal 2 - Trigger the Workflow |
| 124 | +Open a second terminal and execute: |
| 125 | +```bash |
| 126 | +kubectl exec -it cadence-samples -n cadence -- /bin/bash |
| 127 | +./bin/helloworld -m trigger |
| 128 | +``` |
| 129 | + |
| 130 | +#### Stop the Worker |
| 131 | +In Terminal 1, press `Ctrl+C` to stop the worker. |
| 132 | + |
| 133 | +### Some Available Sample Commands |
| 134 | + |
| 135 | +```bash |
| 136 | +# Hello World |
| 137 | +./bin/helloworld -m worker |
| 138 | +./bin/helloworld -m trigger |
| 139 | +
|
| 140 | +# File Processing |
| 141 | +./bin/fileprocessing -m worker |
| 142 | +./bin/fileprocessing -m trigger |
| 143 | +
|
| 144 | +# DSL Example |
| 145 | +./bin/dsl -m worker |
| 146 | +./bin/dsl -m trigger -dslConfig cmd/samples/dsl/workflow1.yaml |
| 147 | +./bin/dsl -m trigger -dslConfig cmd/samples/dsl/workflow2.yaml |
| 148 | +``` |
| 149 | + |
| 150 | +## Complete Sample Documentation |
| 151 | + |
| 152 | +For all available samples, detailed explanations, and source code, visit: |
| 153 | +**https://github.com/cadence-workflow/cadence-samples** |
| 154 | + |
| 155 | +This repository contains comprehensive documentation for each sample workflow pattern and advanced usage examples. |
0 commit comments