Skip to content

Move k8s to docker, optimize Dockerfile, add compose and monitoring setup #94

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
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ test.log
vendor/
# Executables produced by cadence-samples repo
bin/
docker-compose.yml
61 changes: 61 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Multi-stage build for optimization (Image version from go.mod)
FROM golang:1.18-alpine AS builder

# Install build dependencies
RUN apk add --no-cache 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 using existing Makefile
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/

# 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

# 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"]
206 changes: 206 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -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)
91 changes: 91 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions docker/grafana/dashboards/.exists
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions docker/grafana/grafana.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[auth.anonymous]
enabled = true
org_role = Admin
7 changes: 7 additions & 0 deletions docker/grafana/provisioning/datasources/default.yml
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
Loading