Skip to content

Commit 46ab0b1

Browse files
authored
Support for Docker & Kubernetes added (#93)
1 parent 02594b0 commit 46ab0b1

File tree

3 files changed

+217
-0
lines changed

3 files changed

+217
-0
lines changed

k8s/README.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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.

k8s/cadence-samples-pod.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: cadence-samples
5+
namespace: cadence # Replace with your cadence namespace
6+
labels:
7+
app: cadence-samples
8+
spec:
9+
containers:
10+
- name: cadence-samples
11+
image: cadence-samples:latest # Replace with your built image
12+
imagePullPolicy: IfNotPresent
13+
command: ["/bin/bash"]
14+
args: ["-c", "sleep infinity"]
15+
workingDir: /home/cadence
16+
env:
17+
- name: HOME
18+
value: "/home/cadence"
19+
resources:
20+
requests:
21+
memory: "128Mi"
22+
cpu: "100m"
23+
limits:
24+
memory: "1Gi"
25+
cpu: "1"
26+
restartPolicy: Always
27+
securityContext:
28+
runAsUser: 1001
29+
runAsGroup: 1001
30+
fsGroup: 1001

k8s/docker/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM golang:1.21-alpine
2+
3+
# Install all necessary dependencies for building and running
4+
RUN apk add --no-cache git make gcc musl-dev ca-certificates nano curl bash sed
5+
6+
# Build argument for Cadence host configuration
7+
ARG CADENCE_HOST=localhost:7833
8+
9+
# Create non-root user
10+
RUN addgroup -g 1001 cadence && \
11+
adduser -D -u 1001 -G cadence cadence
12+
13+
# Set working directory
14+
WORKDIR /home/cadence
15+
16+
# Clone cadence-samples repository
17+
RUN git clone https://github.com/cadence-workflow/cadence-samples.git .
18+
19+
# Update config file with the provided Cadence host
20+
RUN sed -i "s/host: \"localhost:7833\"/host: \"${CADENCE_HOST}\"/" config/development.yaml
21+
22+
# Build all samples
23+
RUN make
24+
25+
# Change ownership of files
26+
RUN chown -R cadence:cadence /home/cadence
27+
28+
# Switch to non-root user
29+
USER cadence
30+
31+
# Default command - interactive shell
32+
CMD ["/bin/bash"]

0 commit comments

Comments
 (0)