-
Notifications
You must be signed in to change notification settings - Fork 9
Add Cadence Samples: Dockerfile, Deployment YAML, and Usage Guide #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CosminL-DEV
wants to merge
3
commits into
cadence-workflow:main
Choose a base branch
from
CosminL-DEV:cadence-samples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <cadence-frontend-pod-name> -n cadence -- /bin/bash | ||
|
||
# Register the default domain | ||
cadence --address $(hostname -i):7833 \ | ||
--transport grpc \ | ||
--domain default \ | ||
domain register \ | ||
--retention 1 | ||
``` | ||
|
||
**Note**: Replace `<cadence-frontend-pod-name>` 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 -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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for dockerizing this. We can do this in the samples repo and have CI to push image to dockerhub. This way, chart users can simply use it and avoid bunch of steps. I will track this separately.