From 8ac94741f1c39be4182e6f27cc92c161be3f9141 Mon Sep 17 00:00:00 2001 From: Nelson Parente Date: Sat, 24 Oct 2026 04:03:22 +0200 Subject: [PATCH 1/5] feat(tutorials): add dapr-sqlite.yaml and a .http file for the .NET workflow tutorials Add dapr-sqlite.yaml to the .NET history propagation and versioning tutorials, in the shape of the other .NET tutorials: it is the same as dapr.yaml with the resources-sqlite folder, so both tutorials run without Docker and Redis. Add versioning.http to the .NET versioning tutorial. It starts the workflow and reads its status from the Dapr workflow API. Remove the sentence in the .NET tutorials README that says these two tutorials have no dapr-sqlite.yaml. The combined-patterns tutorials use Redis for pub/sub and no SQLite pub/sub component exists, so they keep dapr.yaml only. Signed-off-by: Nelson Parente Co-Authored-By: Claude Opus 5.5 --- tutorials/workflow/csharp/README.md | 2 +- .../csharp/history-propagation/dapr-sqlite.yaml | 7 +++++++ .../csharp/versioning/Versioning/dapr-sqlite.yaml | 12 ++++++++++++ .../csharp/versioning/Versioning/versioning.http | 10 ++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tutorials/workflow/csharp/history-propagation/dapr-sqlite.yaml create mode 100644 tutorials/workflow/csharp/versioning/Versioning/dapr-sqlite.yaml create mode 100644 tutorials/workflow/csharp/versioning/Versioning/versioning.http diff --git a/tutorials/workflow/csharp/README.md b/tutorials/workflow/csharp/README.md index 434b12e1f..ba3895c31 100644 --- a/tutorials/workflow/csharp/README.md +++ b/tutorials/workflow/csharp/README.md @@ -41,7 +41,7 @@ By default, the tutorials use Redis in Docker as the workflow state store, and t Use this option when Docker is not available or not allowed, for example on a locked-down laptop, in a CI job, or in a dev container without Docker. It also starts faster, because it has fewer moving parts. -The [Combined Patterns](./combined-patterns/README.md) tutorial also uses Redis for pub/sub, so it does not run this way. The [History Propagation](./history-propagation/README.md) and Versioning tutorials do not have a `dapr-sqlite.yaml` file. The commands are for Linux and macOS, and for Windows (PowerShell). +The [Combined Patterns](./combined-patterns/README.md) tutorial also uses Redis for pub/sub, so it does not run this way. The commands are for Linux and macOS, and for Windows (PowerShell). 1. Install the Dapr binaries. This command installs `daprd`, `placement`, and `scheduler` in `$HOME/.dapr/bin` (`$env:USERPROFILE\.dapr\bin` on Windows, with the `.exe` extension). It does not start them. diff --git a/tutorials/workflow/csharp/history-propagation/dapr-sqlite.yaml b/tutorials/workflow/csharp/history-propagation/dapr-sqlite.yaml new file mode 100644 index 000000000..976b8787c --- /dev/null +++ b/tutorials/workflow/csharp/history-propagation/dapr-sqlite.yaml @@ -0,0 +1,7 @@ +version: 1 +common: + resourcesPath: ../../resources-sqlite +apps: + - appID: patient-intake + appDirPath: ./patient-intake/ + command: ["dotnet", "run"] diff --git a/tutorials/workflow/csharp/versioning/Versioning/dapr-sqlite.yaml b/tutorials/workflow/csharp/versioning/Versioning/dapr-sqlite.yaml new file mode 100644 index 000000000..e0c858d5b --- /dev/null +++ b/tutorials/workflow/csharp/versioning/Versioning/dapr-sqlite.yaml @@ -0,0 +1,12 @@ +version: 1 +common: + resourcesPath: ../../../resources-sqlite +apps: + - appID: workflow-versioning + appDirPath: ./ + appPort: 5087 + daprHTTPPort: 3500 + daprGRPCPort: 50001 + command: ["dotnet", "run"] + appLogDestination: console + daprdLogDestination: console diff --git a/tutorials/workflow/csharp/versioning/Versioning/versioning.http b/tutorials/workflow/csharp/versioning/Versioning/versioning.http new file mode 100644 index 000000000..95c7fad4a --- /dev/null +++ b/tutorials/workflow/csharp/versioning/Versioning/versioning.http @@ -0,0 +1,10 @@ +@apphost=http://localhost:5087 + +### Start the NotifyUserWorkflow workflow +# @name startWorkflowRequest +GET {{ apphost }}/start + +### Get the workflow status +@instanceId={{startWorkflowRequest.response.body.*}} +@daprHost=http://localhost:3500 +GET {{ daprHost }}/v1.0/workflows/dapr/{{ instanceId }} From 4a79b07feff5d48251289f6ef44cb46a05333dcf Mon Sep 17 00:00:00 2001 From: Nelson Parente Date: Sat, 24 Oct 2026 04:03:23 +0200 Subject: [PATCH 2/5] feat(tutorials): add a runner script that validates a workflow tutorial tutorials/workflow/validate.sh builds and starts a workflow tutorial (dapr run -f for Python, .NET and Go, mvn spring-boot:test-run for Java), sends the requests of its .http file in order, and checks every workflow instance that a request started through GET /v1.0/workflows/dapr/. It exits 0 only when each instance reaches COMPLETED, or is gone after the .http file purges it. A tutorial with no .http file that runs its scenarios and exits is checked on its output. The script stops everything that it started. The .http parser reads @var lines, ### request blocks, # @name names, {{var}}, {{$guid}} and {{name.response.headers.X}} or {{name.response.body.path}} references. Signed-off-by: Nelson Parente Co-Authored-By: Claude Opus 5.5 --- tutorials/workflow/validate.sh | 511 +++++++++++++++++++++++++++++++++ 1 file changed, 511 insertions(+) create mode 100755 tutorials/workflow/validate.sh diff --git a/tutorials/workflow/validate.sh b/tutorials/workflow/validate.sh new file mode 100755 index 000000000..a172e867c --- /dev/null +++ b/tutorials/workflow/validate.sh @@ -0,0 +1,511 @@ +#!/usr/bin/env bash +# +# Copyright 2026 The Dapr Authors +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Usage: tutorials/workflow/validate.sh +# python | csharp | go | java +# a folder name under tutorials/workflow/, for example fundamentals +# +# What it does: +# 1. Builds the tutorial (python: uv venv + uv pip install, csharp: dotnet build, go: go build). +# 2. Starts it. python, csharp and go: `dapr run -f `. java: `mvn spring-boot:test-run`. +# 3. Sends the requests of the topic's .http file, in order. It reads the `@var = value` lines, +# the `###` request blocks, the `# @name` names, and the `{{var}}`, `{{$guid}}`, +# `{{name.response.headers.X}}` and `{{name.response.body.}}` references. +# 4. Checks every instance that a request started through GET /v1.0/workflows/dapr/. +# An instance must reach COMPLETED. An instance that the .http file purges must be gone. +# 5. Stops everything that it started and prints one RESULT line per instance. +# A topic with no .http file (an app that runs its scenarios and exits) is checked on the app output. +# +# It does not start the Dapr control plane. Before a python, csharp or go topic, the Scheduler and +# Placement services must run (the "Run the tutorials without Docker" section of the language +# README starts them) and, for combined-patterns, Redis on localhost:6379. +# Java topics start their own Dapr with Testcontainers and need a running Docker daemon. +# +# Environment: +# VALIDATE_RUN_FILE force the run file (default: dapr-sqlite.yaml when present, otherwise dapr.yaml) +# VALIDATE_TIMEOUT seconds that an instance may take to reach COMPLETED (default 180) +# VALIDATE_LOG_DIR where the app logs go (default: a new temporary folder) +# Exit code: 0 when every instance passes, 1 when one fails, 2 for a usage error. + +set -u + +LANG_=${1:-} +TOPIC=${2:-} +[ -n "$LANG_" ] && [ -n "$TOPIC" ] || { echo "usage: $0 " >&2; exit 2; } + +HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +DIR=$HERE/$LANG_/$TOPIC +[ -d "$DIR" ] || { echo "no such folder: $DIR" >&2; exit 2; } +TIMEOUT=${VALIDATE_TIMEOUT:-180} +LOGDIR=${VALIDATE_LOG_DIR:-$(mktemp -d "${TMPDIR:-/tmp}/validate-$LANG_-$TOPIC.XXXXXX")} +mkdir -p "$LOGDIR" + +say() { echo "[validate] $*"; } +fail() { say "FAIL: $*"; exit 1; } + +# One process group per started app, so that cleanup stops the children too. +PIDS=() +cleanup() { + local p + for p in "${PIDS[@]:-}"; do [ -n "$p" ] && kill -INT -- "-$p" 2>/dev/null; done + for _ in $(seq 1 20); do + local alive=0 + for p in "${PIDS[@]:-}"; do [ -n "$p" ] && kill -0 "$p" 2>/dev/null && alive=1; done + [ "$alive" = 0 ] && break + sleep 0.5 + done + for p in "${PIDS[@]:-}"; do [ -n "$p" ] && kill -9 -- "-$p" 2>/dev/null; done + if [ "$LANG_" = java ] && command -v docker > /dev/null 2>&1; then + local c; c=$(docker ps -aq --filter label=org.testcontainers=true 2>/dev/null) + [ -n "$c" ] && docker rm -f $c > /dev/null 2>&1 + fi + return 0 +} +trap cleanup EXIT +trap 'exit 130' INT TERM + +# start : run a command in its own process group, log to $LOGDIR/.log. +start() { + local name=$1 dir=$2; shift 2 + say "start $name in ${dir#$HERE/}: $*" + ( cd "$dir" && exec setsid "$@" ) > "$LOGDIR/$name.log" 2>&1 < /dev/null & + PIDS+=("$!") +} + +wait_port() { # wait_port + local end=$(( $(date +%s) + $2 )) + while [ "$(date +%s)" -lt "$end" ]; do + (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null && return 0 + for pid in "${PIDS[@]:-}"; do [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null && return 1; done + sleep 0.5 + done + return 1 +} +wait_healthz() { # wait_healthz + local end=$(( $(date +%s) + $2 )) code + while [ "$(date +%s)" -lt "$end" ]; do + code=$(curl -s -o /dev/null -m 3 -w '%{http_code}' "http://localhost:$1/v1.0/healthz") + case "$code" in 2*) return 0;; esac + sleep 0.5 + done + return 1 +} +show_logs() { + local f + for f in "$LOGDIR"/*.log; do [ -f "$f" ] && { say "--- tail of $f"; tail -n 40 "$f"; }; done +} + +# --- Find the run folder. csharp/versioning keeps its files in a Versioning subfolder. +APP=$DIR +if [ ! -f "$APP/dapr.yaml" ] && [ "$LANG_" != java ]; then + nested=$(find "$DIR" -mindepth 2 -maxdepth 2 -name dapr.yaml -print | head -n 2) + [ "$(echo "$nested" | wc -l)" = 1 ] && [ -n "$nested" ] && APP=$(dirname "$nested") +fi + +HTTP_FILE=$(find "$APP" -maxdepth 1 -name '*.http' -print | head -n 1) +[ -z "$HTTP_FILE" ] && HTTP_FILE=$(find "$APP" -maxdepth 2 -name '*.http' -print | head -n 1) + +# --- Build, then start. +APP_PORTS="" +DAPR_PORTS="" +case "$LANG_" in + python) + reqs="" + for r in $(find "$APP" -maxdepth 2 -name requirements.txt | sort); do reqs="$reqs -r $r"; done + [ -n "$reqs" ] || fail "no requirements.txt under $APP" + ( cd "$APP" && uv venv && uv pip install $reqs ) > "$LOGDIR/build.log" 2>&1 || { show_logs; fail "uv venv or uv pip install failed"; } + ;; + csharp) + for p in $(find "$APP" -maxdepth 2 -name '*.csproj' | sort); do + ( cd "$(dirname "$p")" && dotnet build ) > "$LOGDIR/build-$(basename "$p").log" 2>&1 || { show_logs; fail "dotnet build failed for $p"; } + done + ;; + go) + ( cd "$APP" && go build ./... ) > "$LOGDIR/build.log" 2>&1 || { show_logs; fail "go build failed"; } + ;; +esac + +if [ "$LANG_" = java ]; then + if [ -d "$APP/workflow-app" ] && [ -d "$APP/shipping-app" ]; then + # The README of combined-patterns: reuse the Testcontainers Dapr containers across the two apps. + grep -qs 'testcontainers.reuse.enable=true' "$HOME/.testcontainers.properties" 2>/dev/null \ + || echo 'testcontainers.reuse.enable=true' >> "$HOME/.testcontainers.properties" + # Start the second app after the first one is up, as the README does: both apps create the + # same Testcontainers network and Redis container. + start workflow-app "$APP/workflow-app" mvn clean -Dspring-boot.run.arguments="--reuse=true" spring-boot:test-run + wait_port 8080 900 || { show_logs; fail "app port 8080 did not open in 900 s"; } + start shipping-app "$APP/shipping-app" mvn clean -Dspring-boot.run.arguments="--reuse=true" spring-boot:test-run + APP_PORTS="8080 8081" + else + start app "$APP" mvn spring-boot:test-run + APP_PORTS="8080" + fi + DAPR_PORTS=docker + WAIT=900 +else + RUN_FILE=${VALIDATE_RUN_FILE:-} + if [ -z "$RUN_FILE" ]; then + if [ -f "$APP/dapr-sqlite.yaml" ]; then RUN_FILE=dapr-sqlite.yaml; else RUN_FILE=dapr.yaml; fi + fi + [ -f "$APP/$RUN_FILE" ] || fail "no run file $APP/$RUN_FILE" + APP_PORTS=$(sed -n 's/^[[:space:]]*appPort:[[:space:]]*\([0-9]*\).*/\1/p' "$APP/$RUN_FILE" | tr '\n' ' ') + DAPR_PORTS=$(sed -n 's/^[[:space:]]*daprHTTPPort:[[:space:]]*\([0-9]*\).*/\1/p' "$APP/$RUN_FILE" | paste -sd, -) + if [ "$LANG_" = python ]; then + start app "$APP" uv run dapr run -f "$RUN_FILE" + else + start app "$APP" dapr run -f "$RUN_FILE" + fi + WAIT=180 +fi + +# --- A topic with no .http file runs its scenarios and exits (history propagation). +if [ -z "$HTTP_FILE" ]; then + say "no .http file in ${APP#$HERE/}: checking the app output" + APPLOG=$LOGDIR/app.log + end=$(( $(date +%s) + 300 )) + while [ "$(date +%s)" -lt "$end" ]; do + grep -q 'SCENARIO 2' "$APPLOG" 2>/dev/null && grep -qE 'REFUSED' "$APPLOG" 2>/dev/null && break + kill -0 "${PIDS[0]}" 2>/dev/null || break + sleep 1 + done + sleep 2 + rc=0 + check() { # check