From 08592b5fdb8f63cc55838454126eb6ff257bf818 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:59:49 +0200 Subject: [PATCH 1/3] Add Cadence-samples for Kubernetes --- examples/cadence-samples/SAMPLES.md | 137 ++++++++++++++++++ .../cadence-samples/cadence-samples-pod.yaml | 30 ++++ .../cadence-samples/docker/Dockerfile.samples | 32 ++++ 3 files changed, 199 insertions(+) create mode 100644 examples/cadence-samples/SAMPLES.md create mode 100644 examples/cadence-samples/cadence-samples-pod.yaml create mode 100644 examples/cadence-samples/docker/Dockerfile.samples diff --git a/examples/cadence-samples/SAMPLES.md b/examples/cadence-samples/SAMPLES.md new file mode 100644 index 0000000..750b63a --- /dev/null +++ b/examples/cadence-samples/SAMPLES.md @@ -0,0 +1,137 @@ +# Cadence Samples Usage Guide + +This guide explains how to build, deploy, and use the Cadence samples container for testing workflows. + +## Building the Docker Image + +Build the samples image with your Cadence host configuration: + +```bash +docker build --build-arg CADENCE_HOST="cadence-frontend.cadence.svc.cluster.local:7833" -t cadence-samples:latest -f Dockerfile.samples . +``` + +**Important**: Replace `cadence-frontend.cadence.svc.cluster.local:7833` with your actual Cadence frontend service address. + +### Examples for Different Environments + +```bash +# Local development +docker build --build-arg CADENCE_HOST="localhost:7833" -t cadence-samples:latest -f Dockerfile.samples . + +# Kubernetes cluster (same namespace) +docker build --build-arg CADENCE_HOST="cadence-frontend.cadence.svc.cluster.local:7833" -t cadence-samples:latest -f Dockerfile.samples . + +# Different namespace +docker build --build-arg CADENCE_HOST="cadence-frontend.my-namespace.svc.cluster.local:7833" -t cadence-samples:latest -f Dockerfile.samples . +``` + +## Upload to Container Registry + +Tag and push your image to your container registry: + +```bash +# Tag the image +docker tag cadence-samples:latest your-registry.com/cadence-samples:latest + +# Push to registry +docker push your-registry.com/cadence-samples:latest +``` + +## Kubernetes Deployment + +### Pod Configuration + +Edit the provided YAML file: + +```yaml +apiVersion: v1 +kind: Pod +metadata: + name: cadence-samples + namespace: cadence # Change to your namespace + labels: + app: cadence-samples +spec: + containers: + - name: cadence-samples + image: cadence-samples:latest # Change to your registry image + imagePullPolicy: IfNotPresent + command: ["/bin/bash"] + args: ["-c", "sleep infinity"] + workingDir: /home/cadence + env: + - name: HOME + value: "/home/cadence" + resources: + requests: + memory: "128Mi" + cpu: "100m" + limits: + memory: "1Gi" + cpu: "1" + restartPolicy: Always + securityContext: + runAsUser: 1001 + runAsGroup: 1001 + fsGroup: 1001 +``` + +**Required Changes**: +1. **`namespace`**: Change to your Cadence namespace +2. **`image`**: Change to your registry image path + +### Deploy the Pod + +```bash +kubectl apply -f cadence-samples-pod.yaml +``` + +## Using the Samples + +### Step 1: Access the Container + +```bash +kubectl exec -it cadence-samples -n cadence -- /bin/bash +``` + +### Step 2: Run Workflow Examples + +#### Terminal 1 - Start the Worker +```bash +# Example: Hello World worker +./bin/helloworld -m worker +``` + +#### Terminal 2 - Trigger the Workflow +Open a second terminal and execute: +```bash +kubectl exec -it cadence-samples -n cadence -- /bin/bash +./bin/helloworld -m trigger +``` + +#### Stop the Worker +In Terminal 1, press `Ctrl+C` to stop the worker. + +### Available Sample Commands + +```bash +# Hello World +./bin/helloworld -m worker +./bin/helloworld -m trigger + +# File Processing +./bin/fileprocessing -m worker +./bin/fileprocessing -m trigger + +# DSL Example +./bin/dsl -m worker +./bin/dsl -m trigger -dslConfig cmd/samples/dsl/workflow1.yaml +./bin/dsl -m trigger -dslConfig cmd/samples/dsl/workflow2.yaml +``` + +## Complete Sample Documentation + +For all available samples, detailed explanations, and source code, visit: +**https://github.com/cadence-workflow/cadence-samples** + +This repository contains comprehensive documentation for each sample workflow pattern and advanced usage examples. \ No newline at end of file diff --git a/examples/cadence-samples/cadence-samples-pod.yaml b/examples/cadence-samples/cadence-samples-pod.yaml new file mode 100644 index 0000000..e017a61 --- /dev/null +++ b/examples/cadence-samples/cadence-samples-pod.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: Pod +metadata: + name: cadence-samples + namespace: cadence # Replace with your cadence namespace + labels: + app: cadence-samples +spec: + containers: + - name: cadence-samples + image: cadence-samples:latest # Replace with your built image + imagePullPolicy: IfNotPresent + command: ["/bin/bash"] + args: ["-c", "sleep infinity"] + workingDir: /home/cadence + env: + - name: HOME + value: "/home/cadence" + resources: + requests: + memory: "128Mi" + cpu: "100m" + limits: + memory: "1Gi" + cpu: "1" + restartPolicy: Always + securityContext: + runAsUser: 1001 + runAsGroup: 1001 + fsGroup: 1001 \ No newline at end of file diff --git a/examples/cadence-samples/docker/Dockerfile.samples b/examples/cadence-samples/docker/Dockerfile.samples new file mode 100644 index 0000000..c3ae556 --- /dev/null +++ b/examples/cadence-samples/docker/Dockerfile.samples @@ -0,0 +1,32 @@ +FROM golang:1.21-alpine + +# Install all necessary dependencies for building and running +RUN apk add --no-cache git make gcc musl-dev ca-certificates nano curl bash sed + +# Build argument for Cadence host configuration +ARG CADENCE_HOST=localhost:7833 + +# Create non-root user +RUN addgroup -g 1001 cadence && \ + adduser -D -u 1001 -G cadence cadence + +# Set working directory +WORKDIR /home/cadence + +# Clone cadence-samples repository +RUN git clone https://github.com/cadence-workflow/cadence-samples.git . + +# Update config file with the provided Cadence host +RUN sed -i "s/host: \"localhost:7833\"/host: \"${CADENCE_HOST}\"/" config/development.yaml + +# Build all samples +RUN make + +# Change ownership of files +RUN chown -R cadence:cadence /home/cadence + +# Switch to non-root user +USER cadence + +# Default command - interactive shell +CMD ["/bin/bash"] \ No newline at end of file From 94eed1e1dea35089293a5b3a276eb2904bfabea7 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Mon, 16 Jun 2025 15:00:55 +0200 Subject: [PATCH 2/3] rename readme --- examples/cadence-samples/{SAMPLES.md => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/cadence-samples/{SAMPLES.md => README.md} (100%) diff --git a/examples/cadence-samples/SAMPLES.md b/examples/cadence-samples/README.md similarity index 100% rename from examples/cadence-samples/SAMPLES.md rename to examples/cadence-samples/README.md From ef0754362502a77d6f1e61ef11e3fd0c2d79048a Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Mon, 16 Jun 2025 15:07:19 +0200 Subject: [PATCH 3/3] Creation of domain for samples --- examples/cadence-samples/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/cadence-samples/README.md b/examples/cadence-samples/README.md index 750b63a..bdd5453 100644 --- a/examples/cadence-samples/README.md +++ b/examples/cadence-samples/README.md @@ -2,6 +2,24 @@ This guide explains how to build, deploy, and use the Cadence samples container for testing workflows. +## Prerequisites: Domain Registration + +Before running any samples, you must first register the domain in Cadence. Execute this command in the cadence-frontend pod: + +```bash +# Access the cadence-frontend pod +kubectl exec -it -n cadence -- /bin/bash + +# Register the default domain +cadence --address $(hostname -i):7833 \ + --transport grpc \ + --domain default \ + domain register \ + --retention 1 +``` + +**Note**: Replace `` with your actual cadence-frontend pod name and adjust the namespace if needed. + ## Building the Docker Image Build the samples image with your Cadence host configuration: