Skip to content

Commit

Permalink
Adding bicep script to deploy azure function Dapr extension samples i…
Browse files Browse the repository at this point in the history
…n ACA (Azure#150)

* Adding bicep script to deply azure functions with dapr ext in ACA

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

* Adding bicep script to deply azure functions with dapr ext in ACA

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

* Fixed csproj file which causing docker image to fail in ACA

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

* Fixed csproj file which causing docker image to fail in ACA

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

* Fixed csproj file which causing docker image to fail in ACA

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

* Update samples/sample-infra/README.md

Co-authored-by: Shubham Sharma <[email protected]>

* creating bicep templates

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

* creating bicep templates

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

* Update samples/sample-infra/dapr-components.bicep

Co-authored-by: Shubham Sharma <[email protected]>

* creating bicep templates

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

---------

Signed-off-by: MD Ashique <[email protected]>
Co-authored-by: Shubham Sharma <[email protected]>
  • Loading branch information
ASHIQUEMD and shubham1172 authored Sep 20, 2023
1 parent d8ab3c7 commit d3c43b6
Show file tree
Hide file tree
Showing 7 changed files with 386 additions and 26 deletions.
21 changes: 0 additions & 21 deletions samples/dotnet-azurefunction/Startup.cs

This file was deleted.

6 changes: 1 addition & 5 deletions samples/dotnet-azurefunction/dotnet-azurefunction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
<RootNamespace>dotnet_azurefunction</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.1.1" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
</ItemGroup>
<ItemGroup>
<!-- Switch to Nuget Reference by uncommenting following line and removing the Project Reference -->
Expand Down
29 changes: 29 additions & 0 deletions samples/sample-infra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# azure-functions-dapr-aca-deployment
Steps to deploy the Azure Function with Dapr extension in ACA.

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

## Deploy azure function samples with Dapr extension in ACA
```
az deployment group create --resource-group {resourceGroupName} --template-file deploy-samples.bicep
```

## List of resources bicep will create

1. Azure Storage Account
2. Blob Service
3. Blob Container
4. Log Analytics Workspace
5. Application Insights
6. Managed Environment
7. Redis Cache
8. Event Hub Namespace
9. Event Hub Authorization Rule
10. Event Hub
11. Dapr Component for State Management
12. Dapr Component for Message Bus
13. Dapr Component for Event Hub
14. Azure Function App
59 changes: 59 additions & 0 deletions samples/sample-infra/azure-function.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
param envResourceNamePrefix string
param azStorageConnectionString string
param appInsightsConnectionString string
param environmentId string
param stateStoreName string

resource daprComponentStateManagement 'Microsoft.App/managedEnvironments/daprComponents@2023-05-01' existing = {
name: stateStoreName
}

/* ###################################################################### */
// Create Azure Function
/* ###################################################################### */
resource azfunctionapp 'Microsoft.Web/sites@2022-09-01' = {
name: '${envResourceNamePrefix}-funcapp'
location: 'East Asia (Stage)'
kind: 'functionapp,linux,container,azurecontainerapps'
properties: {
name: '${envResourceNamePrefix}-funcapp'
siteConfig: {
appSettings: [
{
name: 'AzureWebJobsStorage'
value: azStorageConnectionString
}
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: appInsightsConnectionString
}
{
name: 'PubSubName'
value: 'messagebus'
}
{
name: 'StateStoreName'
value: 'statestore'
}
{
name: 'KafkaBindingName'
value: 'sample-topic'
}
]
linuxFxVersion: 'Docker|mcr.microsoft.com/daprio/samples/dotnet-azurefunction:edge'
}
DaprConfig: {
enabled: true
appId: '${envResourceNamePrefix}-funcapp'
appPort: 3001
httpReadBufferSize: ''
httpMaxRequestSize: ''
logLevel: ''
enableApiLogging: true
}
managedEnvironmentId: environmentId
}
dependsOn: [
daprComponentStateManagement
]
}
141 changes: 141 additions & 0 deletions samples/sample-infra/azure-services.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
param location string
param redisCacheName string
param eventHubNamespace string
param eventHubName string
param eventHubSku string
param containerName string
param envResourceNamePrefix string

/* ###################################################################### */
// Create storage account for function app prereq
/* ###################################################################### */
resource azStorageAccount 'Microsoft.Storage/storageAccounts@2021-08-01' = {
name: '${envResourceNamePrefix}storage'
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}

var azStorageConnectionString = 'DefaultEndpointsProtocol=https;AccountName=${azStorageAccount.name};EndpointSuffix=${az.environment().suffixes.storage};AccountKey=${azStorageAccount.listKeys().keys[0].value}'

// Create blob service
resource blobService 'Microsoft.Storage/storageAccounts/blobServices@2019-06-01' = {
name: 'default'
parent: azStorageAccount
}

// Create container
resource container 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: containerName
parent: blobService
properties: {
publicAccess: 'None'
metadata: {}
}
}

/* ###################################################################### */
// Create managed ACA environment
/* ###################################################################### */
resource logAnalyticsWorkspace'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: '${envResourceNamePrefix}-la'
location: location
properties: any({
retentionInDays: 30
features: {
searchVersion: 1
}
sku: {
name: 'PerGB2018'
}
})
}

resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
name: '${envResourceNamePrefix}-ai'
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalyticsWorkspace.id
}
}

resource environment 'Microsoft.App/managedEnvironments@2022-10-01' = {
name: '${envResourceNamePrefix}-env'
location: location
properties: {
daprAIInstrumentationKey: appInsights.properties.InstrumentationKey
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
}
}

/* ###################################################################### */
// Create Redis Cache
/* ###################################################################### */
resource redisCache 'Microsoft.Cache/Redis@2020-06-01' = {
name: redisCacheName
location: location
properties: {
enableNonSslPort: true
minimumTlsVersion: '1.2'
sku: {
capacity: 1
family: 'C'
name: 'Standard'
}
}
}

/* ###################################################################### */
// Create Azure EventHub
/* ###################################################################### */
resource eventHubNamespaceResource 'Microsoft.EventHub/namespaces@2021-11-01' = {
name: eventHubNamespace
location: location
sku: {
name: eventHubSku
tier: eventHubSku
capacity: 1
}
properties: {
isAutoInflateEnabled: false
maximumThroughputUnits: 0
kafkaEnabled: true
}
}

resource eventHubAuth 'Microsoft.EventHub/namespaces/authorizationRules@2022-10-01-preview' = {
name: '${envResourceNamePrefix}-eventHubAuth'
parent: eventHubNamespaceResource
properties: {
rights: [
'Listen'
'Manage'
'Send'
]
}
}

resource eventHub 'Microsoft.EventHub/namespaces/eventhubs@2021-11-01' = {
parent: eventHubNamespaceResource
name: eventHubName
properties: {
messageRetentionInDays: 7
partitionCount: 1
}
}

output azStorageConnectionString string = azStorageConnectionString
output appInsightsConnectionString string = appInsights.properties.ConnectionString
output environmentId string = environment.id
output eventHubName string = eventHubName
output azStorageAccountName string = azStorageAccount.name
106 changes: 106 additions & 0 deletions samples/sample-infra/dapr-components.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
param azStorageConnectionString string
param envResourceNamePrefix string
param redisCacheName string
param eventHubName string
param azStorageAccountName string
param containerName string
param eventHubNamespace string

resource environment 'Microsoft.App/managedEnvironments@2022-10-01' existing = {
name: '${envResourceNamePrefix}-env'
}

resource redisCache 'Microsoft.Cache/Redis@2020-06-01' existing = {
name: redisCacheName
}

resource eventHubAuth 'Microsoft.EventHub/namespaces/authorizationRules@2022-10-01-preview' existing = {
name: '${eventHubNamespace}/${envResourceNamePrefix}-eventHubAuth'
}

/* ###################################################################### */
// Setup Dapr componet Redis state store in ACA
/* ###################################################################### */
resource daprComponentStateManagement 'Microsoft.App/managedEnvironments/daprComponents@2023-05-01' = {
parent: environment
name: 'statestore'
properties: {
componentType: 'state.redis'
version: 'v1'
metadata: [
{
name: 'redisHost'
value: '${redisCacheName}.redis.cache.windows.net:6379'
}
{
name: 'redisPassword'
value: redisCache.listKeys().primaryKey
}
]
scopes: []
}
}

/* ###################################################################### */
// Setup Dapr componet Redis message bus in ACA
/* ###################################################################### */
resource daprComponentMessagebus 'Microsoft.App/managedEnvironments/daprComponents@2023-05-01' = {
parent: environment
name: 'messagebus'
properties: {
componentType: 'pubsub.redis'
version: 'v1'
metadata: [
{
name: 'redisHost'
value: '${redisCacheName}.redis.cache.windows.net:6379'
}
{
name: 'redisPassword'
value: redisCache.listKeys().primaryKey
}
]
scopes: []
}
}

/* ###################################################################### */
// Setup Dapr component Eventhub in ACA
/* ###################################################################### */
resource daprComponentEventHub 'Microsoft.App/managedEnvironments/daprComponents@2023-05-01' = {
parent: environment
name: 'sample-topic'
properties: {
componentType: 'bindings.azure.eventhubs'
version: 'v1'
metadata: [
{
name: 'connectionString'
value: '${eventHubAuth.listKeys().primaryConnectionString};EntityPath=${eventHubName}'
}
{
name: 'storageConnectionString'
value: azStorageConnectionString
}
{
name: 'eventHub'
value: eventHubName
}
{
name: 'consumerGroup'
value: '$Default'
}
{
name: 'storageAccountName'
value: azStorageAccountName
}
{
name: 'storageContainerName'
value: containerName
}
]
scopes: []
}
}

output stateStoreName string = 'statestore'
Loading

0 comments on commit d3c43b6

Please sign in to comment.