Skip to content

Commit

Permalink
Generate ACA app infrastructure
Browse files Browse the repository at this point in the history
Regen manifest

Prep for multiple tcp ports

PR feedback

Rules?

Fixes

Moar fixes

Made the endpoint mapping more robust
- Added container app context that has a reference to all of the processing contexts. It will handle caching processing contexts.
- Resovle host and port based on endpoint mappings

Fix bug with additional mapping

Move everything to the contexts
- Rename ProcessingContext to ContainerAppContext. Make everything private

Fixed the formatting

More gen

Better formatting

Full bicep gen

Better parameter names

More gen

Updates

Fix formatting

Pick the first one

Don't throw if there are more than 5 additional endpoints

Do port allocation in the bicep generation

Fixes

Order by group index.

Fix and skip a test

Fixed test

Added target port resolution

Fix AI resource

Fixed AppInsights issues, deleted old files
  • Loading branch information
davidfowl committed May 4, 2024
1 parent 31ce95b commit 39c458c
Show file tree
Hide file tree
Showing 66 changed files with 3,429 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
// The .NET Foundation licenses this file to you under the MIT license.
var builder = DistributedApplication.CreateBuilder(args);

var storage = builder.AddAzureStorage("storage").RunAsEmulator(container =>
{
container.WithDataBindMount();
});
builder.AddAzureProvisioning();

var storage = builder.AddAzureStorage("storage");

var blobs = storage.AddBlobs("blobs");

builder.AddProject<Projects.AzureStorageEndToEnd_ApiService>("api")
.WithExternalHttpEndpoints()
.WithReference(blobs);
ProjectResource p = default!;

var project = builder.AddProject<Projects.AzureStorageEndToEnd_ApiService>("api")
.WithHttpEndpoint(name: "api", targetPort: 1034)
.WithReference(blobs)
.WithEnvironment(context =>
{
context.EnvironmentVariables["URL"] = p.GetEndpoint("api");
});

p = project.Resource;

// This project is only added in playground projects to support development/debugging
// of the dashboard. It is not required in end developer code. Comment out this code
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
param location string
param tags object = {}
param storage_outputs_blobEndpoint string
param default_identity_outputs_id string
param default_identity_outputs_clientId string
param containerAppEnv_outputs_id string
param containerRegistry_outputs_loginServer string
param containerRegistry_outputs_mid string
param api_containerImage string
resource containerApp 'Microsoft.App/containerApps@2023-05-02-preview' = {
name: 'api'
location: location
tags: tags
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${default_identity_outputs_id}': {}
}
}
properties: {
environmentId: containerAppEnv_outputs_id
configuration: {
activeRevisionsMode: 'Single'
ingress: {
external: false
targetPort: 8080
transport: 'http'
additionalPortMappings: [
{
external: false
targetPort: 1034
}
]
}
registries: [
{
server: containerRegistry_outputs_loginServer
identity: containerRegistry_outputs_mid
}
]
secrets: [
{ name: 'connectionstrings--blobs', value: storage_outputs_blobEndpoint }
]
}
template: {
scale: {
minReplicas: 1
}
containers: [
{
image: api_containerImage
name: 'api'
env: [
{ name: 'OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES', value: 'true' }
{ name: 'OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES', value: 'true' }
{ name: 'ASPNETCORE_FORWARDEDHEADERS_ENABLED', value: 'true' }
{ name: 'ConnectionStrings__blobs', secretRef: 'connectionstrings--blobs' }
{ name: 'URL', value: 'http://api:1034' }
{ name: 'AZURE_CLIENT_ID', value: default_identity_outputs_clientId }
]
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
param location string
param tags object = {}
param parameters object = {}
param inputs object = {}
module storage 'storage.module.bicep' = {
name: 'storage'
params: {
location: location
principalId: default_identity.outputs.principalId
principalType: 'ServicePrincipal'
}
}

module containerAppEnv 'containerappenv.bicep' = {
name: 'containerAppEnv'
params: {
location: location
}
}

module containerRegistry 'containerregistry.bicep' = {
name: 'containerRegistry'
params: {
location: location
}
}

module default_identity 'default-identity.bicep' = {
name: 'default-identity'
params: {
location: location
}
}

module api_containerApp 'api-containerapp.bicep' = {
name: 'api-containerApp'
params: {
location: location
storage_outputs_blobEndpoint: storage.outputs.blobEndpoint
default_identity_outputs_id: default_identity.outputs.id
default_identity_outputs_clientId: default_identity.outputs.clientId
containerAppEnv_outputs_id: containerAppEnv.outputs.id
containerRegistry_outputs_loginServer: containerRegistry.outputs.loginServer
containerRegistry_outputs_mid: containerRegistry.outputs.mid
api_containerImage: inputs.api.containerImage
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"type": "azure.bicep.v0",
"path": "storage.module.bicep",
"params": {
"principalId": "",
"principalType": ""
"principalId": "{default-identity.outputs.principalId}",
"principalType": "ServicePrincipal"
}
},
"blobs": {
Expand All @@ -21,22 +21,56 @@
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true",
"OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory",
"ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true",
"ConnectionStrings__blobs": "{blobs.connectionString}"
"ConnectionStrings__blobs": "{blobs.connectionString}",
"URL": "{api.bindings.api.url}"
},
"bindings": {
"http": {
"scheme": "http",
"protocol": "tcp",
"transport": "http",
"external": true
"transport": "http"
},
"https": {
"scheme": "https",
"protocol": "tcp",
"transport": "http"
},
"api": {
"scheme": "http",
"protocol": "tcp",
"transport": "http",
"external": true
"targetPort": 1034
}
}
},
"containerAppEnv": {
"type": "azure.bicep.v0",
"path": "containerappenv.bicep"
},
"containerRegistry": {
"type": "azure.bicep.v0",
"path": "containerregistry.bicep"
},
"default-identity": {
"type": "azure.bicep.v0",
"path": "default-identity.bicep"
},
"api-containerApp": {
"type": "azure.bicep.v0",
"path": "api-containerapp.bicep",
"params": {
"storage_outputs_blobEndpoint": "{storage.outputs.blobEndpoint}",
"default_identity_outputs_id": "{default-identity.outputs.id}",
"default_identity_outputs_clientId": "{default-identity.outputs.clientId}",
"containerAppEnv_outputs_id": "{containerAppEnv.outputs.id}",
"containerRegistry_outputs_loginServer": "{containerRegistry.outputs.loginServer}",
"containerRegistry_outputs_mid": "{containerRegistry.outputs.mid}",
"api_containerImage": "{api.containerImage}"
}
},
"app": {
"type": "azure.bicep.v0",
"path": "app.bicep"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
param location string
param tags object = {}

var resourceToken = uniqueString(resourceGroup().id)

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: 'law-${resourceToken}'
location: location
properties: {
sku: {
name: 'PerGB2018'
}
}
tags: tags
}

resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' = {
name: 'cae-${resourceToken}'
location: location
properties: {
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
}
tags: tags
}

output id string = containerAppEnvironment.id
output logAnalyticsWorkspaceId string = logAnalyticsWorkspace.id
output defaultDomain string = containerAppEnvironment.properties.defaultDomain
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
param location string
param tags object = {}
param sku string = 'Basic'
param adminUserEnabled bool = true

var resourceToken = uniqueString(resourceGroup().id)

resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-07-01' = {
name: replace('acr${resourceToken}', '-', '')
location: location
sku: {
name: sku
}
properties: {
adminUserEnabled: adminUserEnabled
}
tags: tags
}

resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: 'mi-${resourceToken}'
location: location
tags: tags
}

resource caeMiRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(containerRegistry.id, managedIdentity.id, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d'))
scope: containerRegistry
properties: {
principalId: managedIdentity.properties.principalId
principalType: 'ServicePrincipal'
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d')
}
}

output mid string = managedIdentity.id
output loginServer string = containerRegistry.properties.loginServer
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
param location string
param tags object = {}

resource identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: 'cai-${uniqueString(resourceGroup().id)}'
location: location
tags: tags
}

output id string = identity.id
output clientId string = identity.properties.clientId
output principalId string = identity.properties.principalId
output name string = identity.name
1 change: 1 addition & 0 deletions playground/TestShop/AppHost/AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\src\Aspire.Dashboard\Aspire.Dashboard.csproj" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting.Azure\Aspire.Hosting.Azure.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting.RabbitMQ\Aspire.Hosting.RabbitMQ.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting.Redis\Aspire.Hosting.Redis.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting.PostgreSQL\Aspire.Hosting.PostgreSQL.csproj" IsAspireProjectResource="false" />
Expand Down
2 changes: 2 additions & 0 deletions playground/TestShop/AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var builder = DistributedApplication.CreateBuilder(args);

builder.AddAzureProvisioning();

var catalogDb = builder.AddPostgres("postgres")
.WithPgAdmin()
.AddDatabase("catalogdb");
Expand Down
48 changes: 48 additions & 0 deletions playground/TestShop/AppHost/apigateway-containerapp.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
param location string
param tags object = {}
param containerAppEnv_outputs_id string
param containerRegistry_outputs_loginServer string
param containerRegistry_outputs_mid string
param apigateway_containerImage string
resource containerApp 'Microsoft.App/containerApps@2023-05-02-preview' = {
name: 'apigateway'
location: location
tags: tags
properties: {
environmentId: containerAppEnv_outputs_id
configuration: {
activeRevisionsMode: 'Single'
ingress: {
external: false
targetPort: 8080
transport: 'http'
}
registries: [
{
server: containerRegistry_outputs_loginServer
identity: containerRegistry_outputs_mid
}
]
}
template: {
scale: {
minReplicas: 1
}
containers: [
{
image: apigateway_containerImage
name: 'apigateway'
env: [
{ name: 'OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES', value: 'true' }
{ name: 'OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES', value: 'true' }
{ name: 'ASPNETCORE_FORWARDEDHEADERS_ENABLED', value: 'true' }
{ name: 'services__basketservice__http__0', value: 'http://basketservice' }
{ name: 'services__basketservice__https__0', value: 'https://basketservice' }
{ name: 'services__catalogservice__http__0', value: 'http://catalogservice' }
{ name: 'services__catalogservice__https__0', value: 'https://catalogservice' }
]
}
]
}
}
}
Loading

0 comments on commit 39c458c

Please sign in to comment.