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/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..d2415ba --- /dev/null +++ b/docker/Dockerfile @@ -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"] \ No newline at end of file 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 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 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/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/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 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