Skip to content

Commit 2fe7548

Browse files
committed
#63 updated bicep with redis, postgres and azure service bus
1 parent 9f44c0c commit 2fe7548

File tree

10 files changed

+231
-100
lines changed

10 files changed

+231
-100
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ src/web/shrinkwrap.yaml
355355
# git submodules
356356
**/*/healthchecksdb
357357

358+
docker-compose.*.local.yml
359+
tye.*.local.yaml
360+
components/az/
361+
358362
.tye/
359363
.logs/
360364

NET6.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# TODO
2-
1. update refresh token flow in webapi, hard code now
3-
2. error when do checkout, double-check for saleapp
4-
3. scale rule with http concurrency (10)
5-
4. Traffic spliting (modify web to add rating and split traffic 50/50)
2+
1. error when do checkout, double-check for saleapp (we might add Azure Service Bus for pubsub)
3+
2. scale rule with http concurrency (10)
4+
3. Traffic spliting (modify web to add rating and split traffic 50/50)
65

76
# APIs
87

@@ -81,16 +80,25 @@
8180
- POST: cron-complete-order
8281
- Request: CompleteOrderQuery (TODO: Command)
8382

83+
# Get starting
8484

85-
## ASP.NET Core Cert with docker-compose
85+
## docker-compose
86+
87+
- Because dev cert isn't working in docker-compose env, so we need to generate the cert just like https://github.com/thangchung/Sample-Docker-Https, and maps it into docker-compose volume
88+
89+
You need to copy the cert at `src/dotnet/certs/localhost.pfx` into `~/.aspnet/https` so that you can map the cert in local path into docker path when run `docker compose -f docker-compose.yml -f docker-compose.override.yml up -d`
90+
91+
See more about this issue at https://github.com/MicrosoftDocs/visualstudio-docs/issues/5733
92+
93+
## tye
8694

8795
```bash
8896
> dotnet dev-certs https -ep aspnetapp.pfx -p P@ssw0rd # then save it to %USERPROFILE%\.aspnet\https
8997
> dotnet dev-certs https --trust
90-
> docker compose up
98+
> tye run
9199
```
92100

93-
# Get starting
101+
## Azure Container Apps with Bicep
94102

95103
```powershell
96104
> $rgName="coolstore-rg"
@@ -104,14 +112,8 @@
104112
```powershell
105113
> az deployment group create `
106114
--resource-group $rgName `
107-
--template-file core.bicep `
108-
--parameters `
109-
inventoryPostgresHost='<inventory postgres db>' `
110-
productCategoryPostgresHost='<product catalog postgres db>' `
111-
postgresDbPassword='<postgres password>' `
112-
redisConnection='<full redis connection string>' `
113-
redisHost='<redis host>' `
114-
redisPassword='<redis password>'
115+
--template-file main.bicep `
116+
--parameters postgresDbPassword='<postgres password>'
115117
```
116118

117119
```powershell

deploys/bicep/main.bicep

Lines changed: 65 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
param location string = resourceGroup().location
2-
param environmentName string = 'env-${uniqueString(resourceGroup().id)}'
3-
param appInsightsName string = 'app-insights-${uniqueString(resourceGroup().id)}'
4-
param logAnalyticsWorkspaceName string = 'log-analytics-workspace-${uniqueString(resourceGroup().id)}'
2+
param uniqueSeed string = '${subscription().subscriptionId}-${resourceGroup().name}'
3+
param uniqueSuffix string = 'coolstore-${uniqueString(uniqueSeed)}'
4+
5+
param environmentName string = 'env-${uniqueSuffix}'
6+
param appInsightsName string = 'app-insights-${uniqueSuffix}'
7+
param logAnalyticsWorkspaceName string = 'log-analytics-workspace-${uniqueSuffix}'
8+
9+
param redisName string = 'redis-${uniqueSuffix}'
10+
param serviceBusNamespaceName string = 'sb-${uniqueSuffix}'
511

612
param minReplicas int = 0
713

@@ -37,15 +43,42 @@ param identityAppName string = 'identityapp'
3743
param identityAppImage string = 'ghcr.io/vietnam-devs/coolstore-microservices/identityapp-v6:0.1.0'
3844
param identityAppPort int = 80
3945

40-
param inventoryPostgresHost string
41-
param productCategoryPostgresHost string
42-
4346
@secure()
4447
param postgresDbPassword string
45-
//redis
46-
param redisConnection string
47-
param redisHost string
48-
param redisPassword string
48+
49+
module inventoryDb 'modules/postgres.bicep' = {
50+
name: '${deployment().name}--inventory-db'
51+
params: {
52+
location: location
53+
databaseName: 'inventory-db-${uniqueSuffix}'
54+
postgresDbPassword: postgresDbPassword
55+
}
56+
}
57+
58+
module productCatalogDb 'modules/postgres.bicep' = {
59+
name: '${deployment().name}--product-catalog-db'
60+
params: {
61+
location: location
62+
databaseName: 'product--catalogdb-${uniqueSuffix}'
63+
postgresDbPassword: postgresDbPassword
64+
}
65+
}
66+
67+
module serviceBusModule 'modules/servicebus.bicep' = {
68+
name: '${deployment().name}--servicebus'
69+
params: {
70+
serviceBusNamespaceName: serviceBusNamespaceName
71+
location: location
72+
}
73+
}
74+
75+
module redisModule 'modules/redis.bicep' = {
76+
name: '${deployment().name}--redis'
77+
params: {
78+
redisName: redisName
79+
location: location
80+
}
81+
}
4982

5083
// Container Apps Environment
5184
module environment 'modules/environment.bicep' = {
@@ -58,76 +91,30 @@ module environment 'modules/environment.bicep' = {
5891
}
5992
}
6093

61-
// Dapr statestore component
62-
resource stateDaprComponent 'Microsoft.App/managedEnvironments/daprComponents@2022-01-01-preview' = {
63-
name: '${environmentName}/statestore'
94+
module daprStateStore 'modules/dapr/statestore.bicep' = {
95+
name: '${deployment().name}--dapr-statestore'
6496
dependsOn: [
65-
identityApp
66-
webApiGatewayApp
6797
environment
68-
inventoryApp
69-
productCatalogApp
70-
shoppingCartApp
71-
saleApp
98+
redisModule
7299
]
73-
properties: {
74-
componentType: 'state.redis'
75-
version: 'v1'
76-
secrets: [
77-
{
78-
name: 'redis-password'
79-
value: redisPassword
80-
}
81-
]
82-
metadata: [
83-
{
84-
name: 'redisHost'
85-
value: redisHost
86-
}
87-
{
88-
name: 'redisPassword'
89-
secretRef: 'redis-password'
90-
}
91-
{
92-
name: 'actorStateStore'
93-
value: 'false'
94-
}
95-
]
96-
scopes: [
97-
identityAppName
98-
webApiGatewayAppName
99-
inventoryAppName
100-
productCatalogAppName
101-
shoppingCartAppName
102-
saleAppName
103-
]
100+
params: {
101+
environmentName: environmentName
102+
redisName: redisName
103+
shoppingCartAppName: shoppingCartAppName
104104
}
105105
}
106106

107-
// Dapr pubsub component
108-
resource pubsubDaprComponent 'Microsoft.App/managedEnvironments/daprComponents@2022-01-01-preview' = {
109-
name: '${environmentName}/pubsub'
107+
module daprPubsub 'modules/dapr/pubsub.bicep' = {
108+
name: '${deployment().name}--dapr-pubsub'
110109
dependsOn: [
111110
environment
112-
identityApp
113-
webApiGatewayApp
114-
environment
115-
inventoryApp
116-
productCatalogApp
117-
shoppingCartApp
118-
saleApp
111+
serviceBusModule
119112
]
120-
properties: {
121-
componentType: 'pubsub.in-memory'
122-
version: 'v1'
123-
scopes: [
124-
identityAppName
125-
webApiGatewayAppName
126-
inventoryAppName
127-
productCatalogAppName
128-
shoppingCartAppName
129-
saleAppName
130-
]
113+
params: {
114+
environmentName: environmentName
115+
serviceBusNamespaceName: serviceBusNamespaceName
116+
saleAppName: saleAppName
117+
shoppingCartAppName: shoppingCartAppName
131118
}
132119
}
133120

@@ -136,6 +123,7 @@ module inventoryApp 'modules/container-http.bicep' = {
136123
name: '${deployment().name}--${inventoryAppName}'
137124
dependsOn: [
138125
environment
126+
inventoryDb
139127
]
140128
params: {
141129
enableIngress: true
@@ -157,15 +145,15 @@ module inventoryApp 'modules/container-http.bicep' = {
157145
}
158146
{
159147
name: 'PG_HOST'
160-
value: inventoryPostgresHost
148+
value: inventoryDb.outputs.postgresDbHost
161149
}
162150
{
163151
name: 'PG_PORT'
164152
value: '5432'
165153
}
166154
{
167155
name: 'PG_USER'
168-
value: 'coolstore'
156+
value: inventoryDb.outputs.postgresDbUserName
169157
}
170158
{
171159
name: 'PG_PASSWORD'
@@ -193,6 +181,7 @@ module productCatalogApp 'modules/container-http.bicep' = {
193181
name: '${deployment().name}--${productCatalogAppName}'
194182
dependsOn: [
195183
environment
184+
productCatalogDb
196185
inventoryApp
197186
]
198187
params: {
@@ -215,15 +204,15 @@ module productCatalogApp 'modules/container-http.bicep' = {
215204
}
216205
{
217206
name: 'PG_HOST'
218-
value: productCategoryPostgresHost
207+
value: productCatalogDb.outputs.postgresDbHost
219208
}
220209
{
221210
name: 'PG_PORT'
222211
value: '5432'
223212
}
224213
{
225214
name: 'PG_USER'
226-
value: 'coolstore'
215+
value: productCatalogDb.outputs.postgresDbUserName
227216
}
228217
{
229218
name: 'PG_PASSWORD'
@@ -300,11 +289,6 @@ module saleApp 'modules/container-http.bicep' = {
300289
}
301290

302291
// WebApiGateway App
303-
// TODO: we need to modify this gateway to add configurations for identityapp and webapp as below
304-
// az containerapp update `
305-
// --name webapigatewayapp `
306-
// --resource-group $rgName `
307-
// --set-env-vars 'OpenIdConnect__Authority=https://<identityapp output>' 'ReverseProxy__Clusters__appCluster__Destinations__destination1__Address=<webapp output>'
308292
module webApiGatewayApp 'modules/container-http.bicep' = {
309293
name: '${deployment().name}--${webApiGatewayAppName}'
310294
dependsOn: [
@@ -326,7 +310,7 @@ module webApiGatewayApp 'modules/container-http.bicep' = {
326310
env: [
327311
{
328312
name: 'Redis'
329-
value: redisConnection
313+
value: redisModule.outputs.redisHost
330314
}
331315
{
332316
name: 'ASPNETCORE_ENVIRONMENT'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
param environmentName string
2+
param serviceBusNamespaceName string
3+
4+
param shoppingCartAppName string
5+
param saleAppName string
6+
7+
resource serviceBus 'Microsoft.ServiceBus/namespaces@2021-06-01-preview' existing = {
8+
name: serviceBusNamespaceName
9+
}
10+
11+
// Dapr pubsub component
12+
resource pubsubDaprComponent 'Microsoft.App/managedEnvironments/daprComponents@2022-01-01-preview' = {
13+
name: '${environmentName}/pubsub'
14+
properties: {
15+
componentType: 'pubsub.azure.servicebus'
16+
version: 'v1'
17+
metadata: [
18+
{
19+
name: 'connectionString'
20+
secretRef: 'sb-root-connectionstring'
21+
}
22+
]
23+
secrets: [
24+
{
25+
name: 'sb-root-connectionstring'
26+
value: listKeys('${serviceBus.id}/AuthorizationRules/RootManageSharedAccessKey', serviceBus.apiVersion).primaryConnectionString
27+
}
28+
]
29+
scopes: [
30+
shoppingCartAppName
31+
saleAppName
32+
]
33+
}
34+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
param environmentName string
2+
param redisName string
3+
4+
param shoppingCartAppName string
5+
6+
resource redis 'Microsoft.Cache/redis@2020-12-01' existing = {
7+
name: redisName
8+
}
9+
10+
// Dapr statestore component
11+
resource stateDaprComponent 'Microsoft.App/managedEnvironments/daprComponents@2022-01-01-preview' = {
12+
name: '${environmentName}/statestore'
13+
properties: {
14+
componentType: 'state.redis'
15+
version: 'v1'
16+
secrets: [
17+
{
18+
name: 'redis-password'
19+
value: listKeys(redis.id, redis.apiVersion).primaryKey
20+
}
21+
]
22+
metadata: [
23+
{
24+
name: 'redisHost'
25+
value: '${redis.properties.hostName}:${redis.properties.port}'
26+
}
27+
{
28+
name: 'redisPassword'
29+
secretRef: 'redis-password'
30+
}
31+
{
32+
name: 'actorStateStore'
33+
value: 'false'
34+
}
35+
]
36+
scopes: [
37+
shoppingCartAppName
38+
]
39+
}
40+
}

0 commit comments

Comments
 (0)