Skip to content

Commit b301699

Browse files
committed
chore: add initial azd/bicep infra code
1 parent 0f253d4 commit b301699

18 files changed

+2134
-27
lines changed

.env

+4-26
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
1-
# The Llama Cloud API key.
2-
# LLAMA_CLOUD_API_KEY=
3-
4-
# The provider for the AI models to use.
5-
MODEL_PROVIDER=ollama
6-
7-
# The name of LLM model to use.
8-
MODEL=phi3:mini
9-
10-
# Name of the embedding model to use.
11-
EMBEDDING_MODEL=nomic-embed-text
12-
13-
# Dimension of the embedding model to use.
1+
MODEL_PROVIDER=openai
2+
MODEL=gpt-35-turbo
3+
EMBEDDING_MODEL=text-embedding-3-large
144
EMBEDDING_DIM=1024
15-
16-
# The OpenAI API key to use.
17-
# OPENAI_API_KEY=
18-
19-
# Temperature for sampling from the model.
5+
OPENAI_API_KEY="sk-..."
206
# LLM_TEMPERATURE=
21-
22-
# Maximum number of tokens to generate.
237
# LLM_MAX_TOKENS=
24-
25-
# The number of similar embeddings to return when retrieving documents.
268
TOP_K=3
27-
28-
# FILESERVER_URL_PREFIX is the URL prefix of the server storing the images generated by the interpreter.
299
FILESERVER_URL_PREFIX=http://localhost:3000/api/files
30-
31-
# The system prompt for the AI model.
3210
SYSTEM_PROMPT=You are a helpful assistant who helps users with their questions.
3311

.env.example

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# The Llama Cloud API key.
2+
# LLAMA_CLOUD_API_KEY=
3+
4+
# The provider for the AI models to use.
5+
MODEL_PROVIDER=ollama
6+
7+
# The name of LLM model to use.
8+
MODEL=phi3:mini
9+
10+
# Name of the embedding model to use.
11+
EMBEDDING_MODEL=nomic-embed-text
12+
13+
# Dimension of the embedding model to use.
14+
EMBEDDING_DIM=1024
15+
16+
# The OpenAI API key to use.
17+
# OPENAI_API_KEY=
18+
19+
# Temperature for sampling from the model.
20+
# LLM_TEMPERATURE=
21+
22+
# Maximum number of tokens to generate.
23+
# LLM_MAX_TOKENS=
24+
25+
# The number of similar embeddings to return when retrieving documents.
26+
TOP_K=3
27+
28+
# FILESERVER_URL_PREFIX is the URL prefix of the server storing the images generated by the interpreter.
29+
FILESERVER_URL_PREFIX=http://localhost:3000/api/files
30+
31+
# The system prompt for the AI model.
32+
SYSTEM_PROMPT=You are a helpful assistant who helps users with their questions.
33+

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ yarn-error.log*
3434
*.tsbuildinfo
3535
next-env.d.ts
3636

37-
tool-output/
37+
tool-output/
38+
.azure

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ RUN npm install
99
# Build the application
1010
COPY . .
1111
RUN npm run build
12+
RUN npm run generate
1213

1314
# ====================================
1415
FROM build as release

azure.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
2+
3+
name: llama-index-nextjs
4+
metadata:
5+
6+
services:
7+
llama-index-nextjs:
8+
project: .
9+
host: containerapp
10+
language: js
11+
docker:
12+
path: Dockerfile

infra/abbreviations.json

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"analysisServicesServers": "as",
3+
"apiManagementService": "apim-",
4+
"appConfigurationStores": "appcs-",
5+
"appManagedEnvironments": "cae-",
6+
"appContainerApps": "ca-",
7+
"authorizationPolicyDefinitions": "policy-",
8+
"automationAutomationAccounts": "aa-",
9+
"blueprintBlueprints": "bp-",
10+
"blueprintBlueprintsArtifacts": "bpa-",
11+
"cacheRedis": "redis-",
12+
"cdnProfiles": "cdnp-",
13+
"cdnProfilesEndpoints": "cdne-",
14+
"cognitiveServicesAccounts": "cog-",
15+
"cognitiveServicesFormRecognizer": "cog-fr-",
16+
"cognitiveServicesTextAnalytics": "cog-ta-",
17+
"computeAvailabilitySets": "avail-",
18+
"computeCloudServices": "cld-",
19+
"computeDiskEncryptionSets": "des",
20+
"computeDisks": "disk",
21+
"computeDisksOs": "osdisk",
22+
"computeGalleries": "gal",
23+
"computeSnapshots": "snap-",
24+
"computeVirtualMachines": "vm",
25+
"computeVirtualMachineScaleSets": "vmss-",
26+
"containerInstanceContainerGroups": "ci",
27+
"containerRegistryRegistries": "cr",
28+
"containerServiceManagedClusters": "aks-",
29+
"databricksWorkspaces": "dbw-",
30+
"dataFactoryFactories": "adf-",
31+
"dataLakeAnalyticsAccounts": "dla",
32+
"dataLakeStoreAccounts": "dls",
33+
"dataMigrationServices": "dms-",
34+
"dBforMySQLServers": "mysql-",
35+
"dBforPostgreSQLServers": "psql-",
36+
"devicesIotHubs": "iot-",
37+
"devicesProvisioningServices": "provs-",
38+
"devicesProvisioningServicesCertificates": "pcert-",
39+
"documentDBDatabaseAccounts": "cosmos-",
40+
"eventGridDomains": "evgd-",
41+
"eventGridDomainsTopics": "evgt-",
42+
"eventGridEventSubscriptions": "evgs-",
43+
"eventHubNamespaces": "evhns-",
44+
"eventHubNamespacesEventHubs": "evh-",
45+
"hdInsightClustersHadoop": "hadoop-",
46+
"hdInsightClustersHbase": "hbase-",
47+
"hdInsightClustersKafka": "kafka-",
48+
"hdInsightClustersMl": "mls-",
49+
"hdInsightClustersSpark": "spark-",
50+
"hdInsightClustersStorm": "storm-",
51+
"hybridComputeMachines": "arcs-",
52+
"insightsActionGroups": "ag-",
53+
"insightsComponents": "appi-",
54+
"keyVaultVaults": "kv-",
55+
"kubernetesConnectedClusters": "arck",
56+
"kustoClusters": "dec",
57+
"kustoClustersDatabases": "dedb",
58+
"logicIntegrationAccounts": "ia-",
59+
"logicWorkflows": "logic-",
60+
"machineLearningServicesWorkspaces": "mlw-",
61+
"managedIdentityUserAssignedIdentities": "id-",
62+
"managementManagementGroups": "mg-",
63+
"migrateAssessmentProjects": "migr-",
64+
"networkApplicationGateways": "agw-",
65+
"networkApplicationSecurityGroups": "asg-",
66+
"networkAzureFirewalls": "afw-",
67+
"networkBastionHosts": "bas-",
68+
"networkConnections": "con-",
69+
"networkDnsZones": "dnsz-",
70+
"networkExpressRouteCircuits": "erc-",
71+
"networkFirewallPolicies": "afwp-",
72+
"networkFirewallPoliciesWebApplication": "waf",
73+
"networkFirewallPoliciesRuleGroups": "wafrg",
74+
"networkFrontDoors": "fd-",
75+
"networkFrontdoorWebApplicationFirewallPolicies": "fdfp-",
76+
"networkLoadBalancersExternal": "lbe-",
77+
"networkLoadBalancersInternal": "lbi-",
78+
"networkLoadBalancersInboundNatRules": "rule-",
79+
"networkLocalNetworkGateways": "lgw-",
80+
"networkNatGateways": "ng-",
81+
"networkNetworkInterfaces": "nic-",
82+
"networkNetworkSecurityGroups": "nsg-",
83+
"networkNetworkSecurityGroupsSecurityRules": "nsgsr-",
84+
"networkNetworkWatchers": "nw-",
85+
"networkPrivateDnsZones": "pdnsz-",
86+
"networkPrivateLinkServices": "pl-",
87+
"networkPublicIPAddresses": "pip-",
88+
"networkPublicIPPrefixes": "ippre-",
89+
"networkRouteFilters": "rf-",
90+
"networkRouteTables": "rt-",
91+
"networkRouteTablesRoutes": "udr-",
92+
"networkTrafficManagerProfiles": "traf-",
93+
"networkVirtualNetworkGateways": "vgw-",
94+
"networkVirtualNetworks": "vnet-",
95+
"networkVirtualNetworksSubnets": "snet-",
96+
"networkVirtualNetworksVirtualNetworkPeerings": "peer-",
97+
"networkVirtualWans": "vwan-",
98+
"networkVpnGateways": "vpng-",
99+
"networkVpnGatewaysVpnConnections": "vcn-",
100+
"networkVpnGatewaysVpnSites": "vst-",
101+
"notificationHubsNamespaces": "ntfns-",
102+
"notificationHubsNamespacesNotificationHubs": "ntf-",
103+
"operationalInsightsWorkspaces": "log-",
104+
"portalDashboards": "dash-",
105+
"powerBIDedicatedCapacities": "pbi-",
106+
"purviewAccounts": "pview-",
107+
"recoveryServicesVaults": "rsv-",
108+
"resourcesResourceGroups": "rg-",
109+
"searchSearchServices": "srch-",
110+
"serviceBusNamespaces": "sb-",
111+
"serviceBusNamespacesQueues": "sbq-",
112+
"serviceBusNamespacesTopics": "sbt-",
113+
"serviceEndPointPolicies": "se-",
114+
"serviceFabricClusters": "sf-",
115+
"signalRServiceSignalR": "sigr",
116+
"sqlManagedInstances": "sqlmi-",
117+
"sqlServers": "sql-",
118+
"sqlServersDataWarehouse": "sqldw-",
119+
"sqlServersDatabases": "sqldb-",
120+
"sqlServersDatabasesStretch": "sqlstrdb-",
121+
"storageStorageAccounts": "st",
122+
"storageStorageAccountsVm": "stvm",
123+
"storSimpleManagers": "ssimp",
124+
"streamAnalyticsCluster": "asa-",
125+
"synapseWorkspaces": "syn",
126+
"synapseWorkspacesAnalyticsWorkspaces": "synw",
127+
"synapseWorkspacesSqlPoolsDedicated": "syndp",
128+
"synapseWorkspacesSqlPoolsSpark": "synsp",
129+
"timeSeriesInsightsEnvironments": "tsi-",
130+
"webServerFarms": "plan-",
131+
"webSitesAppService": "app-",
132+
"webSitesAppServiceEnvironment": "ase-",
133+
"webSitesFunctions": "func-",
134+
"webStaticSites": "stapp-"
135+
}

infra/app/llama-index-nextjs.bicep

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
param name string
2+
param location string = resourceGroup().location
3+
param tags object = {}
4+
5+
param identityName string
6+
param containerRegistryName string
7+
param containerAppsEnvironmentName string
8+
param applicationInsightsName string
9+
param exists bool
10+
@secure()
11+
param appDefinition object
12+
13+
var appSettingsArray = filter(array(appDefinition.settings), i => i.name != '')
14+
var secrets = map(filter(appSettingsArray, i => i.?secret != null), i => {
15+
name: i.name
16+
value: i.value
17+
secretRef: i.?secretRef ?? take(replace(replace(toLower(i.name), '_', '-'), '.', '-'), 32)
18+
})
19+
var env = map(filter(appSettingsArray, i => i.?secret == null), i => {
20+
name: i.name
21+
value: i.value
22+
})
23+
24+
resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
25+
name: identityName
26+
location: location
27+
}
28+
29+
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-01-01-preview' existing = {
30+
name: containerRegistryName
31+
}
32+
33+
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = {
34+
name: containerAppsEnvironmentName
35+
}
36+
37+
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = {
38+
name: applicationInsightsName
39+
}
40+
41+
resource acrPullRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
42+
scope: containerRegistry
43+
name: guid(subscription().id, resourceGroup().id, identity.id, 'acrPullRole')
44+
properties: {
45+
roleDefinitionId: subscriptionResourceId(
46+
'Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d')
47+
principalType: 'ServicePrincipal'
48+
principalId: identity.properties.principalId
49+
}
50+
}
51+
52+
module fetchLatestImage '../modules/fetch-container-image.bicep' = {
53+
name: '${name}-fetch-image'
54+
params: {
55+
exists: exists
56+
name: name
57+
}
58+
}
59+
60+
resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
61+
name: name
62+
location: location
63+
tags: union(tags, {'azd-service-name': 'llama-index-nextjs' })
64+
dependsOn: [ acrPullRole ]
65+
identity: {
66+
type: 'UserAssigned'
67+
userAssignedIdentities: { '${identity.id}': {} }
68+
}
69+
properties: {
70+
managedEnvironmentId: containerAppsEnvironment.id
71+
configuration: {
72+
ingress: {
73+
external: true
74+
targetPort: 3000
75+
transport: 'auto'
76+
}
77+
registries: [
78+
{
79+
server: '${containerRegistryName}.azurecr.io'
80+
identity: identity.id
81+
}
82+
]
83+
secrets: union([
84+
],
85+
map(secrets, secret => {
86+
name: secret.secretRef
87+
value: secret.value
88+
}))
89+
}
90+
template: {
91+
containers: [
92+
{
93+
image: fetchLatestImage.outputs.?containers[?0].?image ?? 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
94+
name: 'main'
95+
env: union([
96+
{
97+
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
98+
value: applicationInsights.properties.ConnectionString
99+
}
100+
{
101+
name: 'PORT'
102+
value: '3000'
103+
}
104+
],
105+
env,
106+
map(secrets, secret => {
107+
name: secret.name
108+
secretRef: secret.secretRef
109+
}))
110+
resources: {
111+
cpu: json('1.0')
112+
memory: '2.0Gi'
113+
}
114+
}
115+
]
116+
scale: {
117+
minReplicas: 1
118+
maxReplicas: 10
119+
}
120+
}
121+
}
122+
}
123+
124+
output defaultDomain string = containerAppsEnvironment.properties.defaultDomain
125+
output name string = app.name
126+
output uri string = 'https://${app.properties.configuration.ingress.fqdn}'
127+
output id string = app.id

0 commit comments

Comments
 (0)