Skip to content

Commit

Permalink
Adding documentation (Azure#165)
Browse files Browse the repository at this point in the history
* Adding documentation

Signed-off-by: MD Ashique <[email protected]>

* Adding documentation

Signed-off-by: MD Ashique <[email protected]>

* Adding documentation

Signed-off-by: MD Ashique <[email protected]>

* Adding documentation

Signed-off-by: MD Ashique <[email protected]>

* Adding documentation for tenant id

Signed-off-by: MD Ashique <[email protected]>

* Adding documentation

Signed-off-by: MD Ashique <[email protected]>

* Adding documentation

Signed-off-by: MD Ashique <[email protected]>

---------

Signed-off-by: MD Ashique <[email protected]>
  • Loading branch information
ASHIQUEMD authored Oct 6, 2023
1 parent eb953dd commit 1143d0d
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 210 deletions.
139 changes: 17 additions & 122 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ The Azure Functions Dapr extension allows you to easily interact with the Dapr A

This extension supports all the languages that Azure Function supports - [C# Isolated](./samples/dotnet-isolated-azurefunction), [C# Inproc](./samples/dotnet-azurefunction), [Java](./samples/java-azurefunction), [JavaScript / TypeScript](./samples/javascript-azurefunction), [Python V2](./samples/python-v2-azurefunction), [Python V1](./samples/python-azurefunction), [PowerShell](./samples/powershell-azurefunction).


If you are new to Azure Functions, it's recommended to [try out an Azure Function's quickstart first](https://docs.microsoft.com/azure/azure-functions/) to understand the basics of the programming model.

You can run through a quickstart of developing JavaScript Azure Functions that leverage Dapr following this [tutorial](./docs/quickstart.md)

You can easily deploy Azure Functions with the Dapr extension in Azure Container Apps (ACA) using a Bicep template. Follow the steps outlined in the [accompanying guide](./deploy/aca/aca-deployment.md).

## Function Triggers

Azure Function triggers cause a function to run. A trigger defines how a function is invoked and a function must have exactly one trigger. Triggers have associated data, which is often provided as the payload of the function.
Expand All @@ -36,44 +43,6 @@ Azure Function bindings is a way of declaratively connecting another resource to
| [daprPublish][publish-output-docs] | Output | Publish a message to a Dapr topic | [C# Isolated][csharp-isolated-publish-output], [C# Inproc][csharp-publish-output], [JavaScript][javascript-publish-output], [Python V2][python-v2-publish-output], [Python V1][python-publish-output], [Java][java-publish-output], [PowerShell][powershell-publish-output] |
| [daprBinding][binding-output-docs] | Output | Send a value to a Dapr output binding | [C# Isolated][csharp-isolated-binding-output], [C# Inproc][csharp-binding-output], [JavaScript][javascript-binding-output], [Python V2][python-v2-binding-output], [Python V1][python-binding-output], [Java][java-binding-output], [PowerShell][powershell-binding-output] |

## Quickstart

If you are new to Azure Functions, it's recommended to [try out an Azure Function's quickstart first](https://docs.microsoft.com/azure/azure-functions/) to understand the basics of the programming model.

You can run through a quickstart of developing JavaScript Azure Functions that leverage Dapr following this [tutorial](./docs/quickstart.md)

## Installing the extension

### .NET Functions

Run the following command from the path where your csproj is located to add the Nuget package to your Azure Function project

**Isolated Worker Process:**

```
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Dapr
```

**In-process**

```
dotnet add package Microsoft.Azure.WebJobs.Extensions.Dapr
```

### Non-.NET Functions

Since this extension is in Preview, you need to add the preview extension by adding or replacing the following code in your host.json file:

```
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
"version": "[4.*, 5.0.0)"
}
}
```

## Dapr ports and listeners

When you are triggering a function from Dapr, the extension will expose port 3001 automatically to listen to incoming requests from the Dapr sidecar. This port is configurable, you can provide any other available port in your app settings for `DAPR_APP_PORT` env variable instead of 3001.
Expand All @@ -86,91 +55,15 @@ You can override the Dapr address used by input and output bindings by setting t

The function app will still expose another port and endpoint for things like HTTP triggers (locally this defaults to 7071, in a container it defaults to 80).

## Running and debugging an app

Normally when debugging an Azure Function you use the `func` command line tool to start up the function app process and trigger your code. When debugging or running an Azure Function that will leverage Dapr, you need to use `dapr` alongside `func` so both processes are running.

So when running a Dapr app locally using the default ports, you would leverage the `dapr` CLI to start the `func` CLI.

### If no Dapr triggers are in the app
`dapr run --app-id functionA --dapr-http-port 3501 -- func host start --no-build`

### If Dapr triggers are in the app
`dapr run --app-id functionA --app-port 3001 --dapr-http-port 3501 -- func host start --no-build`

## Deploying to Kubernetes

You can annotate your function Kubernetes deployments to include the Dapr sidecar.

> IMPORTANT: Port 3001 will only be exposed and listened if a Dapr trigger is defined in the function app. When using Dapr, the sidecar will wait to receive a response from the defined port before completing instantiation. This means it is important to NOT define the `dapr.io/port` annotation or `--app-port` unless you have a trigger. Doing so may lock your application from the Dapr sidecar. Port 3001 does not need to be exposed or defined if only using input and output bindings.
To generate a Dockerfile for your app if you don't already have one, you can run the following command in your function project:
`func init --docker-only`.

The Azure Function core tools can automatically generate for you Kubernetes deployment files based on your local app. It's worth noting these manifests expect [KEDA](https://keda.sh) will be present to manage scaling, so if not using KEDA you may need to remove the `ScaledObjects` generated, or craft your own deployment YAML file. We do recommend including KEDA in any cluster that is running Azure Functions containers (with or without Dapr), but it is an optional component to assist with scaling.

An example of a function app deployment for Kubernetes can be [found below](#sample-kubernetes-deployment).

The following command will generate a `deploy.yaml` file for your project:
`func kubernetes deploy --name {container-name} --registry {docker-registry} --dry-run > deploy.yaml`

You can then edit the generated `deploy.yaml` to add the dapr annotations. You can also craft a deployment manually.

### Azure Storage account requirements

While an Azure Storage account is required to run functions within Azure, it is NOT required for functions that run in Kubernetes or from a Docker container. The exception to that is functions that leverage a Timer trigger or Event Hub trigger. In those cases the storage account is used to coordinate leases for instances, so you will need to set an `AzureWebJobsStorage` connection string if using those triggers. You can set the `AzureWebJobsStorage` value to `none` if not using any of the triggers that require it.

### Sample Kubernetes deployment

```yml
apiVersion: v1
kind: Service
metadata:
name: my-function
namespace: default
spec:
selector:
app: my-function
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-function
namespace: default
labels:
app: my-function
spec:
replicas: 1
selector:
matchLabels:
app: my-function
template:
metadata:
labels:
app: my-function
annotations:
dapr.io/enabled: "true"
dapr.io/id: "functionapp"
# Only define port of Dapr triggers are included
dapr.io/port: "3001"
spec:
containers:
- name: my-function
image: myregistry/my-function
ports:
# Port for HTTP triggered functions
- containerPort: 80
---
```

## Known Issues

- **By Design:** In out-of-proc model, support for POCO model isn't available for output bindings and triggers, all the payloads must send JSON data and these data should be used as JsonElement type in Azure Functions. Please look at the [Note section][dotnet-out-of-proc] to find out required values for each bindings and triggers.
- **By Design:** In isolated mode, there's no support for using POCO (Plain Old CLR Object) models in output bindings and triggers. All payloads must be sent as JSON data, and these data should be treated as the JsonElement type in Azure Functions. You can refer to the [input bindings][input-binding-details], [output bindings][output-binding-details], and [triggers][trigger-details] sections to understand the data format and the necessary properties for each type of binding.

## Deployments
Please follow below documentation to deploy Azure Functions with Dapr Extension.
1. [Local](./deploy/local/local-deployment.md)
2. [ACA](./deploy/aca/aca-deployment.md)
3. [Kubernetes](./deploy/kubernetes/kubernetes-deployment.md)

[binding-trigger-docs]: ./docs/triggers.md#input-binding-trigger
[service-invocation-trigger-docs]: ./docs/triggers.md#service-invocation-trigger
Expand Down Expand Up @@ -253,6 +146,8 @@ spec:
[powershell-binding-output]: ./samples/powershell-azurefunction/SendMessageToKafka/run.ps1


[dotnet-out-of-proc]: ./docs/dotnet-out-of-proc.md#Note
[input-binding-details]: ./docs/input-bindings.md
[output-binding-details]: ./docs/output-bindings.md
[trigger-details]: ./docs/triggers.md


11 changes: 9 additions & 2 deletions samples/sample-infra/README.md → deploy/aca/aca-deployment.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# azure-functions-dapr-aca-deployment
# Quickstart: Deploying to ACA
Steps to deploy the Azure Function with Dapr extension in ACA.

## Clone the Azure function Dapr Extension Repo
```
git clone https://github.com/Azure/azure-functions-dapr-extension.git
cd azure-functions-dapr-extension/aca-deployment
```

## Create resource group
```
az group create --name {resourceGroupName} --location eastasia
az group create --name {resourceGroupName} --location {region}
```

## Deploy azure function samples with Dapr extension in ACA
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
69 changes: 69 additions & 0 deletions deploy/kubernetes/kubernetes-deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Quickstart: Deploying to Kubernetes

You can annotate your function Kubernetes deployments to include the Dapr sidecar.

> IMPORTANT: Port 3001 will only be exposed and listened if a Dapr trigger is defined in the function app. When using Dapr, the sidecar will wait to receive a response from the defined port before completing instantiation. This means it is important to NOT define the `dapr.io/port` annotation or `--app-port` unless you have a trigger. Doing so may lock your application from the Dapr sidecar. Port 3001 does not need to be exposed or defined if only using input and output bindings.
To generate a Dockerfile for your app if you don't already have one, you can run the following command in your function project:
`func init --docker-only`.

The Azure Function core tools can automatically generate for you Kubernetes deployment files based on your local app. It's worth noting these manifests expect [KEDA](https://keda.sh) will be present to manage scaling, so if not using KEDA you may need to remove the `ScaledObjects` generated, or craft your own deployment YAML file. We do recommend including KEDA in any cluster that is running Azure Functions containers (with or without Dapr), but it is an optional component to assist with scaling.

An example of a function app deployment for Kubernetes can be [found below](#sample-kubernetes-deployment).

The following command will generate a `deploy.yaml` file for your project:
`func kubernetes deploy --name {container-name} --registry {docker-registry} --dry-run > deploy.yaml`

You can then edit the generated `deploy.yaml` to add the dapr annotations. You can also craft a deployment manually.

### Azure Storage account requirements

While an Azure Storage account is required to run functions within Azure, it is NOT required for functions that run in Kubernetes or from a Docker container. The exception to that is functions that leverage a Timer trigger or Event Hub trigger. In those cases the storage account is used to coordinate leases for instances, so you will need to set an `AzureWebJobsStorage` connection string if using those triggers. You can set the `AzureWebJobsStorage` value to `none` if not using any of the triggers that require it.

### Sample Kubernetes deployment

```yml
apiVersion: v1
kind: Service
metadata:
name: my-function
namespace: default
spec:
selector:
app: my-function
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-function
namespace: default
labels:
app: my-function
spec:
replicas: 1
selector:
matchLabels:
app: my-function
template:
metadata:
labels:
app: my-function
annotations:
dapr.io/enabled: "true"
dapr.io/id: "functionapp"
# Only define port of Dapr triggers are included
dapr.io/port: "3001"
spec:
containers:
- name: my-function
image: myregistry/my-function
ports:
# Port for HTTP triggered functions
- containerPort: 80
---
```
64 changes: 64 additions & 0 deletions deploy/local/local-deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Quickstart: Deploying to Local

## Installing the extension

### .NET Functions

Run the following command from the path where your csproj is located to add the Nuget package to your Azure Function project

**Isolated Worker Process:**

```
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Dapr --prerelease
```

**In-process**

```
dotnet add package Microsoft.Azure.WebJobs.Extensions.Dapr --prerelease
```

### Non-.NET Functions

Since this extension is in Preview, you need to add the preview extension by adding or replacing the following code in your host.json file:

```
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
"version": "[4.*, 5.0.0)"
}
}
```

## Using Dapr Extension local build

The samples in this repo (other than the quickstart) are set up to run using a local build of the extension.

You can use a development build of the extension for any function by:

- Referencing the Microsoft.Azure.WebJobs.Extensions.Dapr project in your .NET function
- Publishing the extension to the `bin/` directory of your non-.NET function

Example for non-.NET function:

```sh
dotnet publish /path/to/Microsoft.Azure.WebJobs.Extensions.Dapr -o bin/
```

## Running and debugging an app

Normally when debugging an Azure Function you use the `func` command line tool to start up the function app process and trigger your code. When debugging or running an Azure Function that will leverage Dapr, you need to use `dapr` alongside `func` so both processes are running.

So when running a Dapr app locally using the default ports, you would leverage the `dapr` CLI to start the `func` CLI.

### If no Dapr triggers are in the app
```sh
dapr run --app-id functionA --dapr-http-port 3501 -- func host start --no-build
```

### If Dapr triggers are in the app
```sh
dapr run --app-id functionA --app-port 3001 --dapr-http-port 3501 -- func host start --no-build
```
62 changes: 59 additions & 3 deletions docs/development/development.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,69 @@
# Setup Local Development

This document is a TODO.
This guide will help you set up the Azure Functions Dapr Extension in your local development environment. Follow these steps to get started.

## Prerequisites

## Clone the repository
Before you begin, ensure you have the following prerequisites installed:

- Setup Dapr: Follow instructions to [download and install the Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/) and [initialize Dapr](https://docs.dapr.io/getting-started/install-dapr-selfhost/)
- [Azure Functions Core Tools](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local)
- [.NET SDK](https://dotnet.microsoft.com/download)
- [Docker](https://www.docker.com/get-started)
- [Setup Dapr components](https://github.com/Azure/azure-functions-dapr-extension/tree/master/samples/components) if you need one

## Clone the Repository

To start, clone the Azure Functions Dapr Extension repository to your local machine. Use the following command in your terminal or Git client:

```bash
git clone https://github.com/Azure/azure-functions-dapr-extension.git
```

## Build the project
Once you have cloned the repository, navigate to the project directory and build the project. Use the following commands:
```
cd azure-functions-dapr-extension
dotnet build
```

## Run tests

To ensure everything is functioning correctly, it's a good practice to run the tests. Use the following command to run the tests:
```
dotnet test
```
## Debugging
To debug the Azure Functions Dapr Extension locally, you can use your preferred development environment, such as Visual Studio Code or Visual Studio. Set breakpoints in your code where needed, and use the appropriate debugging tools for your chosen development environment.

### Debugging in Visual Studio Code
1. Create/reuse existing samples to debug the extension.
2. Run the function app with below command.

> [!WARNING]
> Provide ` --app-port 3001` only when you have Dapr trigger(s) in your Azure function
```
dapr run --app-id functionapp --app-port 3001 --dapr-http-port 3501 -- func host start
```
3. Open Visual Studio Code, navigate to the project folder, and open the relevant code file.
4. Add breakpoints in your code where needed.
5. In Visual Studio Code, open the "Run and Debug" sidebar, select the configuration for your function, and click the "Run" button.
6. Visual Studio Code will automatically attach the debugger to the running process, and you can enjoy debugging.

### Debugging in Visual Studio
1. Create/reuse existing samples to debug the extension.
2. Run the function app with below command.

> [!WARNING]
> Provide ` --app-port 3001` only when you have Dapr trigger(s) in your Azure function
```
dapr run --app-id functionapp --app-port 3001 --dapr-http-port 3501 -- func host start
```
3. Open Visual Studio, navigate to the project folder, and open the relevant code file.
4. Add breakpoints in your code where needed.
5. In Visual Studio, select the "Debug" menu, then choose "Attach to Process..."
6. Choose the func process or provide the corresponding process ID.
7. Click the "Attach" button to attach the debugger.


That's it! You're now set up for local development with the Azure Functions Dapr Extension. You can start building and testing your Azure Functions with Dapr support locally.
Loading

0 comments on commit 1143d0d

Please sign in to comment.