Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7c7c711

Browse files
committedMay 21, 2025·
Add dockerfile and docs
1 parent 769c94e commit 7c7c711

File tree

6 files changed

+221
-0
lines changed

6 files changed

+221
-0
lines changed
 
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Build stage
2+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
3+
ARG BUILD_CONFIGURATION=Release
4+
WORKDIR /src
5+
6+
# Copy solution and project files
7+
COPY post-dapr-output-binding.sln ./
8+
COPY Drasi.Reactions.PostDaprOutputBinding/Drasi.Reactions.PostDaprOutputBinding.csproj ./Drasi.Reactions.PostDaprOutputBinding/
9+
10+
# Restore dependencies
11+
RUN dotnet restore "./Drasi.Reactions.PostDaprOutputBinding/Drasi.Reactions.PostDaprOutputBinding.csproj"
12+
13+
# Copy only the source code
14+
COPY Drasi.Reactions.PostDaprOutputBinding/ ./Drasi.Reactions.PostDaprOutputBinding/
15+
16+
# Build the reaction project
17+
WORKDIR /src/Drasi.Reactions.PostDaprOutputBinding
18+
RUN dotnet publish "./Drasi.Reactions.PostDaprOutputBinding.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
19+
20+
# Final stage/image
21+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
22+
WORKDIR /app
23+
COPY --from=build /app/publish .
24+
25+
# Set log levels for reaction in production
26+
ENV Logging__LogLevel__Default="Debug"
27+
ENV Logging__LogLevel__Microsoft="Warning"
28+
ENV Logging__LogLevel__Microsoft_Hosting_Lifetime="Information"
29+
ENV Logging__LogLevel__Drasi_Reactions_PostDaprOutputBinding "Debug"
30+
31+
USER app
32+
ENTRYPOINT ["dotnet", "Drasi.Reactions.PostDaprOutputBinding.dll"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Build stage
2+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
3+
ARG BUILD_CONFIGURATION=Release
4+
WORKDIR /src
5+
6+
# Copy solution and project files
7+
COPY post-dapr-output-binding.sln ./
8+
COPY Drasi.Reactions.PostDaprOutputBinding/Drasi.Reactions.PostDaprOutputBinding.csproj ./Drasi.Reactions.PostDaprOutputBinding/
9+
10+
# Restore dependencies
11+
RUN dotnet restore "./Drasi.Reactions.PostDaprOutputBinding/Drasi.Reactions.PostDaprOutputBinding.csproj"
12+
13+
# Copy only the source code
14+
COPY Drasi.Reactions.PostDaprOutputBinding/ ./Drasi.Reactions.PostDaprOutputBinding/
15+
16+
# Build the reaction project
17+
WORKDIR /src/Drasi.Reactions.PostDaprOutputBinding
18+
RUN dotnet publish "./Drasi.Reactions.PostDaprOutputBinding.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
19+
20+
# Final stage/image
21+
FROM ubuntu:25.04 AS final
22+
RUN apt-get update && apt-get install -y bash curl dotnet-runtime-8.0 aspnetcore-runtime-8.0 && rm -rf /var/lib/apt/lists/*
23+
WORKDIR /app
24+
COPY --from=build /app/publish .
25+
26+
# Set log levels for reaction in debug environment
27+
ENV Logging__LogLevel__Default="Debug"
28+
ENV Logging__LogLevel__Microsoft="Information"
29+
ENV Logging__LogLevel__Microsoft_Hosting_Lifetime="Information"
30+
ENV Logging__LogLevel__Drasi_Reactions_PostDaprPubSub="Debug"
31+
32+
USER app
33+
ENTRYPOINT ["dotnet", "Drasi.Reactions.PostDaprOutputBinding.dll"]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.PHONY: default docker-build kind-load k3d-load test clean
2+
3+
CLUSTER_NAME ?= kind
4+
IMAGE_PREFIX ?= drasi-project
5+
DOCKER_TAG_VERSION ?= latest
6+
DOCKERX_OPTS ?= --load --cache-to type=inline,mode=max
7+
8+
default: docker-build
9+
10+
# Build the Docker image for the reaction
11+
docker-build:
12+
docker buildx build . --no-cache -t $(IMAGE_PREFIX)/post-dapr-output-binding:$(DOCKER_TAG_VERSION) $(DOCKERX_OPTS) -f Dockerfile
13+
14+
# Load the built image into the specified Kind cluster
15+
kind-load:
16+
kind load docker-image $(IMAGE_PREFIX)/post-dapr-output-binding:$(DOCKER_TAG_VERSION) --name $(CLUSTER_NAME)
17+
18+
# Load the built image into the specified k3d cluster
19+
k3d-load: CLUSTER_NAME=k3s-default
20+
k3d-load:
21+
k3d image import $(IMAGE_PREFIX)/post-dapr-output-binding:$(DOCKER_TAG_VERSION) -c $(CLUSTER_NAME)
22+
23+
# Run unit tests
24+
test:
25+
dotnet test post-dapr-output-binding.sln
26+
27+
lint-check:
28+
@echo "No lint checks to run yet"
29+
30+
# Clean build artifacts
31+
clean:
32+
dotnet clean post-dapr-output-binding.sln
33+
rm -rf */bin */obj
34+
rm -rf Drasi.Reactions.PostDaprOutputBinding.Tests/TestResults
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Post Dapr Output Binding Reaction
2+
3+
This reaction forwards Drasi query results to Dapr Output Binding. It allows mapping each Drasi query to a specific Dapr Output Binding component with a specified operation.
4+
5+
## Features
6+
7+
- Maps Drasi queries to Dapr Output Binding
8+
- Supports both packed and unpacked event formats (unpacked is default, using Drasi native format)
9+
- Forwards both change events and control signals
10+
- Configurable per query
11+
- Automatic tracking of query failure states
12+
- Validation of configurations at startup
13+
14+
## Configuration
15+
16+
The reaction is configured using JSON for each query. The configuration includes:
17+
18+
| Parameter | Description | Default | Required |
19+
|-----------|-------------|---------|----------|
20+
| `bindingName` | Name of the Dapr Output Binding component | `drasi-binding` | Yes |
21+
| `bindingType` | The type of the Output Binding | - | Yes |
22+
| `bindingOperation` | The operation to run | - | Yes |
23+
| `packed` | Whether to send events in packed format (`true`) or unpacked (`false`) | `false` | No |
24+
| `maxFailureCount` | Max failures before query is marked as failed | `5` | No |
25+
| `skipControlSignals` | Skip publishing control signals | `false` | No |
26+
27+
### Example Configuration
28+
29+
```yaml
30+
kind: Reaction
31+
apiVersion: v1
32+
name: post-dapr-output-binding
33+
spec:
34+
kind: PostDaprOutputBinding
35+
properties:
36+
# No global properties needed for this reaction
37+
queries:
38+
example-query: |
39+
{
40+
"bindingName": "drasi-output-binding",
41+
"bindingType": "http",
42+
"bindingOperation": "put"
43+
"packed": false,
44+
"maxFailureCount": 5,
45+
"skipControlSignals": false
46+
}
47+
another-query: |
48+
{
49+
"bindingName": "drasi-output-binding",
50+
"bindingType": "http",
51+
"bindingOperation": "get"
52+
"packed": false,
53+
"maxFailureCount": 5,
54+
"skipControlSignals": false
55+
}
56+
control-signals-skipped: |
57+
{
58+
"bindingName": "drasi-output-binding",
59+
"bindingType": "http",
60+
"bindingOperation": "get"
61+
"packed": false,
62+
"maxFailureCount": 5,
63+
"skipControlSignals": true
64+
}
65+
```
66+
67+
## Event Formats
68+
69+
### Packed vs. Unpacked
70+
71+
- **Packed format**: The entire ChangeEvent or ControlEvent is sent as a single message to the topic.
72+
- **Unpacked format (Default)**: Individual messages are created for each change or control signal.
73+
74+
### Drasi Native Format (for Unpacked Events)
75+
76+
The native Drasi format uses these operation types:
77+
- Insert operations (I): For new data added
78+
- Update operations (U): For data changes
79+
- Delete operations (D): For data removed
80+
- Control signals (X): For system events
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ReactionProvider
3+
name: PostDaprOutputBinding
4+
spec:
5+
services:
6+
reaction:
7+
image: reaction-post-dapr-output-binding
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
kind: Reaction
2+
apiVersion: v1
3+
name: post-dapr-output-binding
4+
spec:
5+
kind: PostDaprOutputBinding
6+
properties:
7+
# No global properties needed for this reaction
8+
queries:
9+
example-query: |
10+
{
11+
"bindingName": "drasi-output-binding",
12+
"bindingType": "http",
13+
"bindingOperation": "put"
14+
"packed": false,
15+
"maxFailureCount": 5,
16+
"skipControlSignals": false
17+
}
18+
another-query: |
19+
{
20+
"bindingName": "drasi-output-binding",
21+
"bindingType": "http",
22+
"bindingOperation": "get"
23+
"packed": false,
24+
"maxFailureCount": 5,
25+
"skipControlSignals": false
26+
}
27+
control-signals-skipped: |
28+
{
29+
"bindingName": "drasi-output-binding",
30+
"bindingType": "http",
31+
"bindingOperation": "get"
32+
"packed": false,
33+
"maxFailureCount": 5,
34+
"skipControlSignals": true
35+
}

0 commit comments

Comments
 (0)
Please sign in to comment.