Skip to content

Commit 3ed6a8a

Browse files
committed
create cosmosdb containers at deployment time in bicep instead of the graphrag webapp
1 parent b656061 commit 3ed6a8a

File tree

6 files changed

+249
-120
lines changed

6 files changed

+249
-120
lines changed

backend/graphrag_app/main.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from pathlib import Path
88

99
import yaml
10-
from azure.cosmos import PartitionKey, ThroughputProperties
10+
11+
# from azure.cosmos import PartitionKey, ThroughputProperties
1112
from fastapi import (
1213
FastAPI,
1314
Request,
@@ -28,7 +29,8 @@
2829
from graphrag_app.api.query import query_route
2930
from graphrag_app.api.source import source_route
3031
from graphrag_app.logger.load_logger import load_pipeline_logger
31-
from graphrag_app.utils.azure_clients import AzureClientManager
32+
33+
# from graphrag_app.utils.azure_clients import AzureClientManager
3234

3335

3436
async def catch_all_exceptions_middleware(request: Request, call_next):
@@ -46,19 +48,19 @@ async def catch_all_exceptions_middleware(request: Request, call_next):
4648
return Response("Unexpected internal server error.", status_code=500)
4749

4850

49-
def intialize_cosmosdb_setup():
50-
"""Initialise database setup (if necessary) and configure CosmosDB containers that are expected at startup time if they do not exist."""
51-
azure_client_manager = AzureClientManager()
52-
client = azure_client_manager.get_cosmos_client()
53-
db_client = client.create_database_if_not_exists("graphrag")
54-
# create containers with default settings
55-
db_client.create_container_if_not_exists(
56-
id="jobs", partition_key=PartitionKey(path="/id")
57-
)
58-
db_client.create_container_if_not_exists(
59-
id="container-store",
60-
partition_key=PartitionKey(path="/id"),
61-
)
51+
# def intialize_cosmosdb_setup():
52+
# """Initialise database setup (if necessary) and configure CosmosDB containers that are expected at startup time if they do not exist."""
53+
# azure_client_manager = AzureClientManager()
54+
# client = azure_client_manager.get_cosmos_client()
55+
# db_client = client.create_database_if_not_exists("graphrag")
56+
# # create containers with default settings
57+
# db_client.create_container_if_not_exists(
58+
# id="jobs", partition_key=PartitionKey(path="/id")
59+
# )
60+
# db_client.create_container_if_not_exists(
61+
# id="container-store",
62+
# partition_key=PartitionKey(path="/id"),
63+
# )
6264

6365

6466
@asynccontextmanager
@@ -74,8 +76,8 @@ async def lifespan(app: FastAPI):
7476
yield
7577
return
7678

77-
# Initialize CosmosDB setup
78-
intialize_cosmosdb_setup()
79+
# TODO: must identify proper CosmosDB RBAC roles before databases and containers can be created by this web app
80+
# intialize_cosmosdb_setup()
7981

8082
try:
8183
# Check if the cronjob exists and create it if it does not exist

infra/core/apim/apim.bicep

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
@description('The name of the API Management service instance')
5-
param apiManagementName string = 'apiservice${uniqueString(resourceGroup().id)}'
5+
param apiManagementName string
66

77
@description('The email address of the owner of the service')
88
@minLength(1)

infra/core/cosmosdb/cosmosdb.bicep

+78-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ resource cosmosDb 'Microsoft.DocumentDB/databaseAccounts@2024-11-15' = {
7272
}
7373

7474
// create a single database that is used to maintain state information for graphrag indexing
75-
// NOTE: The current CosmosDB role assignments are not sufficient to allow the aks workload identity to create databases so we must do it in bicep at deployment time.
76-
// TODO: Identify and assign appropriate RBAC roles that allow the workload identity to create new databases instead of relying on this bicep implementation.
75+
// NOTE: The current CosmosDB role assignments are not sufficient to allow the aks workload identity to create databases and containers so we must do it in bicep at deployment time.
76+
// TODO: Identify and assign appropriate RBAC roles that allow the workload identity to create new databases and containers instead of relying on this bicep implementation.
7777
resource graphragDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2024-11-15' = {
7878
parent: cosmosDb
7979
name: 'graphrag'
@@ -89,6 +89,82 @@ resource graphragDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@20
8989
}
9090
}
9191

92+
resource jobsContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2024-11-15' = {
93+
parent: graphragDatabase
94+
name: 'jobs'
95+
properties: {
96+
resource: {
97+
id: 'jobs'
98+
indexingPolicy: {
99+
indexingMode: 'consistent'
100+
automatic: true
101+
includedPaths: [
102+
{
103+
path: '/*'
104+
}
105+
]
106+
excludedPaths: [
107+
{
108+
path: '/"_etag"/?'
109+
}
110+
]
111+
}
112+
partitionKey: {
113+
paths: [
114+
'/id'
115+
]
116+
kind: 'Hash'
117+
version: 2
118+
}
119+
uniqueKeyPolicy: {
120+
uniqueKeys: []
121+
}
122+
conflictResolutionPolicy: {
123+
mode: 'LastWriterWins'
124+
conflictResolutionPath: '/_ts'
125+
}
126+
}
127+
}
128+
}
129+
130+
resource containerStoreContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2024-11-15' = {
131+
parent: graphragDatabase
132+
name: 'container-store'
133+
properties: {
134+
resource: {
135+
id: 'container-store'
136+
indexingPolicy: {
137+
indexingMode: 'consistent'
138+
automatic: true
139+
includedPaths: [
140+
{
141+
path: '/*'
142+
}
143+
]
144+
excludedPaths: [
145+
{
146+
path: '/"_etag"/?'
147+
}
148+
]
149+
}
150+
partitionKey: {
151+
paths: [
152+
'/id'
153+
]
154+
kind: 'Hash'
155+
version: 2
156+
}
157+
uniqueKeyPolicy: {
158+
uniqueKeys: []
159+
}
160+
conflictResolutionPolicy: {
161+
mode: 'LastWriterWins'
162+
conflictResolutionPath: '/_ts'
163+
}
164+
}
165+
}
166+
}
167+
92168
output name string = cosmosDb.name
93169
output id string = cosmosDb.id
94170
output endpoint string = cosmosDb.properties.documentEndpoint

infra/core/monitor/app-insights.bicep

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
2525
}
2626
}
2727

28+
output name string = appInsights.name
2829
output id string = appInsights.id
2930
output connectionString string = appInsights.properties.ConnectionString
3031
output instrumentationKey string = appInsights.properties.InstrumentationKey

0 commit comments

Comments
 (0)