Skip to content

Commit

Permalink
Fixed warnings in bicep. Added testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkp committed Mar 29, 2024
1 parent aad9e5c commit 1e41842
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 39 deletions.
5 changes: 2 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
"ms-azuretools.azure-dev",
"ms-azuretools.vscode-azurefunctions",
"ms-azuretools.vscode-bicep",
"ms-azuretools.vscode-docker"
// Include other VSCode language extensions if needed
// Right click on an extension inside VSCode to add directly to devcontainer.json, or copy the extension ID
"ms-azuretools.vscode-docker",
"humao.rest-client"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jobs:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
scope: subscription
region: northeurope
template: ./infrastructure/main-with-storage.bicep
template: ./infrastructure/main.bicep
parameters: infrastructure/params.json
failOnStdErr: false
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Azure Container Apps - Infrastructure Template
# Azure Container Apps - Semantic Search Backend

Use this template to create an Azure Container App repository that configures an Azure environment ready for use for hosting docker containers. It uses the subscription deploy scope, so you need a service principal with access to the subscription where you want to deploy the resource group.
Use this template to create an Azure Container App Semantic Search backend using [qdrant](https://qdrant.tech) as vector database and https://github.com/sjkp/blitz-embed/tree/master as embedding endpoint.

Besides Azure Container Apps, it deploys a storage account and an Azure Key Vault, and log analytics workspace.
Besides Azure Container Apps, the template deploys a storage account and log analytics workspace.

Things you want to modify
| Location | Usage |
| - | - |
|.github/workflows/deploy.yaml| For the github action to work you must set the following Github action secrets: `AZURE_CREDENTIALS` (see below how to create a value, it is the full json response of the `az ad sp` command that you should use) `AZURE_SUBSCRIPTION` (this should contain the subscription Id). *If you need an Azure Container App that uses an Azure file share mount you can use the template `main-with-storage.bicep` instead of just main in `deploy.yaml`*
|.github/workflows/deploy.yaml| For the github action to work you must set the following Github action secrets: `AZURE_CREDENTIALS` (see below how to create a value, it is the full json response of the `az ad sp` command that you should use) `AZURE_SUBSCRIPTION` (this should contain the subscription Id).
| infrastructure/params.json | You can change the `location` of the resource group (all resource are deployed to same location) and the `appName` in here, `appName` is used to generate the name of all the resources and the resource group. You can also change which `containerImage` that you want deployed, it defaults to nginx |


Expand All @@ -27,3 +27,7 @@ When generating your credentials (in this example we store in a secret named AZU
az ad sp create-for-rbac --name "{sp-name}" --sdk-auth --role contributor --scopes /subscriptions/{subscription-id}
```
Note: the `sp-name` must be a subdomain of your tenant name, e.g. `ghaction.<your-tenant>.onmicrosoft.com`


## Testing
You can use the included `test.http` file to test the endpoints. Replace the apiKey and baseUri and baseUriEmbedding with your endpoints. The API key can be found in the environment variables section of the embedding container app, as it is generated dynamically during the deployment.
6 changes: 6 additions & 0 deletions embedding.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"vector": [0.0346868, 0.0277891, 0.0523196, 0.0365636, 0.0165901, 0.00892579, 0.0428915, -0.0275851, -0.00856243, -0.0745539, 0.00102096, 0.00526032, -0.0536172, 0.0463208, -0.00971167, 0.0378302, 0.0500082, 0.0668809, -0.00842292, 0.00638258, 0.004725, -0.0345607, 0.0422167, -0.00283607, 0.00472428, 0.00201819, 0.00804061, 0.0150512, -0.0455343, -0.0287145, 0.0378039, -0.00163606, -0.0185293, -0.0304859, 0.00222441, -0.00122602, -0.0103595, -0.0411364, -0.00135946, -0.0451634, -0.0331605, -0.0159062, -0.0462774, -0.0156906, -0.0208196, 0.00266117, -0.0722372, 0.0355447, -0.0476742, 0.012688, -0.0815554, 0.0382993, -0.0123248, 0.0306779, -0.021632, 0.028071, 0.00158277, -0.0443838, -0.00386494, -0.0551219, 0.0307124, -0.0243249, 0.0202872, 0.0204015, 0.0158352, -0.0125067, -0.0137742, 0.0700892, -0.0380367, -0.0304638, -0.0127976, 0.0221229, 0.0270013, -0.0247291, -0.0257979, -0.0662881, 0.0386992, -0.00720711, 0.0858116, 0.0365669, 0.0235888, -0.0265835, 0.0288966, 0.0601788, 0.0086496, -0.0285926, -0.0300374, 0.00533039, -0.0313214, 0.0713253, -0.0238349, -0.0239278, 0.0714322, 0.0470536, 0.0176318, 0.0225061, 0.0309548, -0.0149036, 0.0118781, 0.0225147, -0.0352669, -0.0376559, -0.00274173, -0.0490154, -0.0829928, 0.00875333, -0.041397, -0.0215225, 0.0134125, 0.0204625, -0.0524414, -0.0225063, 0.00194512, -2.66702e-05, -0.0470722, 0.0699277, 0.0506378, 0.0194991, 0.0184928, 0.0124586, 0.0303314, 0.0448185, 0.00877822, 0.0775953, -0.006422, 0.0376561, -0.00128171, 0.00217674, -0.00702975, -0.0315714, 0.0173388, 0.0658624, 0.0215342, 0.0231006, -0.0253743, 0.00213488, 0.073707, 0.0111904, 0.00206328, -0.0429465, 0.00954349, -0.0155306, 0.0233171, -0.0221303, 0.091166, -0.00561042, -0.00663477, -0.0228176, -0.0521299, -0.00212917, -0.0259577, 0.0126401, 0.00467974, -0.00596297, 0.0516432, 0.0374084, 0.0452985, 0.00797131, -0.0287185, 0.00580122, 0.0135949, 0.0233572, -0.00316838, 0.02258, -0.0583015, 0.0188294, 0.0101831, 0.0389987, -0.0105307, 0.0199816, -0.0277429, -0.0369549, 0.0260031, 0.0293257, 0.00501238, 0.0443473, 0.0980375, 0.0189102, 0.0260807, 0.00214711, -0.106891, 0.0361877, 0.0415604, 0.0175746, -0.0361755, -0.0123861, 0.0770368, -0.0242276, 0.0175426, 0.0132505, -0.0575334, -0.060045, -0.00992377, -0.0102315, 0.0603574, -0.0116044, 0.0376777, 0.00857699, 0.0128506, 0.0567737, 0.0585033, 0.0224022, 0.0559764, -0.00487178, -0.0343094, -0.012206, -0.00536796, -0.0398729, -0.0448373, 0.00411681, 0.0112714, -0.0114835, 0.0253541, 0.0265669, 0.0545706, 0.0376912, 0.0129275, -7.1511e-05, -0.000112377, -0.029215, 0.0850035, -0.025249, -0.0316489, 0.0251293, -0.00578575, 0.0867689, 0.0854708, -0.0702491, -0.0219309, -0.0474761, -0.0423888, -0.0127976, 0.0179347, -0.0141466, 0.0104039, 0.012023, 0.0491593, -0.0288722, 0.0644741, -0.0571583, -0.0448436, 0.0155504, 0.0296555, 0.0497946, 0.0543626, -0.0151732, 0.0312108, -0.0146586, -0.0128817, -0.0018097, -0.0346675, -0.0042956, 0.00516369, 0.00948479, 0.00141036, -0.0695081, 0.0258453, -0.0358831, 0.0191185, 0.0705469, -0.0168245, 0.0105833, -0.0309467, -0.0173429, 0.00679792, -0.0930071, -0.0607455, -0.0267286, -0.000862185, -0.00383164, 0.0115042, -0.00201634, 0.0208825, 0.0252693, -0.00596171, -0.0856587, 0.0485282, 0.0180922, -0.0220566, -0.0408328, 0.0284976, 0.0579772, -0.0469201, -0.0558371, -0.0100904, -0.0151976, 0.00572216, -0.0439647, -0.0153275, -0.0817064, 0.0171175, 0.00167688, -0.0555306, -0.00899772, 0.0205408, 0.0114084, 0.0118584, 0.030743, -0.0233728, 0.0352324, -0.00509825, 0.0476974, -0.025406, -0.0152134, -0.00837507, 0.0134512, 0.0279179, -0.0613159, -0.210116, 0.0157261, 0.0173726, -0.0433484, 0.0244509, -0.0213721, -0.0499161, -0.0190523, -0.0505536, -0.00034807, -0.00344056, 0.050826, 0.0131696, 0.00365615, 0.0336945, 0.000382599, 0.0462619, -0.0196368, -0.00584143, -0.0155797, -0.00463558, -0.0668087, 0.0266732, -0.0195291, -0.0121437, 0.00915416, 0.0177658, -3.90648e-05, -0.0594072, 0.00150132, 0.0180518, -0.0478774, -0.0331619, 0.0298936, 0.00897692, 0.0349562, 0.00623362, -0.0554584, 0.0263029, -0.00239249, 0.0267625, -0.0421116, -0.0089069, -0.0171607, 0.0435228, -0.0256827, -0.0553935, -0.0249748, -0.0116364, 0.0453987, -0.00943429, -0.00682323, -0.0374478, -0.00704436, -0.00814869, -0.019148, 0.0368839, 0.0314381, -0.0170571, -0.0354312, -0.0232583, -0.0540318, -0.0772573, -0.0806923, -0.00131631, -0.0279417, -0.0318536, -0.0412348, 0.0105147, 0.0125683, -0.00488161, 0.0674458, -0.0268015, -0.0809354, -0.0227558, -0.0161076, -0.0225841, 0.000607307, -0.000923193, 0.0205466, -0.0413814, -0.0464134, -0.0382923, -0.0225873, -0.00523348, -0.0660919, 0.0548808, -0.0131477, 0.0177424, -0.0082503, 0.0428968, -0.0618056, -0.0371376, 0.0379894, 0.0331375, 0.00108479, 0.0210889, -0.009449, 0.0278067, -0.00384112, 0.0249594, -0.0370634, 0.0018827, -0.0485216, -0.0192962, 0.0339573, -0.0604648, -0.0192103, 0.0610481, -0.00196441, 0.00417631, 0.00826587, 0.0178044, -0.0338128, 0.041095, -0.0419773, 0.0111511, 0.0183286, 0.0270988, -0.0136936, -0.0355216, 0.0414321, -0.0337204, 0.0104129, -0.0413514, 0.0246236, 0.0032131, 0.0411879, -0.00152519, 0.00834147, -0.0108898, 0.0458507, 0.00767149, 0.0158115, 0.0486159, 0.000677128, 0.0188168, -0.0417899, 0.00718917, 0.0386436, -0.0233396, 0.039016, -0.0261093, 0.0277246, 0.00760927, 0.0194646, -0.0327464, -0.0534463, -0.00817692, 0.00899088, -0.0304468, -0.0389323, 0.00138964, -0.068563, -0.0318277, -0.0391431, 0.0793486, -0.0369261, 0.00314684, -0.0543347, 0.0163, -0.032523, -0.00873442, 0.0142842, -0.000335395, 0.0785062, -0.00368084, -0.0285162, -0.0585384, 0.0148438, 0.00996303, 0.025283, 0.00466912, -0.0379747, -0.0312402, 0.0105783, -0.0283614, 0.0320944, 0.00690954, 0.0138507, 0.0483426, -0.00620213, -0.0182599, -0.0109785, 0.0391603, -0.0895736, 0.00704786, -0.0432448, -0.00628598, 0.0294414, -0.0146165, 0.0248053, -0.014032, 0.0135348, -0.0299454, -0.0712555, 0.0197791, 0.0552708, -0.0156012, 0.00453587, 0.00735264, 0.0365039, 0.000557701, -0.0199813, 0.0320858, -0.0647678, 0.0526246, -0.00556777, -0.0187897, 0.000789816, -0.0607881, -0.0520016, -0.0213166, -0.0138355, -0.0152077, -0.033672, -0.0193878, 0.0231228, 0.0156199, -0.0462233, 0.00864113, -0.016369, -0.0333891, -0.0344666, -0.050352, 0.045808, 0.054604, -0.0102991, 0.0583529, -0.00798892, 0.0183406, -0.0743688, -0.0228855, 0.0842119, -0.00229232, -0.015398, -0.0372985, -0.000403822, -0.0265571, 0.0138542, 0.000519519, 0.010103, -0.0396387, -0.0162565, 0.0184576, 0.0136397, -0.03829, 0.0188518, 0.00141432, 0.00269885, -0.0277288, -0.00478118, -0.0408798, 0.00267129, 0.0369562, -0.0358954, -0.0341877, -0.00692984, -0.0146007, -0.0185959, 0.0327975, 0.0166928, -0.00937472, 0.0678522, 0.040836, 0.0109048, -0.033192, 0.014749, 0.0315465, -0.0520517, 0.0166155, -0.0367016, -0.0361581, 0.0132889, 0.0262524, -0.000513194, -0.0192742, -0.0472092, 0.020484, -0.0585343, -0.038887, 0.027219, -0.0181957, 0.00914687, -0.0211561, -0.0343408, 0.00592847, 0.00301473, -0.01737, 0.055488, 0.0147303, 0.0193202, 0.00930932, 0.0690701, -0.0559315, -0.00421222, 0.0420103, 0.0681103, -0.0526146, 0.0191544, -0.0277468, 0.0705887, 0.0284053, -0.00205742, 0.0458553, -0.0122328, -0.00679277, -0.0700396, 0.0204795, 0.0339042, -0.0167774, -0.0644976, 0.0532773, 0.0194671, -0.0128415, 0.0205008, 0.0574721, -0.0137991, -0.0266083, -0.0209429, 0.00316573, -0.00112886, 0.0502081, -0.027611, 0.0170565, 0.0476421, -0.0181632, 0.0367066, 0.00497887, 0.0888281, 0.032766, 0.0545738, -0.00468979, 0.0643928, -0.0357686, -0.0359152, -0.0290054, 0.0104998, -0.0328259, 0.0186467, -0.00260071, 0.0382772, 0.0384711, 0.0395445, -0.0188138, 0.0217212, -0.0111592, -0.00753347, 0.0300507, -0.00333151, 0.0769343, 0.00109964, -0.00358248, -0.0308506, -0.0219969, -0.0195277, 0.00960031, 0.00921237, 0.0146536, -0.00923227, 0.00597347, -0.0323546, 0.0981287, 0.00838638, 0.00447016, 0.050964, 0.019612, -0.00276146, 0.0149172, -0.00077006, -0.0528166, 0.0120142, -0.0341276, 0.0667685, -0.0276565, 0.0346057, 0.0410196, 0.00805251, -0.0185234, -0.00357313, 0.0157613, -0.0263726, -0.0439007, -0.0266643, 0.0167602, -0.0304427, -0.00698665, 0.0358756, 0.00351067, -0.070182, -0.00765159, -0.0260096, -0.00679931, 0.0554207, -0.0550129, -0.0114618, 0.0572032, 0.0456407, 0.0180921, 0.041989, 0.00631331, -0.024956, -0.0633734, 0.0165865, -0.0158081, 0.0656377, -0.0267861, -0.0253589, -0.120928, 0.0457521, 0.039644, 0.0132743, -0.0824937, 0.0527804, -0.0622724, 0.0130503, 0.0567382, 0.0198186, 0.0561768, -0.0220823, -0.0498251, -0.0376711, -0.0231315, 0.0557371, -0.064247, 0.0662012, 0.00347971, -0.0119787, -0.0235818, 0.0264086, -0.0146509, 0.0195022, -0.00435461, -0.00936311, -0.0158259, -0.0647228, 0.0207341, 0.00341112, -0.00195105, -0.0379534, 0.013017, 0.0367623, -0.0122962, 0.0481172, -0.000350114, 0.00301426, -0.00586416, -0.00568411, -0.0754874, 0.0241398, -0.00285175, 0.0182236, 0.0258124, -0.0336019, -0.00651747, -0.037047, -0.017345, 0.0174451, 0.0447473, 0.0305165],
"limit": 10,
"with_payload": true
}

49 changes: 26 additions & 23 deletions infrastructure/aca-with-storage-mount.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

param name string
param location string
param lawClientId string
@secure()
param lawClientSecret string
param lawname string

@description('Number of CPU cores the container can use. Can be with a maximum of two decimals.')
param cpuCore string = '0.25'
param cpuCore string = '1'

@description('Amount of memory (in gibibytes, GiB) allocated to the container up to 4GiB. Can be with a maximum of two decimals. Ratio with CPU cores must be equal to 2.')
param memorySize string = '0.5'
param memorySize string = '2'

@description('Minimum number of replicas that will be deployed')
@minValue(0)
Expand All @@ -23,34 +21,41 @@ param minReplicas int = 0
param maxReplicas int = 1

param storageAccountName string
@secure()
param storageAccountKey string

param fileshareName string

resource law 'Microsoft.OperationalInsights/workspaces@2023-09-01' existing = {
name: lawname
}

resource env 'Microsoft.App/managedEnvironments@2022-03-01'= {
name: 'containerapp-env-${name}'
location: location
properties: {
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: lawClientId
sharedKey: lawClientSecret
customerId: law.properties.customerId
sharedKey: law.listKeys().primarySharedKey
}
}
}
}

var storageName = 'acastorage'
var apikey = guid(resourceGroup().id)

resource stg 'Microsoft.Storage/storageAccounts@2021-02-01' existing = {
name: storageAccountName
}

resource envStorage 'Microsoft.App/managedEnvironments/storages@2022-03-01' = {
parent: env
name: storageName
properties: {
azureFile: {
accessMode: 'ReadWrite'
accountKey: storageAccountKey
accountKey: stg.listKeys().keys[0].value
accountName: storageAccountName
shareName: fileshareName
}
Expand All @@ -59,25 +64,17 @@ resource envStorage 'Microsoft.App/managedEnvironments/storages@2022-03-01' = {

// qdrant container
resource containerApp 'Microsoft.App/containerApps@2023-11-02-preview' = {
name: 'container-app-${name}-qdrant'
name: 'ca-${name}-qdrant'
dependsOn: [
envStorage
]
location: location
properties: {
managedEnvironmentId: env.id
configuration: {
ingress: {
additionalPortMappings: [
{
exposedPort: 6334
external: true
targetPort: 6334
}
]
ingress: {
external: true
targetPort: 6333
exposedPort: 6333
allowInsecure: false
traffic: [
{
Expand All @@ -97,7 +94,7 @@ resource containerApp 'Microsoft.App/containerApps@2023-11-02-preview' = {
]
containers: [
{
name: 'container-app-${name}-qdrant'
name: 'ca-${name}-qdrant'
image: 'qdrant/qdrant:latest'
resources: {
cpu: json(cpuCore)
Expand All @@ -109,6 +106,12 @@ resource containerApp 'Microsoft.App/containerApps@2023-11-02-preview' = {
volumeName: 'externalstorage'
}
]
env: [
{
name: 'QDRANT__SERVICE__API_KEY'
value: apikey
}
]
}
]
scale: {
Expand All @@ -121,7 +124,7 @@ resource containerApp 'Microsoft.App/containerApps@2023-11-02-preview' = {


resource containerApp2 'Microsoft.App/containerApps@2023-11-02-preview' = {
name: 'container-app-${name}-embed'
name: 'ca-${name}-embed'
dependsOn: [
envStorage
]
Expand All @@ -144,7 +147,7 @@ resource containerApp2 'Microsoft.App/containerApps@2023-11-02-preview' = {
template: {
containers: [
{
name: 'container-app-${name}-embed'
name: 'ca-${name}-embed'
image: 'sjkp/blitz-embed:v1'
resources: {
cpu: json(cpuCore)
Expand Down
3 changes: 1 addition & 2 deletions infrastructure/logs.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ resource law 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
}


output clientId string = law.properties.customerId
output clientSecret string = law.listKeys().primarySharedKey
output name string = law.name
6 changes: 2 additions & 4 deletions infrastructure/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ module aca 'aca-with-storage-mount.bicep' = {
scope: rg
name: 'azurecontainer'
params: {
lawClientId: logs.outputs.clientId
lawClientSecret: logs.outputs.clientSecret
lawname: logs.outputs.name
location: location
name: appName
fileshareName: fileshareName
storageAccountKey: storage.outputs.storageAccountKey
storageAccountName: storageAccountName
storageAccountName: storage.outputs.storageAccountName
}
}
3 changes: 3 additions & 0 deletions infrastructure/storage-file-share.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ param fileshareName string

resource fileshare 'Microsoft.Storage/storageAccounts/fileServices/shares@2021-09-01' = {
name: '${storageAccountName}/default/${fileshareName}'
properties: {
shareQuota: 512
}
}
3 changes: 1 addition & 2 deletions infrastructure/storage.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ resource stg 'Microsoft.Storage/storageAccounts@2021-02-01' = {
kind: 'StorageV2'
}

output connectionString string = 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${listKeys(stg.id, stg.apiVersion).keys[0].value};EndpointSuffix=core.windows.net'
output storageAccountKey string = listKeys(stg.id, stg.apiVersion).keys[0].value
output storageAccountName string = stg.name

63 changes: 63 additions & 0 deletions test.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@baseUri = https://ca-sjkpembedding-qdrant.kindrock-b324fec9.northeurope.azurecontainerapps.io
@baseUriEmbedding = https://ca-sjkpembedding-embed.kindrock-b324fec9.northeurope.azurecontainerapps.io
@apiKey = 6e05dbc5-785f-57f2-a1a6-5a219d9e5dda

### create collection

PUT {{baseUri}}/collections/test
Content-Type: application/json
api-key: {{apiKey}}

{
"vectors": {
"size": 768,
"distance": "Cosine"
}
}


### Delete collection

DELETE {{baseUri}}/collections/test
api-key: {{apiKey}}

### Search for machates
POST {{baseUri}}/collections/test/points/search
api-key: {{apiKey}}

< embedding.json

### Generate embedding

POST {{baseUriEmbedding}}
Content-Type: application/json

{
"sent": [
"All technical managers must have hands-on experience. For example, managers of software teams must spend at least 20% of their time coding. Solar roof managers must spend time on the roofs doing installations. Otherwise, they are like a cavalry leader who can't ride a horse or a general who can't use a sword.",
"It's OK to be wrong. Just don't be confident and wrong.",
"Never ask your troops to do something you're not willing to do.",
"The only rules are the ones dictated by the laws of physics. Everything else is a recommendation.",
"When hiring, look for people with the right attitude. Skills can be taught. Attitude requires a brain transplant.",
"Whenever there are problems to solve, don't just meet with your managers. Do a skip level, where you meet with the right below your managers."
],
"model": "/opt/bge-base-en-v1.5-q4_0.gguf",
"batch_size": 6,
"max_len": 64,
"normalise": true
}


### More relistic example
POST {{baseUriEmbedding}}
Content-Type: application/json

{
"sent": [
"hyper-v"
],
"model": "/opt/bge-base-en-v1.5-q4_0.gguf",
"batch_size": 6,
"max_len": 64,
"normalise": true
}

0 comments on commit 1e41842

Please sign in to comment.