Skip to content

Commit

Permalink
deploy to azure with azd (autogenhub#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostapetan authored Apr 11, 2024
1 parent 65a262b commit 9168d11
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 63 deletions.
4 changes: 2 additions & 2 deletions samples/gh-flow/azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
name: ai-dev-team
services:
gh-flow:
project: "src/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj"
project: "src/Microsoft.AI.DevTeam"
language: csharp
host: containerapp
docker:
context: ../../../
context: ../../../../
6 changes: 6 additions & 0 deletions samples/gh-flow/infra/app/gh-flow.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ resource cosmos 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' existing = {
}

var contributorRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
var wehbookSecret = uniqueString(resourceGroup().id)

resource rgContributor 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(subscription().id, resourceGroup().id, contributorRole)
Expand Down Expand Up @@ -89,6 +90,10 @@ module app '../core/host/container-app.bicep' = {
name: 'GithubOptions__InstallationId'
value: githubAppInstallationId
}
{
name: 'GithubOptions__WebhookSecret'
value: wehbookSecret
}
{
name: 'AzureOptions__SubscriptionId'
value: subscription().subscriptionId
Expand Down Expand Up @@ -162,3 +167,4 @@ module app '../core/host/container-app.bicep' = {
output SERVICE_TRANSLATE_API_IDENTITY_PRINCIPAL_ID string = app.outputs.identityPrincipalId
output SERVICE_TRANSLATE_API_NAME string = app.outputs.name
output SERVICE_TRANSLATE_API_URI string = app.outputs.uri
output WEBHOOK_SECRET string = wehbookSecret
45 changes: 0 additions & 45 deletions samples/gh-flow/infra/app/sk-func.bicep

This file was deleted.

60 changes: 60 additions & 0 deletions samples/gh-flow/infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@ param environmentName string
@description('Primary location for all resources')
param location string

@secure()
param githubAppKey string
param githubAppId string
param githubAppInstallationId string
param openAIServiceType string
param openAIServiceId string
param openAIDeploymentId string
param openAIEmbeddingId string
param openAIEndpoint string
@secure()
param openAIKey string

param applicationInsightsDashboardName string = ''
param applicationInsightsName string = ''
param logAnalyticsName string = ''
param resourceGroupName string = ''
param storageAccountName string = ''
param containerAppsEnvironmentName string = ''
param containerRegistryName string = ''
param ghFlowServiceName string = ''
param cosmosAccountName string = ''


var aciShare = 'acishare'
Expand Down Expand Up @@ -85,6 +99,46 @@ module qdrant './core/database/qdrant/qdrant-aca.bicep' = {
}
}

// The application database
module cosmos './app/db.bicep' = {
name: 'cosmos'
scope: rg
params: {
accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}'
databaseName: 'devteam'
location: location
tags: tags
}
}

module ghFlow './app/gh-flow.bicep' = {
name: 'gh-flow'
scope: rg
params: {
name: !empty(ghFlowServiceName) ? ghFlowServiceName : '${abbrs.appContainerApps}ghflow-${resourceToken}'
location: location
tags: tags
identityName: '${abbrs.managedIdentityUserAssignedIdentities}ghflow-${resourceToken}'
applicationInsightsName: monitoring.outputs.applicationInsightsName
containerAppsEnvironmentName: containerApps.outputs.environmentName
containerRegistryName:containerApps.outputs.registryName
storageAccountName: storage.outputs.name
aciShare: aciShare
githubAppId: githubAppId
githubAppInstallationId: githubAppInstallationId
githubAppKey: githubAppKey
openAIDeploymentId: openAIDeploymentId
openAIEmbeddingId: openAIEmbeddingId
openAIEndpoint: openAIEndpoint
openAIKey: openAIKey
openAIServiceId: openAIServiceId
openAIServiceType: openAIServiceType
qdrantEndpoint: 'https://${qdrant.outputs.fqdn}'
rgName: rg.name
cosmosAccountName: cosmos.outputs.accountName
}
}


// App outputs
output APPLICATIONINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString
Expand All @@ -98,3 +152,9 @@ output AZURE_RESOURCE_GROUP_NAME string = rg.name
output AZURE_FILESHARE_NAME string = aciShare
output AZURE_FILESHARE_ACCOUNT_NAME string = storage.outputs.name
output QDRANT_ENDPOINT string = 'https://${qdrant.outputs.fqdn}'
output WEBHOOK_SECRET string = ghFlow.outputs.WEBHOOK_SECRET

// Data outputs
output AZURE_COSMOS_ENDPOINT string = cosmos.outputs.endpoint
output AZURE_COSMOS_CONNECTION_STRING_KEY string = cosmos.outputs.connectionStringKey
output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName
27 changes: 27 additions & 0 deletions samples/gh-flow/infra/main.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@
"location": {
"value": "${AZURE_LOCATION}"
},
"githubAppKey": {
"value": "${GH_APP_KEY}"
},
"githubAppId": {
"value": "${GH_APP_ID}"
},
"githubAppInstallationId": {
"value": "${GH_APP_INST_ID}"
},
"openAIServiceType": {
"value": "${OAI_SERVICE_TYPE}"
},
"openAIServiceId": {
"value": "${OAI_SERVICE_ID}"
},
"openAIDeploymentId": {
"value": "${OAI_DEPLOYMENT_ID}"
},
"openAIEmbeddingId": {
"value": "${OAI_EMBEDDING_ID}"
},
"openAIEndpoint": {
"value": "${OAI_ENDPOINT}"
},
"openAIKey": {
"value": "${OAI_KEY}"
},
"principalId": {
"value": "${AZURE_PRINCIPAL_ID}"
}
Expand Down
14 changes: 7 additions & 7 deletions samples/gh-flow/src/Microsoft.AI.DevTeam/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 5274
EXPOSE 11111
EXPOSE 30000

ENV ASPNETCORE_URLS=http://+:5274

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG configuration=Release
COPY . .
RUN dotnet restore "src/apps/gh-flow/gh-flow.csproj"
WORKDIR "/src/apps/gh-flow"
RUN dotnet build "gh-flow.csproj" -c $configuration -o /app/build
RUN dotnet restore "samples/gh-flow/src/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj"
WORKDIR "samples/gh-flow/src/Microsoft.AI.DevTeam"
RUN dotnet build "Microsoft.AI.DevTeam.csproj" -c $configuration -o /app/build

FROM build AS publish
ARG configuration=Release
RUN dotnet publish "gh-flow.csproj" -c $configuration -o /app/publish
RUN dotnet publish "Microsoft.AI.DevTeam.csproj" -c $configuration -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "gh-flow.dll"]
ENTRYPOINT ["dotnet", "Microsoft.AI.DevTeam.dll"]
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<PackageReference Include="Azure.Identity" Version="1.11.0-beta.1" />

<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.4.1" />
<PackageReference Include="Microsoft.Orleans.Serialization.NewtonsoftJson" Version="8.0.0" />


</ItemGroup>
Expand Down
62 changes: 57 additions & 5 deletions samples/gh-flow/src/Microsoft.AI.DevTeam/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Connectors.Qdrant;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using System.Configuration;
using Orleans.Configuration;
using Orleans.Serialization;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<WebhookEventProcessor, GithubWebHookProcessor>();
Expand Down Expand Up @@ -85,13 +86,64 @@

builder.Host.UseOrleans(siloBuilder =>
{

siloBuilder.UseLocalhostClustering()
siloBuilder.UseDashboard(x => x.HostSelf = true);
siloBuilder.Services.AddSerializer( sb => {
sb.AddNewtonsoftJsonSerializer(isSupported: t => true);
});
if (builder.Environment.IsDevelopment())
{
siloBuilder.UseLocalhostClustering()
.AddMemoryStreams("StreamProvider")
.AddMemoryGrainStorage("PubSubStore")
.AddMemoryGrainStorage("messages");
siloBuilder.UseInMemoryReminderService();
siloBuilder.UseDashboard(x => x.HostSelf = true);
siloBuilder.UseInMemoryReminderService();
}
else
{
var cosmosDbconnectionString = builder.Configuration.GetValue<string>("AzureOptions:CosmosConnectionString");
siloBuilder.Configure<ClusterOptions>(options =>
{
options.ClusterId = "ai-dev-cluster";
options.ServiceId = "ai-dev-cluster";
});
siloBuilder.Configure<SiloMessagingOptions>(options =>
{
options.ResponseTimeout = TimeSpan.FromMinutes(3);
options.SystemResponseTimeout = TimeSpan.FromMinutes(3);
});
siloBuilder.Configure<ClientMessagingOptions>(options =>
{
options.ResponseTimeout = TimeSpan.FromMinutes(3);
});
siloBuilder.UseCosmosClustering( o =>
{
o.ConfigureCosmosClient(cosmosDbconnectionString);
o.ContainerName = "devteam";
o.DatabaseName = "clustering";
o.IsResourceCreationEnabled = true;
});

siloBuilder.UseCosmosReminderService( o =>
{
o.ConfigureCosmosClient(cosmosDbconnectionString);
o.ContainerName = "devteam";
o.DatabaseName = "reminders";
o.IsResourceCreationEnabled = true;
});
siloBuilder.AddCosmosGrainStorage(
name: "messages",
configureOptions: o =>
{
o.ConfigureCosmosClient(cosmosDbconnectionString);
o.ContainerName = "devteam";
o.DatabaseName = "persistence";
o.IsResourceCreationEnabled = true;
});
//TODO: replace with EventHub
siloBuilder
.AddMemoryStreams("StreamProvider")
.AddMemoryGrainStorage("PubSubStore");
}

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public async Task CreateBranch(string org, string repo, string branch)
try
{
var ghRepo = await _ghClient.Repository.Get(org, repo);
if (ghRepo.Size == 0)
var contents = await _ghClient.Repository.Content.GetAllContents(org, repo);
if (!contents.Any())
{
// Create a new file and commit it to the repository
var createChangeSet = await _ghClient.Repository.Content.CreateFile(
Expand All @@ -90,7 +91,6 @@ public async Task CreateBranch(string org, string repo, string branch)
new CreateFileRequest("Initial commit", "# Readme")
);
}

await _ghClient.Git.Reference.CreateBranch(org, repo, branch, ghRepo.DefaultBranch);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"FilesAccountName":"",
"FilesAccountKey":"",
"SandboxImage" : "mcr.microsoft.com/dotnet/sdk:7.0",
"ManagedIdentity": ""
"ManagedIdentity": "",
"CosmosConnectionString":""
},
"OpenAIOptions" : {
"ServiceType":"AzureOpenAI",
Expand Down
4 changes: 4 additions & 0 deletions src/Microsoft.AI.Agents/Abstractions/Event.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
namespace Microsoft.AI.Agents.Abstractions
{
[GenerateSerializer]
public class Event
{
[Id(0)]
public string Message { get; set; }
[Id(1)]
public Dictionary<string, string> Data { get; set; }
[Id(2)]
public string Type { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.AI.Agents/Microsoft.AI.Agents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>

<PackageReference Include="Microsoft.SemanticKernel" Version="1.6.2" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="8.0.0" />
</ItemGroup>

</Project>

0 comments on commit 9168d11

Please sign in to comment.