Skip to content

Commit

Permalink
optimized for local dev provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
bradygaster committed Feb 28, 2024
1 parent 69ac1bb commit 1bb02c7
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 35 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ jobs:
runs-on: ubuntu-latest

env:
# uncomment these to use federated
# AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
# AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}

# uncomment this to use client credentials

AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}

steps:
Expand Down Expand Up @@ -67,10 +63,12 @@ jobs:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }}

- name: Deploy App
run: azd deploy --no-prompt
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }}
14 changes: 4 additions & 10 deletions AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
var pubsub = // a redis container the app will use for simple messaging to the frontend
builder.AddRedis("pubsub");

var qdrant = // the qdrant container the app will use for vector search
var qdrant = // the qdrant container the app will use for vector search
builder.AddContainer("qdrant", "qdrant/qdrant")
.WithServiceBinding(containerPort: 6333, name: "qdrant", scheme: "http");
.WithEndpoint(hostPort: 6333, name: "qdrant", scheme: "http");

var histdb = // a postgres container the app will use for history storage
builder.AddPostgres("postgres")
Expand Down Expand Up @@ -34,17 +34,11 @@
var backend = // the main .net app that will perform augmentation and vector search
builder.AddProject<Projects.Backend>("backend")
.WithEnvironment("QDRANT_ENDPOINT", qdrant.GetEndpoint("qdrant"))
.WithReference(histsvc)
.WithReference(pubsub)
.WithReference(blobs)
.WithReference(queues);
.WithReference(histsvc).WithReference(pubsub).WithReference(blobs).WithReference(queues);

_ = // a blazor server app that will provide a web ui for the app
builder.AddProject<Projects.Frontend>("frontend")
.WithReference(histsvc)
.WithReference(backend)
.WithReference(pubsub)
.WithReference(queues);
.WithReference(histsvc).WithReference(backend).WithReference(pubsub).WithReference(queues);

builder.Build().Run();

Expand Down
2 changes: 1 addition & 1 deletion Backend/Backend.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<SelfContained>True</SelfContained>
<UserSecretsId>593a3d33-6654-4298-84ff-e022ff449746</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="System.Linq.Async" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.QDrant " />
<PackageReference Include="Microsoft.SemanticKernel" />
Expand Down
4 changes: 0 additions & 4 deletions Backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
builder.Services.AddSingleton<UrlListAugmentor>();
builder.Services.AddSingleton<LiveUpdateService>();
builder.Services.AddHostedService<AugmentationWorker>();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.MapDefaultEndpoints();

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.MapGet("/", () => Results.Ok("Backend is up"))
Expand Down
3 changes: 0 additions & 3 deletions Backend/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5160",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand All @@ -23,7 +22,6 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7153;http://localhost:5160",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand All @@ -32,7 +30,6 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
1 change: 1 addition & 0 deletions Frontend/Frontend.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<SelfContained>True</SelfContained>
<UserSecretsId>cf44a86e-6145-4059-8aab-4967a5e9d0f2</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion Frontend/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7154;http://localhost:5161",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
1 change: 0 additions & 1 deletion HistoryDb/HistoryDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
1 change: 0 additions & 1 deletion HistoryService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

builder.AddServiceDefaults();
builder.AddNpgsqlDbContext<HistoryDbContext>("historydb");
builder.Services.AddSwaggerGen();

var app = builder.Build();
app.MapDefaultEndpoints();
Expand Down
16 changes: 16 additions & 0 deletions infra/keyvault.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ param tags object = {}
@description('String representing the ID of the logged-in user ')
param principalId string = ''

@description('String representing the name of the KeyVault Key representing the Azure OpenAI API Key secret')
param openAIKeyName string = ''

@description('String representing the name of the Azure OpenAI resource')
param openAIName string = ''

var resourceToken = uniqueString(resourceGroup().id)

// create a keyvault to store openai secrets
Expand All @@ -21,5 +27,15 @@ module keyvault 'core/security/keyvault.bicep' = {
}
}

// create secret to store openai api key
module openAIKey 'core/security/keyvault-secret.bicep' = {
name: 'openai-key'
params: {
name: openAIKeyName
keyVaultName: keyvault.name
secretValue: listKeys(resourceId(subscription().subscriptionId, resourceGroup().name, 'Microsoft.CognitiveServices/accounts', openAIName), '2023-05-01').key1
}
}

output AZURE_KEY_VAULT_ENDPOINT string = keyvault.outputs.endpoint
output AZURE_KEY_VAULT_NAME string = keyvault.name
24 changes: 15 additions & 9 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ targetScope = 'subscription'
@description('Name of the environment that can be used as part of naming resource convention, the name of the resource group for your application will use this name, prefixed with rg-')
param environmentName string

@description('If true, only the OpenAI resources are created.')
param isInLocalDevMode bool = true

@minLength(1)
@description('The location used for all deployed resources')
param location string
Expand Down Expand Up @@ -48,10 +51,12 @@ module keyvault 'keyvault.bicep' = {
location: location
tags: tags
principalId: principalId
openAIKeyName: openAIKeyName
openAIName: ai.outputs.AZURE_OPENAI_NAME
}
}

module resources 'resources.bicep' = {
module resources 'resources.bicep' = if (!isInLocalDevMode) {
scope: rg
name: 'resources'
params: {
Expand All @@ -66,14 +71,15 @@ module resources 'resources.bicep' = {
}
}

output AZURE_CLIENT_ID string = resources.outputs.MANAGED_IDENTITY_CLIENT_ID
output MANAGED_IDENTITY_CLIENT_ID string = resources.outputs.MANAGED_IDENTITY_CLIENT_ID
output AZURE_CONTAINER_REGISTRY_ENDPOINT string = resources.outputs.AZURE_CONTAINER_REGISTRY_ENDPOINT
output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID string = resources.outputs.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID
output AZURE_CONTAINER_APPS_ENVIRONMENT_ID string = resources.outputs.AZURE_CONTAINER_APPS_ENVIRONMENT_ID
output AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN string = resources.outputs.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN
output SERVICE_BINDING_AZUREBLOBS_ENDPOINT string = resources.outputs.SERVICE_BINDING_AZUREBLOBS_ENDPOINT
output SERVICE_BINDING_AZUREQUEUES_ENDPOINT string = resources.outputs.SERVICE_BINDING_AZUREQUEUES_ENDPOINT
output AZURE_CLIENT_ID string = ((!isInLocalDevMode) ? resources.outputs.MANAGED_IDENTITY_CLIENT_ID : '')
output MANAGED_IDENTITY_CLIENT_ID string = ((!isInLocalDevMode) ? resources.outputs.MANAGED_IDENTITY_CLIENT_ID : '')
output AZURE_CONTAINER_REGISTRY_ENDPOINT string = ((!isInLocalDevMode) ? resources.outputs.AZURE_CONTAINER_REGISTRY_ENDPOINT : '')
output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID string = ((!isInLocalDevMode) ? resources.outputs.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID : '')
output AZURE_CONTAINER_APPS_ENVIRONMENT_ID string = ((!isInLocalDevMode) ? resources.outputs.AZURE_CONTAINER_APPS_ENVIRONMENT_ID : '')
output AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN string = ((!isInLocalDevMode) ? resources.outputs.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN : '')
output SERVICE_BINDING_AZUREBLOBS_ENDPOINT string = ((!isInLocalDevMode) ? resources.outputs.SERVICE_BINDING_AZUREBLOBS_ENDPOINT : '')
output SERVICE_BINDING_AZUREQUEUES_ENDPOINT string = ((!isInLocalDevMode) ? resources.outputs.SERVICE_BINDING_AZUREQUEUES_ENDPOINT : '')

output AZURE_KEY_VAULT_ENDPOINT string = keyvault.outputs.AZURE_KEY_VAULT_ENDPOINT
output AZURE_OPENAI_KEY_NAME string = ai.outputs.AZURE_OPENAI_KEY_NAME
output AZURE_OPENAI_ENDPOINT string = ai.outputs.AZURE_OPENAI_ENDPOINT
Expand Down
3 changes: 3 additions & 0 deletions infra/main.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"principalId": {
"value": "${AZURE_PRINCIPAL_ID}"
},
"isInLocalDevMode": {
"value": "true"
},
"runningOnGh": {
"value": "${GITHUB_ACTIONS}"
},
Expand Down

0 comments on commit 1bb02c7

Please sign in to comment.