Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add deployment to Azure (with Cosmos DB as push subscription store) #18

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions .github/workflows/deploy-to-azure-with-cosmos-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ on: workflow_dispatch

env:
PROJECT_NAME: demo-aspnetcore-pushnotifications
PROJECT_PATH: './Demo.AspNetCore.PushNotifications'
PROJECT_LOCATION: westeurope
PROJECT_APP_SERVICE_NAME: app-demo-aspnetcore-pushnotifications

permissions:
id-token: write
contents: read

jobs:
deploy-infrastructe:
deploy-infrastructure:
runs-on: ubuntu-latest
environment: azure
steps:
Expand All @@ -30,17 +32,43 @@ jobs:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
deploymentName: ${{ env.PROJECT_NAME }}
template: '"./infrastructure/azure/main.bicep"'
parameters: 'projectName=${{ env.PROJECT_NAME }} projectLocation=${{ env.PROJECT_LOCATION }}'
parameters: 'projectName=${{ env.PROJECT_NAME }} projectLocation=${{ env.PROJECT_LOCATION }} pushServiceClientSubject=${{ secrets.PUSHSERVICECLIENT_SUBJECT }} pushServiceClientPublicKey=${{ secrets.PUSHSERVICECLIENT_PUBLICKEY }} pushServiceClientPrivateKey=${{ secrets.PUSHSERVICECLIENT_PRIVATEKEY }}'
failOnStdErr: false
- name: Azure Logout
run: |
az logout
az cache purge
az account clear
build-and-deploy-webapp:
needs: [deploy-infrastructe]
needs: [deploy-infrastructure]
runs-on: ubuntu-latest
environment: azure
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v3
- name: Setup .NET 6.0 SDK
uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: '6.0.x'
- name: Restore
run: dotnet restore "${PROJECT_PATH}"
- name: Build
run: dotnet build "${PROJECT_PATH}" --configuration Release --no-restore
- name: Publish
run: dotnet publish "${PROJECT_PATH}" --configuration Release --no-build --output ${DOTNET_ROOT}/${PROJECT_APP_SERVICE_NAME}
- name: Azure Login
uses: azure/#@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Deploy
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.PROJECT_APP_SERVICE_NAME }}
package: ${{ env.DOTNET_ROOT }}/${{ env.PROJECT_APP_SERVICE_NAME }}
- name: Azure Logout
run: |
az logout
az cache purge
az account clear
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In order to run the project, some configuration is required. Inside *appsettings
}
```

Those keys can be acquired with help of online generators (https://vapidkeys.com/).
Those keys can be acquired with help of online generators (https://vapidkeys.com/, https://www.attheminute.com/vapid-key-generator).

## Donating

Expand Down
19 changes: 19 additions & 0 deletions infrastructure/azure/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@ targetScope = 'subscription'
param projectName string
param projectLocation string

@secure()
param pushServiceClientSubject string
@secure()
param pushServiceClientPublicKey string
@secure()
param pushServiceClientPrivateKey string

resource resourceGroupResource 'Microsoft.Resources/resourceGroups@2022-09-01' = {
name: 'rg-${projectName}'
location: projectLocation
}

module resourceGroupModule 'resource-group.bicep' = {
name: '${projectName}-rg'
scope: resourceGroup(resourceGroupResource.name)
params: {
projectName: projectName
projectLocation: resourceGroupResource.location
pushServiceClientSubject: pushServiceClientSubject
pushServiceClientPublicKey: pushServiceClientPublicKey
pushServiceClientPrivateKey: pushServiceClientPrivateKey
}
}
89 changes: 89 additions & 0 deletions infrastructure/azure/resource-group.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
targetScope = 'resourceGroup'

param projectName string
param projectLocation string = resourceGroup().location

@secure()
param pushServiceClientSubject string
@secure()
param pushServiceClientPublicKey string
@secure()
param pushServiceClientPrivateKey string

var projectAppServiceName = 'app-${length(projectName) > 56 ? substring(projectName, 0, 56) : projectName}'
var projectAppServicePlanName = 'asp-${length(projectName) > 36 ? substring(projectName, 0, 36) : projectName}'
var projectDocumentDBAccountName = 'cosmos-${uniqueString(resourceGroup().id)}'

resource projectDocumentDBAccount 'Microsoft.DocumentDB/databaseAccounts@2023-04-15' = {
name: projectDocumentDBAccountName
location: projectLocation
properties: {
enableFreeTier: true
databaseAccountOfferType: 'Standard'
consistencyPolicy: {
defaultConsistencyLevel: 'Session'
}
locations: [
{
locationName: projectLocation
}
]
}
}

resource projectAppServicePlan 'Microsoft.Web/serverfarms@2022-09-01' = {
name: projectAppServicePlanName
location: projectLocation
sku: {
name: 'F1'
}
kind: 'linux'
properties: {
reserved: true
}
}

resource projectAppService 'Microsoft.Web/sites@2022-09-01' = {
name: projectAppServiceName
location: projectLocation
properties: {
serverFarmId: projectAppServicePlan.id
siteConfig: {
linuxFxVersion: 'DOTNETCORE|6.0'
appSettings: [
{
name: 'PushSubscriptionStoreType'
value: 'CosmosDB'
}
{
name: 'CosmosDB__AccountEndpoint'
value: projectDocumentDBAccount.properties.documentEndpoint
}
{
name: 'CosmosDB__AuthKey'
value: projectDocumentDBAccount.listKeys().primaryMasterKey
}
{
name: 'CosmosDB__DatabaseName'
value: 'PushNotifications'
}
{
name: 'CosmosDB__ContainerName'
value: 'Subscriptions'
}
{
name: 'PushServiceClient__Subject'
value: pushServiceClientSubject
}
{
name: 'PushServiceClient__PublicKey'
value: pushServiceClientPublicKey
}
{
name: 'PushServiceClient__PrivateKey'
value: pushServiceClientPrivateKey
}
]
}
}
}