Skip to content

Commit 5261069

Browse files
authored
Merge pull request #51 from seesharprun/rework
Rework
2 parents 5538fba + d3d508b commit 5261069

File tree

11 files changed

+113
-127
lines changed

11 files changed

+113
-127
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"image": "mcr.microsoft.com/devcontainers/dotnet:latest",
2+
"image": "mcr.microsoft.com/devcontainers/dotnet:9.0",
33
"features": {
44
"ghcr.io/azure/azure-dev/azd:latest": {},
55
"ghcr.io/devcontainers/features/azure-cli:latest": {},

.github/workflows/azure-dev.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Run when commits are pushed to main
2+
on:
3+
workflow_dispatch:
4+
push:
5+
# Run when commits are pushed to mainline branch (main or master)
6+
# Set this to the mainline branch you are using
7+
branches:
8+
- main
9+
10+
# Set up permissions for deploying with secretless Azure federated credentials
11+
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication
12+
permissions:
13+
id-token: write
14+
contents: read
15+
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
env:
21+
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
22+
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
23+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
24+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
25+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
- name: Install azd
30+
uses: Azure/[email protected]
31+
- name: Log in with Azure (Federated Credentials)
32+
run: |
33+
azd auth login `
34+
--client-id "$Env:AZURE_CLIENT_ID" `
35+
--federated-credential-provider "github" `
36+
--tenant-id "$Env:AZURE_TENANT_ID"
37+
shell: pwsh
38+
39+
40+
- name: Provision Infrastructure
41+
run: azd provision --no-prompt
42+
env:
43+
AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }}
44+
45+
- name: Deploy Application
46+
run: azd deploy --no-prompt

infra/app/database.bicep

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,31 @@ param appPrincipalId string
1010
@description('Id of the user principals to assign database and application roles.')
1111
param userPrincipalId string = ''
1212

13-
var database = {
14-
name: 'cosmicworks' // Based on AdventureWorksLT data set
15-
}
16-
17-
var containers = [
18-
{
19-
name: 'products' // Set of products
20-
partitionKeyPaths: [
21-
'/category' // Partition on the product category
22-
]
23-
autoscale: true // Scale at the container level
24-
throughput: 1000 // Enable autoscale with a minimum of 100 RUs and a maximum of 1,000 RUs
25-
}
26-
]
27-
2813
module cosmosDbAccount 'br/public:avm/res/document-db/database-account:0.6.1' = {
2914
name: 'cosmos-db-account'
3015
params: {
3116
name: accountName
3217
location: location
18+
locations: [
19+
{
20+
failoverPriority: 0
21+
locationName: location
22+
isZoneRedundant: false
23+
}
24+
]
3325
tags: tags
3426
disableKeyBasedMetadataWriteAccess: true
3527
disableLocalAuth: true
28+
capabilitiesToAdd: [
29+
'EnableServerless'
30+
]
3631
sqlRoleDefinitions: [
3732
{
3833
name: 'nosql-data-plane-contributor'
3934
dataAction: [
40-
'Microsoft.DocumentDB/databaseAccounts/readMetadata' // Read account metadata
41-
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*' // Create items
42-
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*' // Manage items
35+
'Microsoft.DocumentDB/databaseAccounts/readMetadata'
36+
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*'
37+
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*'
4338
]
4439
}
4540
]
@@ -55,18 +50,18 @@ module cosmosDbAccount 'br/public:avm/res/document-db/database-account:0.6.1' =
5550
)
5651
sqlDatabases: [
5752
{
58-
name: database.name
53+
name: 'cosmicworks'
5954
containers: [
60-
for container in containers: {
61-
name: container.name
62-
paths: container.partitionKeyPaths
63-
autoscaleSettingsMaxThroughput: container.throughput
55+
{
56+
name: 'products'
57+
paths: [
58+
'/category'
59+
]
6460
}
6561
]
6662
}
6763
]
6864
}
6965
}
7066

71-
output name string = cosmosDbAccount.outputs.name
7267
output endpoint string = cosmosDbAccount.outputs.endpoint

infra/app/identity.bicep

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module userAssignedIdentity 'br/public:avm/res/managed-identity/user-assigned-id
1313
}
1414
}
1515

16-
output name string = userAssignedIdentity.outputs.name
1716
output resourceId string = userAssignedIdentity.outputs.resourceId
1817
output principalId string = userAssignedIdentity.outputs.principalId
1918
output clientId string = userAssignedIdentity.outputs.clientId

infra/app/registry.bicep

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ module registryUserAssignment 'br/public:avm/ptn/authorization/resource-role-ass
3232
}
3333
}
3434

35-
output name string = containerRegistry.outputs.name
3635
output endpoint string = containerRegistry.outputs.loginServer

infra/app/web.bicep

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ module containerAppsApp 'br/public:avm/res/app/container-app:0.9.0' = {
4545
tags: union(tags, { 'azd-service-name': serviceTag })
4646
ingressTargetPort: 8080
4747
ingressExternal: true
48-
ingressTransport: 'auto'
48+
ingressTransport: 'http'
49+
corsPolicy: {
50+
allowCredentials: true
51+
allowedOrigins: [
52+
'*'
53+
]
54+
}
4955
managedIdentities: {
5056
systemAssigned: false
5157
userAssignedResourceIds: [
@@ -69,8 +75,8 @@ module containerAppsApp 'br/public:avm/res/app/container-app:0.9.0' = {
6975
image: 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
7076
name: 'web-front-end'
7177
resources: {
72-
cpu: '0.25'
73-
memory: '0.5Gi'
78+
cpu: '1'
79+
memory: '2Gi'
7480
}
7581
env: [
7682
{
@@ -86,7 +92,3 @@ module containerAppsApp 'br/public:avm/res/app/container-app:0.9.0' = {
8692
]
8793
}
8894
}
89-
90-
output endpoint string = 'https://${containerAppsApp.outputs.fqdn}'
91-
output envName string = containerAppsApp.outputs.name
92-
output systemAssignedManagedIdentityPrincipalId string = containerAppsApp.outputs.systemAssignedMIPrincipalId

infra/main.bicep

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
targetScope = 'subscription'
1+
targetScope = 'resourceGroup'
22

33
@minLength(1)
44
@maxLength(64)
@@ -23,21 +23,14 @@ param containerAppsAppName string = ''
2323
param serviceName string = 'web'
2424

2525
var abbreviations = loadJsonContent('abbreviations.json')
26-
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
26+
var resourceToken = toLower(uniqueString(resourceGroup().id, environmentName, location))
2727
var tags = {
2828
'azd-env-name': environmentName
2929
repo: 'https://github.com/azure-samples/cosmos-db-nosql-dotnet-quickstart'
3030
}
3131

32-
resource resourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = {
33-
name: environmentName
34-
location: location
35-
tags: tags
36-
}
37-
3832
module identity 'app/identity.bicep' = {
3933
name: 'identity'
40-
scope: resourceGroup
4134
params: {
4235
identityName: '${abbreviations.userAssignedIdentity}-${resourceToken}'
4336
location: location
@@ -47,7 +40,6 @@ module identity 'app/identity.bicep' = {
4740

4841
module database 'app/database.bicep' = {
4942
name: 'database'
50-
scope: resourceGroup
5143
params: {
5244
accountName: !empty(cosmosDbAccountName) ? cosmosDbAccountName : '${abbreviations.cosmosDbAccount}-${resourceToken}'
5345
location: location
@@ -59,7 +51,6 @@ module database 'app/database.bicep' = {
5951

6052
module registry 'app/registry.bicep' = {
6153
name: 'registry'
62-
scope: resourceGroup
6354
params: {
6455
registryName: !empty(containerRegistryName) ? containerRegistryName : '${abbreviations.containerRegistry}${resourceToken}'
6556
location: location
@@ -69,7 +60,6 @@ module registry 'app/registry.bicep' = {
6960

7061
module web 'app/web.bicep' = {
7162
name: serviceName
72-
scope: resourceGroup
7363
params: {
7464
workspaceName: !empty(logWorkspaceName) ? logWorkspaceName : '${abbreviations.logAnalyticsWorkspace}-${resourceToken}'
7565
envName: !empty(containerAppsEnvName) ? containerAppsEnvName : '${abbreviations.containerAppsEnv}-${resourceToken}'
@@ -83,13 +73,5 @@ module web 'app/web.bicep' = {
8373
}
8474
}
8575

86-
// Database outputs
8776
output AZURE_COSMOS_DB_NOSQL_ENDPOINT string = database.outputs.endpoint
88-
89-
// Container outputs
9077
output AZURE_CONTAINER_REGISTRY_ENDPOINT string = registry.outputs.endpoint
91-
output AZURE_CONTAINER_REGISTRY_NAME string = registry.outputs.name
92-
93-
// Application outputs
94-
output AZURE_CONTAINER_APP_ENDPOINT string = web.outputs.endpoint
95-
output AZURE_CONTAINER_ENVIRONMENT_NAME string = web.outputs.envName

readme.md

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,48 @@ products:
1212

1313
# Quickstart: Azure Cosmos DB for NoSQL client library for .NET
1414

15-
This is a simple Blazor web application to illustrate common basic usage of Azure Cosmos DB for NoSQL's client library for .NET. This sample application accesses an existing account, database, and container using the [`Microsoft.Azure.Cosmos`](https://www.nuget.org/packages/Microsoft.Azure.Cosmos) and [`Azure.Identity`](https://www.nuget.org/packages/Azure.Identity) libraries from NuGet. Modify the source code and leverage the Infrastructure as Code (IaC) Bicep assets to get up and running quickly.
16-
17-
When you are finished, you will have a fully functional web application deployed to Azure.
18-
19-
![Screenshot of the deployed web application.](assets/web.png)
20-
21-
<sup>Screenshot of the deployed web application.</sup>
15+
This is a simple Blazor web application to illustrate common basic usage of Azure Cosmos DB for NoSQL's client library for .NET. This sample application accesses an existing account, database, and container using the [`Microsoft.Azure.Cosmos`](https://www.nuget.org/packages/Microsoft.Azure.Cosmos) and [`Azure.Identity`](https://www.nuget.org/packages/Azure.Identity) libraries from NuGet.
2216

2317
### Prerequisites
2418

25-
> This template will create infrastructure and deploy code to Azure. If you don't have an Azure Subscription, you can sign up for a [free account here](https://azure.microsoft.com/free/). Make sure you have the contributor role in the Azure subscription.
26-
27-
The following prerequisites are required to use this application. Please ensure that you have them all installed locally.
28-
19+
- [Docker](https://www.docker.com/)
2920
- [Azure Developer CLI](https://aka.ms/azd-install)
3021
- [.NET SDK 8.0](https://dotnet.microsoft.com/download/dotnet/8.0)
3122

3223
### Quickstart
3324

34-
To learn how to get started with any template, follow the steps in [this quickstart](https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-dotnet) with this template (`cosmos-db-nosql-dotnet-quickstart`).
35-
36-
This quickstart will show you how to authenticate on Azure, initialize using a template, provision infrastructure and deploy code on Azure via the following commands:
37-
38-
```bash
39-
# Log in to azd. Only required once per-install.
40-
azd auth login
41-
42-
# First-time project setup. Initialize a project in the current directory, using this template.
43-
# Omit the --template argument if you are running in a development container.
44-
azd init --template cosmos-db-nosql-dotnet-quickstart
45-
46-
# Provision and deploy to Azure
47-
azd up
48-
```
49-
50-
### Application Architecture
51-
52-
This application utilizes the following Azure resources:
25+
1. Log in to Azure Developer CLI.
5326

54-
- [**Azure Container Registry**](https://learn.microsoft.com/azure/container-registry/)
55-
- This services hosts the container image.
56-
- [**Azure Container Apps**](https://learn.microsoft.com/azure/container-apps/)
57-
- This service hosts the ASP.NET Blazor web application.
58-
- [**Azure Cosmos DB for NoSQL**](https://learn.microsoft.com/azure/cosmos-db/)
59-
- This service stores the NoSQL data.
27+
```bash
28+
azd auth login
29+
```
6030

61-
Here's a high level architecture diagram that illustrates these components. Notice that these are all contained within a single **resource group**, that will be created for you when you create the resources.
31+
> [!TIP]
32+
> This is only required once per-install.
6233

63-
```mermaid
64-
%%{ init: { 'theme': 'base', 'themeVariables': { 'background': '#243A5E', 'primaryColor': '#50E6FF', 'primaryBorderColor': '#243A5E', 'tertiaryBorderColor': '#50E6FF', 'tertiaryColor': '#243A5E', 'fontFamily': 'Segoe UI', 'lineColor': '#FFFFFF', 'primaryTextColor': '#243A5E', 'tertiaryTextColor': '#FFFFFF' } }}%%
65-
flowchart TB
66-
subgraph web-app[Azure Container Apps]
67-
app-framework([.NET 8 - Blazor])
68-
end
69-
subgraph cosmos-db[Azure Cosmos DB]
70-
subgraph database-cosmicworks[Database: cosmicworks]
71-
subgraph container-products[Container: products]
72-
prd-yamba[Product: Yamba Surfboard]
73-
prd-kiama-classic[Product: Kiama Classic Surfboard]
74-
end
75-
end
76-
end
77-
web-app --> cosmos-db
78-
```
34+
1. Initialize this template (`cosmos-db-nosql-dotnet-quickstart`) using `azd init`
7935

80-
### Cost of provisioning and deploying this template
36+
```bash
37+
azd init --template cosmos-db-nosql-dotnet-quickstart
38+
```
8139

82-
This template provisions resources to an Azure subscription that you will select upon provisioning them. Refer to the [Pricing calculator for Microsoft Azure](https://azure.microsoft.com/pricing/calculator/) to estimate the cost you might incur when this template is running on Azure and, if needed, update the included Azure resource definitions found in [`infra/main.bicep`](infra/main.bicep) to suit your needs.
40+
1. Ensure that **Docker** is running in your environment.
8341

84-
### Application Code
42+
1. Use `azd up` to provision your Azure infrastructure and deploy the web application to Azure.
8543

86-
This template is structured to follow the [Azure Developer CLI](https://aka.ms/azure-dev/overview). You can learn more about `azd` architecture in [the official documentation](https://learn.microsoft.com/azure/developer/azure-developer-cli/make-azd-compatible?pivots=azd-create#understand-the-azd-architecture).
44+
```bash
45+
azd up
46+
```
8747

88-
### Next Steps
48+
1. Observed the deployed web application
8949

90-
At this point, you have a complete application deployed on Azure. But there is much more that the Azure Developer CLI can do. These next steps will introduce you to additional commands that will make creating applications on Azure much easier. Using the Azure Developer CLI, you can setup your pipelines, monitor your application, test and debug locally.
50+
![Screenshot of the deployed web application.](assets/web.png)
9151

92-
- [`azd pipeline config`](https://learn.microsoft.com/azure/developer/azure-developer-cli/configure-devops-pipeline?tabs=GitHub) - to configure a CI/CD pipeline (using GitHub Actions or Azure DevOps) to deploy your application whenever code is pushed to the main branch.
52+
1. (Optionally) Run this web application locally in the `src/web` folder:
9353

94-
- [Run and Debug Locally](https://learn.microsoft.com/azure/developer/azure-developer-cli/debug?pivots=ide-vs-code) - using Visual Studio Code and the Azure Developer CLI extension
54+
```dotnetcli
55+
dotnet watch run
56+
```
9557

96-
- [`azd down`](https://learn.microsoft.com/azure/developer/azure-developer-cli/reference#azd-down) - to delete all the Azure resources created with this template
58+
> [!IMPORTANT]
59+
> When your Azure infrastructure is provisioned, the endpoint for your deployed Azure Cosmos DB for NoSQL account is automatically saved in the .NET user secrets store to make debugging easier. For more information, see [safe storage of app secrets in development](https://learn.microsoft.com/aspnet/core/security/app-secrets).

src/Cosmos.Samples.NoSQL.Quickstart.sln

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Samples.NoSQL.Quickstart.Web", "web\Cosmos.Samples.NoSQL.Quickstart.Web.csproj", "{F161D39F-F515-410A-9FE3-CA95A2659966}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Samples.NoSQL.Quickstart.Web", "web\Cosmos.Samples.NoSQL.Quickstart.Web.csproj", "{97D8FD8C-DE38-4CD8-A97B-8B1F1A72D22F}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -14,9 +14,9 @@ Global
1414
HideSolutionNode = FALSE
1515
EndGlobalSection
1616
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17-
{F161D39F-F515-410A-9FE3-CA95A2659966}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18-
{F161D39F-F515-410A-9FE3-CA95A2659966}.Debug|Any CPU.Build.0 = Debug|Any CPU
19-
{F161D39F-F515-410A-9FE3-CA95A2659966}.Release|Any CPU.ActiveCfg = Release|Any CPU
20-
{F161D39F-F515-410A-9FE3-CA95A2659966}.Release|Any CPU.Build.0 = Release|Any CPU
17+
{97D8FD8C-DE38-4CD8-A97B-8B1F1A72D22F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{97D8FD8C-DE38-4CD8-A97B-8B1F1A72D22F}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{97D8FD8C-DE38-4CD8-A97B-8B1F1A72D22F}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{97D8FD8C-DE38-4CD8-A97B-8B1F1A72D22F}.Release|Any CPU.Build.0 = Release|Any CPU
2121
EndGlobalSection
2222
EndGlobal
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<Nullable>enable</Nullable>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<UserSecretsId>65c85440-31fd-4394-ae83-614ffddbb71f</UserSecretsId>
77
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
88
</PropertyGroup>
99
<ItemGroup>
10-
<PackageReference Include="Azure.Identity" Version="1.*" />
11-
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.*" />
12-
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.*" />
10+
<PackageReference Include="Azure.Identity" Version="1.13.0" />
11+
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.44.1" />
12+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1313
</ItemGroup>
1414
</Project>

0 commit comments

Comments
 (0)