From 8982714fe2dae15ec721101efa207ee2e3897290 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Mon, 16 Jun 2025 17:36:45 +0200 Subject: [PATCH 01/11] Support for Kubernetes added --- k8s/README.md | 155 +++++++++++++++++++++++++++++++++++ k8s/cadence-samples-pod.yaml | 30 +++++++ k8s/docker/Dockerfile | 32 ++++++++ 3 files changed, 217 insertions(+) create mode 100644 k8s/README.md create mode 100644 k8s/cadence-samples-pod.yaml create mode 100644 k8s/docker/Dockerfile diff --git a/k8s/README.md b/k8s/README.md new file mode 100644 index 0000000..f6b6804 --- /dev/null +++ b/k8s/README.md @@ -0,0 +1,155 @@ +# Cadence Samples Usage Guide + +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: + +```bash +docker build --build-arg CADENCE_HOST="cadence-frontend.cadence.svc.cluster.local:7833" -t cadence-samples:latest . +``` + +**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 . + +# Different namespace +docker build --build-arg CADENCE_HOST="cadence-frontend.my-namespace.svc.cluster.local:7833" -t cadence-samples:latest . +``` + +## 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. + +### Some 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/k8s/cadence-samples-pod.yaml b/k8s/cadence-samples-pod.yaml new file mode 100644 index 0000000..e017a61 --- /dev/null +++ b/k8s/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/k8s/docker/Dockerfile b/k8s/docker/Dockerfile new file mode 100644 index 0000000..c3ae556 --- /dev/null +++ b/k8s/docker/Dockerfile @@ -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 5da88a375b28e7d53afef016991e27134cf709bf Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Mon, 16 Jun 2025 18:02:40 +0200 Subject: [PATCH 02/11] Changed structure and Dockerfile --- docker/Dockerfile | 55 +++++++++++++++++++ {k8s => docker/kubernetes-example}/README.md | 0 .../cadence-samples-pod.yaml | 0 k8s/docker/Dockerfile | 32 ----------- 4 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 docker/Dockerfile rename {k8s => docker/kubernetes-example}/README.md (100%) rename {k8s => docker/kubernetes-example}/cadence-samples-pod.yaml (100%) delete mode 100644 k8s/docker/Dockerfile diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..c69abce --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,55 @@ +# Multi-stage build for optimization +FROM golang:1.21-alpine AS builder + +# Install build dependencies +RUN apk add --no-cache git make gcc musl-dev + +# Set working directory +WORKDIR /app + +# Copy go mod files first for better layer caching +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source code +COPY . . + +# Build all samples +RUN make + +# Final stage - minimal runtime image +FROM alpine:3.22 + +# Install runtime dependencies +RUN apk add --no-cache ca-certificates bash curl + +# 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 + +# Copy built binaries from builder stage +COPY --from=builder /app/bin/ ./bin/ + +# Copy configuration files +COPY --from=builder /app/config/ ./config/ + +# Update config file with the provided Cadence host +RUN sed -i "s/host: \"localhost:7833\"/host: \"${CADENCE_HOST}\"/" config/development.yaml + +# Change ownership of files +RUN chown -R cadence:cadence /home/cadence + +# Switch to non-root user +USER cadence + +# Add bin directory to PATH +ENV PATH="/home/cadence/bin:${PATH}" + +# Default command - interactive shell +CMD ["/bin/bash"] \ No newline at end of file diff --git a/k8s/README.md b/docker/kubernetes-example/README.md similarity index 100% rename from k8s/README.md rename to docker/kubernetes-example/README.md diff --git a/k8s/cadence-samples-pod.yaml b/docker/kubernetes-example/cadence-samples-pod.yaml similarity index 100% rename from k8s/cadence-samples-pod.yaml rename to docker/kubernetes-example/cadence-samples-pod.yaml diff --git a/k8s/docker/Dockerfile b/k8s/docker/Dockerfile deleted file mode 100644 index c3ae556..0000000 --- a/k8s/docker/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -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 24906377066f1154805572510e10010479cf7a69 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Mon, 16 Jun 2025 18:15:03 +0200 Subject: [PATCH 03/11] no git needed --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index c69abce..875775b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.21-alpine AS builder # Install build dependencies -RUN apk add --no-cache git make gcc musl-dev +RUN apk add --no-cache make gcc musl-dev # Set working directory WORKDIR /app From c4a446fc8916468d3f9ec5d2ce45c0835a63dfd6 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Tue, 17 Jun 2025 10:48:10 +0200 Subject: [PATCH 04/11] docker compose created --- .gitignore | 1 - docker/docker-compose.yml | 91 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 docker/docker-compose.yml diff --git a/.gitignore b/.gitignore index 33bb963..6bdea96 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,3 @@ test.log vendor/ # Executables produced by cadence-samples repo bin/ -docker-compose.yml diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..e69a61d --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,91 @@ +# Docker Compose based on: https://raw.githubusercontent.com/cadence-workflow/cadence/refs/heads/master/docker/docker-compose.yml +# The cadence-samples service is added at the end for testing this application +services: + cassandra: + image: cassandra:4.1.1 + ports: + - "9042:9042" + environment: + - "MAX_HEAP_SIZE=256M" + - "HEAP_NEWSIZE=128M" + healthcheck: + test: ["CMD", "cqlsh", "-u cassandra", "-p cassandra" ,"-e describe keyspaces"] + interval: 15s + timeout: 30s + retries: 10 + + prometheus: + image: prom/prometheus:latest + volumes: + - ./prometheus:/etc/prometheus + command: + - '--config.file=/etc/prometheus/prometheus.yml' + ports: + - '9090:9090' + + node-exporter: + image: prom/node-exporter + ports: + - '9100:9100' + + cadence: + image: ubercadence/server:master-auto-setup + ports: + - "8000:8000" + - "8001:8001" + - "8002:8002" + - "8003:8003" + - "7933:7933" + - "7934:7934" + - "7935:7935" + - "7939:7939" + - "7833:7833" + - "7936:7936" + environment: + - "CASSANDRA_SEEDS=cassandra" + - "PROMETHEUS_ENDPOINT_0=0.0.0.0:8000" + - "PROMETHEUS_ENDPOINT_1=0.0.0.0:8001" + - "PROMETHEUS_ENDPOINT_2=0.0.0.0:8002" + - "PROMETHEUS_ENDPOINT_3=0.0.0.0:8003" + - "DYNAMIC_CONFIG_FILE_PATH=config/dynamicconfig/development.yaml" + - "FRONTEND_PPROF_PORT=7936" + - "LOG_LEVEL=debug" + depends_on: + cassandra: + condition: service_healthy + prometheus: + condition: service_started + + cadence-web: + image: ubercadence/web:latest + environment: + - "CADENCE_GRPC_PEERS=cadence:7833" + ports: + - "8088:8088" + depends_on: + - cadence + + grafana: + image: grafana/grafana + volumes: + - ./grafana:/etc/grafana + user: "1000" + depends_on: + - prometheus + ports: + - '3000:3000' + + # Added service for cadence-samples + cadence-samples: + build: + context: .. + dockerfile: ./docker/Dockerfile + args: + - CADENCE_HOST=cadence:7833 + depends_on: + cadence: + condition: service_started + environment: + - CADENCE_HOST=cadence:7833 + stdin_open: true + tty: true \ No newline at end of file From c678b81f101c5ff5649f8ec1e5d328713155ee32 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Tue, 17 Jun 2025 10:48:41 +0200 Subject: [PATCH 05/11] required files for docker-compose --- docker/grafana/dashboards/.exists | 1 + docker/grafana/grafana.ini | 3 +++ .../grafana/provisioning/datasources/default.yml | 7 +++++++ docker/prometheus/prometheus.yml | 14 ++++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 docker/grafana/dashboards/.exists create mode 100644 docker/grafana/grafana.ini create mode 100644 docker/grafana/provisioning/datasources/default.yml create mode 100644 docker/prometheus/prometheus.yml diff --git a/docker/grafana/dashboards/.exists b/docker/grafana/dashboards/.exists new file mode 100644 index 0000000..3eaa3f8 --- /dev/null +++ b/docker/grafana/dashboards/.exists @@ -0,0 +1 @@ +Dashboards are updated periodically, so it is recommended to import them manually by downloading them from: https://github.com/cadence-workflow/cadence/tree/master/docker/grafana/provisioning/dashboards \ No newline at end of file diff --git a/docker/grafana/grafana.ini b/docker/grafana/grafana.ini new file mode 100644 index 0000000..d087b64 --- /dev/null +++ b/docker/grafana/grafana.ini @@ -0,0 +1,3 @@ +[auth.anonymous] +enabled = true +org_role = Admin \ No newline at end of file diff --git a/docker/grafana/provisioning/datasources/default.yml b/docker/grafana/provisioning/datasources/default.yml new file mode 100644 index 0000000..060e855 --- /dev/null +++ b/docker/grafana/provisioning/datasources/default.yml @@ -0,0 +1,7 @@ +# Based on: https://github.com/cadence-workflow/cadence/blob/master/docker/grafana/provisioning/datasources/default.yaml +datasources: + - name: Prometheus + type: prometheus + url: http://host.docker.internal:9090 + version: 1 + editable: true \ No newline at end of file diff --git a/docker/prometheus/prometheus.yml b/docker/prometheus/prometheus.yml new file mode 100644 index 0000000..05cb832 --- /dev/null +++ b/docker/prometheus/prometheus.yml @@ -0,0 +1,14 @@ +# Based on: https://github.com/cadence-workflow/cadence/blob/master/docker/prometheus/prometheus.yml +global: + scrape_interval: 5s + external_labels: + monitor: 'cadence-monitor' +scrape_configs: + - job_name: 'prometheus' + static_configs: + - targets: # addresses to scrape + - 'cadence:9090' + - 'cadence:8000' + - 'cadence:8001' + - 'cadence:8002' + - 'cadence:8003' \ No newline at end of file From d8003ac250b34f049089ba9ec44f6b3756f95755 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Tue, 17 Jun 2025 10:49:52 +0200 Subject: [PATCH 06/11] Documentation for docker-compose --- docker/README.md | 206 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 docker/README.md diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..d28a004 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,206 @@ +# Cadence Samples with Docker Compose + +This project provides a complete Cadence development environment using Docker Compose, including the core Cadence services and cadence-samples application. + +## Prerequisites + +- Docker and Docker Compose installed +- Basic understanding of Cadence workflows + +## Project Structure + +``` +. +├── docker/ +│ └── Dockerfile # Your cadence-samples Dockerfile +├── docker-compose.yml # Complete Cadence stack + samples +├── config/ # Configuration files +├── bin/ # Built binaries (after build) +└── README.md # This file +``` + +## Getting Started + +### Step 1: Start the Complete Stack + +```bash +# Start all services (Cadence, Cassandra, Web UI, Grafana, and cadence-samples) +docker-compose up -d + +# Check if all services are running +docker-compose ps + +# View logs to ensure everything started correctly +docker-compose logs cadence +``` + +### Step 2: Wait for Services to be Ready + +Wait for Cadence to be fully initialized: + +```bash +# Monitor Cadence logs until you see "Started" +docker-compose logs -f cadence +``` + +### Step 3: Access the Cadence Web UI + +Open your browser and navigate to: +- **Cadence Web UI**: http://localhost:8088 +- **Grafana**: http://localhost:3000 +- **Prometheus**: http://localhost:9090 + +## Using the Samples + +### Step 1: Access the Container + +```bash +docker-compose exec cadence-samples /bin/bash +``` + +### Step 2: Run Workflow Examples + +You need **two terminals** for most examples - one for the worker and another for triggering workflows. + +#### Terminal 1 - Start the Worker +```bash +# Access the container +docker-compose exec cadence-samples /bin/bash + +# Example: Hello World worker +./bin/helloworld -m worker +``` + +#### Terminal 2 - Trigger the Workflow +Open a second terminal and execute: +```bash +# Access the container in a new session +docker-compose exec cadence-samples /bin/bash + +# Trigger the workflow +./bin/helloworld -m trigger +``` + +#### Stop the Worker +In Terminal 1, press `Ctrl+C` to stop the worker. + +### Available Sample Commands + +Once inside the container, you can run various sample workflows: + +```bash +# List available binaries +ls -la ./bin/ + +# Examples (replace with actual sample names) +./bin/helloworld -m worker # Start worker +./bin/helloworld -m trigger # Trigger workflow + +./bin/timer -m worker # Timer example worker +./bin/timer -m trigger # Timer example trigger +``` + +## Updating the Docker Compose + +### Option 1: Update from Original Source + +To update the base Cadence services: + +1. Download the latest version: +```bash +curl -o docker-compose-base.yml https://raw.githubusercontent.com/cadence-workflow/cadence/refs/heads/master/docker/docker-compose.yml +``` + +2. Manually merge the `cadence-samples` service from the current `docker-compose.yml` + +3. Test the updated configuration + +### Option 2: Modify the Current Configuration + +To update your cadence-samples service: + +1. **Change the Docker image**: Modify the `build` section in `docker-compose.yml` +2. **Update environment variables**: Add or modify variables in the `environment` section +3. **Rebuild the service**: `docker-compose build cadence-samples` +4. **Restart the service**: `docker-compose up -d cadence-samples` + +### Example: Adding a New Environment Variable + +```yaml +cadence-samples: + # ... existing configuration + environment: + - CADENCE_HOST=cadence:7833 + - YOUR_NEW_VAR=your_value # Add this line +``` + +## Troubleshooting + +### Service Not Starting + +```bash +# Check service status +docker-compose ps + +# View logs for specific service +docker-compose logs cadence-samples +docker-compose logs cadence + +# Restart specific service +docker-compose restart cadence-samples +``` + +### Connection Issues + +```bash +# Test connectivity from samples to Cadence +docker-compose exec cadence-samples ping cadence + +# Check if Cadence ports are accessible +docker-compose exec cadence-samples telnet cadence 7833 +``` + +### Rebuilding After Code Changes + +```bash +# Rebuild cadence-samples after code changes +docker-compose build cadence-samples + +# Restart with new build +docker-compose up -d cadence-samples +``` + +## Development Workflow + +1. **Make code changes** in your local files +2. **Rebuild the service**: `docker-compose build cadence-samples` +3. **Restart the container**: `docker-compose up -d cadence-samples` +4. **Test your changes** using the workflow examples + +## Stopping the Environment + +```bash +# Stop all services +docker-compose down + +# Stop and remove volumes (WARNING: This will delete data) +docker-compose down -v + +# Stop and remove everything including images +docker-compose down --rmi all -v +``` + +## Service Ports + +- **Cadence Frontend**: 7833 +- **Cadence Web UI**: 8088 +- **Grafana**: 3000 +- **Prometheus**: 9090 +- **Cassandra**: 9042 + +## Notes + +- The cadence-samples container runs in interactive mode by default +- Configuration files are automatically updated to point to the correct Cadence host +- All services use Docker internal networking for communication +- Data persists in Docker volumes between restarts (unless explicitly removed) \ No newline at end of file From 5ec2a0f7e4e20cbc14557e6d8d57d69b02ab8d80 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Tue, 17 Jun 2025 10:56:14 +0200 Subject: [PATCH 07/11] k8s folder removed due re-organization --- k8s/README.md | 155 ----------------------------------- k8s/cadence-samples-pod.yaml | 30 ------- k8s/docker/Dockerfile | 32 -------- 3 files changed, 217 deletions(-) delete mode 100644 k8s/README.md delete mode 100644 k8s/cadence-samples-pod.yaml delete mode 100644 k8s/docker/Dockerfile diff --git a/k8s/README.md b/k8s/README.md deleted file mode 100644 index f6b6804..0000000 --- a/k8s/README.md +++ /dev/null @@ -1,155 +0,0 @@ -# Cadence Samples Usage Guide - -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: - -```bash -docker build --build-arg CADENCE_HOST="cadence-frontend.cadence.svc.cluster.local:7833" -t cadence-samples:latest . -``` - -**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 . - -# Different namespace -docker build --build-arg CADENCE_HOST="cadence-frontend.my-namespace.svc.cluster.local:7833" -t cadence-samples:latest . -``` - -## 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. - -### Some 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/k8s/cadence-samples-pod.yaml b/k8s/cadence-samples-pod.yaml deleted file mode 100644 index e017a61..0000000 --- a/k8s/cadence-samples-pod.yaml +++ /dev/null @@ -1,30 +0,0 @@ -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/k8s/docker/Dockerfile b/k8s/docker/Dockerfile deleted file mode 100644 index c3ae556..0000000 --- a/k8s/docker/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -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 0d1589b149fe2d492734af90783089260113b8f2 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Fri, 20 Jun 2025 11:13:50 +0200 Subject: [PATCH 08/11] added all folders to final image --- docker/Dockerfile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 875775b..7b2d32d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ # Multi-stage build for optimization -FROM golang:1.21-alpine AS builder +FROM golang:1.24-alpine AS builder # Install build dependencies RUN apk add --no-cache make gcc musl-dev @@ -14,7 +14,7 @@ RUN go mod download # Copy source code COPY . . -# Build all samples +# Build all samples using existing Makefile RUN make # Final stage - minimal runtime image @@ -39,6 +39,12 @@ COPY --from=builder /app/bin/ ./bin/ # Copy configuration files COPY --from=builder /app/config/ ./config/ +# Copy cmd directory +COPY --from=builder /app/cmd/ ./cmd/ + +# Copy new_samples directory +COPY --from=builder /app/new_samples/ ./new_samples/ + # Update config file with the provided Cadence host RUN sed -i "s/host: \"localhost:7833\"/host: \"${CADENCE_HOST}\"/" config/development.yaml From 554bcdae8b0b8919b8bb76ed8d63e69985b25410 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Fri, 20 Jun 2025 11:18:17 +0200 Subject: [PATCH 09/11] using stable image --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 7b2d32d..ddd0d42 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ # Multi-stage build for optimization -FROM golang:1.24-alpine AS builder +FROM golang:1.21-alpine AS builder # Install build dependencies RUN apk add --no-cache make gcc musl-dev From 6384a39f0212d621dca05ee483ee5a5c7997931c Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Fri, 20 Jun 2025 11:19:11 +0200 Subject: [PATCH 10/11] using same version as build --- docker/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index ddd0d42..54fa309 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ -# Multi-stage build for optimization -FROM golang:1.21-alpine AS builder +# Multi-stage build for optimization (Image version from go.sum) +FROM golang:1.18-alpine AS builder # Install build dependencies RUN apk add --no-cache make gcc musl-dev From 5e53872d2cf9334eaa7e0b138e58fbb4749da412 Mon Sep 17 00:00:00 2001 From: CosminL-DEV <82363564+CosminL-DEV@users.noreply.github.com> Date: Fri, 20 Jun 2025 11:20:46 +0200 Subject: [PATCH 11/11] Update Dockerfile --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 54fa309..d2415ba 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -# Multi-stage build for optimization (Image version from go.sum) +# Multi-stage build for optimization (Image version from go.mod) FROM golang:1.18-alpine AS builder # Install build dependencies