-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
537 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+47.4 KB
docs/content/guides/author-apps/application/overview/graph-automation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
type: docs | ||
title: "Dapr building blocks" | ||
linkTitle: "Dapr" | ||
description: "Easily leverage Dapr building blocks in your application for code and infrastructure portability" | ||
weight: 500 | ||
slug: "dapr" | ||
categories: "Concept" | ||
tags: ["Dapr"] | ||
--- | ||
|
||
Radius offers first-class support for the [Dapr](https://dapr.io) runtime and building blocks to make it easy to make your code fully portable across code and infrastructure. Simply drop in your Dapr building blocks as resources and Radius will automatically configure and apply the accompanying Dapr configuration. | ||
|
||
## Installation | ||
|
||
Follow the [Dapr installation instructions](https://docs.dapr.io/operations/hosting/kubernetes/kubernetes-deploy/) to install Dapr in your Kubernetes cluster. Once installed, you can begin adding Dapr sidecars and building blocks. | ||
|
||
{{< button text="Setup Dapr" link="https://docs.dapr.io/operations/hosting/kubernetes/kubernetes-deploy/" newtab="true" >}} | ||
|
||
## Sidecar | ||
|
||
A [Dapr sidecar](https://docs.dapr.io/concepts/dapr-services/sidecar/) allows your services to interact with Dapr building blocks. It is required if your service leverages Dapr. | ||
|
||
<img src="dapr-sidecar.png" style="width:600px" alt="Diagram of the Dapr sidecar" /><br /> | ||
|
||
You can easily add the Dapr sidecar to your [Containers]({{< ref "guides/author-apps/containers" >}}) using a Dapr sidecar extension: | ||
|
||
{{< tabs Bicep >}} | ||
|
||
{{% codetab %}} | ||
{{< rad file="snippets/sidecar.bicep" embed=true marker="//CONTAINER" >}} | ||
{{% /codetab %}} | ||
|
||
{{< /tabs >}} | ||
|
||
Your container can now interact with the sidecar using the Dapr [building block APIs](https://docs.dapr.io/concepts/building-blocks-concept/) or the [Dapr SDKs](https://docs.dapr.io/developing-applications/sdks/). | ||
|
||
## Building blocks | ||
|
||
Dapr resources make it easy to model and configure [Dapr building block APIs](https://docs.dapr.io/developing-applications/building-blocks/). Simply specify the building block and the backing resource, and Radius will apply the accompanying Dapr component configuration. | ||
|
||
<img src="dapr-buildingblocks.png" style="width:1000px" alt="Diagram of all the Dapr building blocks" /><br /> | ||
|
||
Model your building blocks as resources: | ||
|
||
{{< tabs Bicep >}} | ||
|
||
{{< codetab >}} | ||
{{< rad file="snippets/statestore.bicep" embed=true marker="//STATESTORE" >}} | ||
{{< /codetab >}} | ||
|
||
{{< /tabs >}} | ||
|
||
### Component naming | ||
|
||
To interact with a Dapr building block, you need to know the name of the [Dapr component](https://docs.dapr.io/concepts/components-concept/). This name is the same as the name of the building block resource. | ||
|
||
For example, if you have a `Applications.Dapr/stateStores` resource named `mystatestore` the Dapr component name will be `mystatestore`. Your code will then interact with this component via `http://localhost:3500/v1.0/state/mystatestore`, or via the Dapr SDKs through the `mystatestore` component name. | ||
|
||
### Connecting to Dapr building blocks | ||
|
||
You can connect to a Dapr building block by manually referencing the resource name or by adding a connection. Connections automatically inject environment variables into your container with the resource name prefixed. | ||
|
||
{{< rad file="snippets/dapr-componentname.bicep" embed=true marker="//MARKER" replace-key-ss="//STATESTORE" replace-value-ss="resource statestore 'Applications.Dapr/stateStores@2022-03-15-privatepreview' = {...}" >}} | ||
|
||
### Service invocation | ||
|
||
Dapr [service invocation](https://docs.dapr.io/developing-applications/building-blocks/service-invocation/service-invocation-overview/) allows your services to discover and call each other. | ||
|
||
One container in an application can invoke another using the `AppId`. | ||
|
||
{{< tabs Bicep >}} | ||
|
||
{{< codetab >}} | ||
{{< rad file="snippets/service-invocation.bicep" embed=true marker="//INVOKE" >}} | ||
{{< /codetab >}} | ||
|
||
{{< /tabs >}} | ||
|
||
## Resource schema | ||
|
||
Refer to the [schema reference docs]({{< ref dapr-schema >}}) for more information on how to model Dapr resources. |
66 changes: 66 additions & 0 deletions
66
docs/content/guides/author-apps/dapr/snippets/dapr-componentname.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import radius as rad | ||
|
||
param environment string | ||
|
||
resource account 'Microsoft.Storage/storageAccounts@2019-06-01' existing = { | ||
name: 'myaccount' | ||
|
||
resource tableServices 'tableServices' existing = { | ||
name: 'default' | ||
|
||
resource table 'tables' existing = { | ||
name: 'mytable' | ||
} | ||
} | ||
} | ||
|
||
resource app 'Applications.Core/applications@2022-03-15-privatepreview' = { | ||
name: 'myapp' | ||
properties: { | ||
environment: environment | ||
} | ||
} | ||
|
||
//MARKER | ||
resource container 'Applications.Core/containers@2022-03-15-privatepreview' = { | ||
name: 'mycontainer' | ||
properties: { | ||
application: app.id | ||
container: { | ||
image: 'myimage' | ||
env: { | ||
// Option 1: Manually set component name as an environment variable | ||
DAPR_COMPONENTNAME: statestore.name | ||
} | ||
} | ||
connections: { | ||
// Option 2 (preferred): Automatically set environment variable with component name | ||
c1: { | ||
source: statestore.id // Results in CONNECTION_C1_COMPONENTNAME | ||
} | ||
} | ||
} | ||
} | ||
|
||
//STATESTORE | ||
resource statestore 'Applications.Dapr/stateStores@2022-03-15-privatepreview' = { | ||
name: 'mystatestore' | ||
properties: { | ||
environment: environment | ||
application: app.id | ||
resourceProvisioning: 'manual' | ||
resources: [ | ||
{ id: account.id } | ||
{ id: account::tableServices::table.id } | ||
] | ||
metadata: { | ||
accountName: account.name | ||
accountKey: account.listKeys().keys[0].value | ||
tableName: account::tableServices::table.name | ||
} | ||
type: 'state.azure.tablestorage' | ||
version: 'v1' | ||
} | ||
} | ||
//STATESTORE | ||
//MARKER |
45 changes: 45 additions & 0 deletions
45
docs/content/guides/author-apps/dapr/snippets/service-invocation.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import radius as rad | ||
|
||
|
||
resource app 'Applications.Core/applications@2022-03-15-privatepreview' existing = { | ||
name: 'myapp' | ||
} | ||
|
||
// Backend is being invoked through service invocation | ||
resource backend 'Applications.Core/containers@2022-03-15-privatepreview' = { | ||
name: 'backend' | ||
properties: { | ||
application: app.id | ||
container: { | ||
image: 'backend:latest' | ||
} | ||
extensions: [ | ||
{ | ||
kind: 'daprSidecar' | ||
appId: 'backend' | ||
} | ||
] | ||
} | ||
} | ||
|
||
|
||
// Frontend invokes backend | ||
resource frontend 'Applications.Core/containers@2022-03-15-privatepreview' = { | ||
name: 'frontend' | ||
properties: { | ||
application: app.id | ||
container: { | ||
image: 'frontend:latest' | ||
env: { | ||
// Configures the appID of the backend service. | ||
CONNECTION_BACKEND_APPID: 'backend' | ||
} | ||
} | ||
extensions: [ | ||
{ | ||
kind: 'daprSidecar' | ||
appId: 'frontend' | ||
} | ||
] | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
docs/content/guides/author-apps/dapr/snippets/sidecar.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import radius as radius | ||
|
||
param environment string | ||
|
||
resource app 'Applications.Core/applications@2022-03-15-privatepreview' = { | ||
name: 'myapp' | ||
properties: { | ||
environment: environment | ||
} | ||
} | ||
|
||
//CONTAINER | ||
resource container 'Applications.Core/containers@2022-03-15-privatepreview' = { | ||
name: 'mycontainer' | ||
properties: { | ||
application: app.id | ||
container: { | ||
image: 'myimage' | ||
} | ||
extensions: [ | ||
{ | ||
kind: 'daprSidecar' | ||
appId: 'mycontainer' | ||
appPort: 3500 | ||
} | ||
] | ||
} | ||
} | ||
//CONTAINER |
46 changes: 46 additions & 0 deletions
46
docs/content/guides/author-apps/dapr/snippets/statestore.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import radius as radius | ||
|
||
param environment string | ||
|
||
|
||
resource app 'Applications.Core/applications@2022-03-15-privatepreview' = { | ||
name: 'myapp' | ||
properties: { | ||
environment: environment | ||
} | ||
} | ||
|
||
//STATESTORE | ||
resource account 'Microsoft.Storage/storageAccounts@2019-06-01' existing = { | ||
name: 'myaccount' | ||
|
||
resource tableServices 'tableServices' existing = { | ||
name: 'default' | ||
|
||
resource table 'tables' existing = { | ||
name: 'mytable' | ||
} | ||
} | ||
} | ||
|
||
// The accompanying Dapr component resource is automatically created for you | ||
resource stateStore 'Applications.Dapr/stateStores@2022-03-15-privatepreview' = { | ||
name: 'mystatestore' | ||
properties: { | ||
environment: environment | ||
application: app.id | ||
resourceProvisioning: 'manual' | ||
resources: [ | ||
{ id: account.id } | ||
{ id: account::tableServices::table.id } | ||
] | ||
metadata: { | ||
accountName: account.name | ||
accountKey: account.listKeys().keys[0].value | ||
tableName: account::tableServices::table.name | ||
} | ||
type: 'state.azure.tablestorage' | ||
version: 'v1' | ||
} | ||
} | ||
//STATESTORE |
Oops, something went wrong.