- 
                Notifications
    
You must be signed in to change notification settings  - Fork 716
 
Added initial support for app service as a compute environment #9090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 14 commits
      Commits
    
    
            Show all changes
          
          
            18 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f601838
              
                Added initial support for app service as a compute environment
              
              
                davidfowl 75754d0
              
                Rename AzureContainerAppExecutableExtensions to AzureAppServiceComput…
              
              
                davidfowl d377bda
              
                Add playground sample
              
              
                davidfowl de11dd4
              
                Enhance Azure App Service error messages and skip ignored resources i…
              
              
                davidfowl 2517e25
              
                Refactor Azure Cosmos DB configuration to remove access key authentic…
              
              
                davidfowl 8584b0c
              
                Remove Redis package references from Azure App Host project
              
              
                davidfowl c12e359
              
                Remove redis urls
              
              
                davidfowl 6990e1b
              
                Refactor identity handling in Azure App Service environment extension…
              
              
                davidfowl 70ea39b
              
                Remove unused parameter resolution logic for Azure Bicep resources in…
              
              
                davidfowl bca9076
              
                Refactor Key Vault secret handling to streamline resource allocation …
              
              
                davidfowl 94ef997
              
                Added test or AsKeyVaultSecret
              
              
                davidfowl d1f17a4
              
                Normalize Key Vault name generation in AsKeyVaultSecret method for co…
              
              
                davidfowl 655962f
              
                Update Key Vault secret URI handling to use non-versioned URIs for Ap…
              
              
                davidfowl 964202c
              
                Add Azure Bicep modules and update App Service environment references…
              
              
                davidfowl b2cceb5
              
                Moved projects
              
              
                davidfowl 770945d
              
                Update parameter names from 'id' to 'planid' for consistency in Bicep…
              
              
                davidfowl 2ed723d
              
                Update PackageTags in project file for improved clarity and consistency
              
              
                davidfowl 3282b01
              
                Fixed xml
              
              
                davidfowl File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "appHostPath": "../AzureAppService.AppHost/AzureAppService.AppHost.csproj" | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add  I don't understand why this file is even required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, it should be checked in  | 
||
| } | ||
        
          
          
            15 changes: 15 additions & 0 deletions
          
          15 
        
  playground/AzureAppService/AzureAppService.ApiService/AzureAppService.ApiService.csproj
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
| 
     | 
||
| <PropertyGroup> | ||
| <TargetFramework>$(DefaultTargetFramework)</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
| 
     | 
||
| <ItemGroup> | ||
| <AspireProjectOrPackageReference Include="Aspire.Azure.Storage.Blobs" /> | ||
| <AspireProjectOrPackageReference Include="Aspire.Microsoft.EntityFrameworkCore.Cosmos" /> | ||
| <ProjectReference Include="..\..\Playground.ServiceDefaults\Playground.ServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
| 
     | 
||
| </Project> | 
        
          
          
            81 changes: 81 additions & 0 deletions
          
          81 
        
  playground/AzureAppService/AzureAppService.ApiService/Program.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| 
     | 
||
| using Azure.Storage.Blobs; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Newtonsoft.Json; | ||
| 
     | 
||
| var builder = WebApplication.CreateBuilder(args); | ||
| 
     | 
||
| builder.AddServiceDefaults(); | ||
| 
     | 
||
| builder.AddCosmosDbContext<TestCosmosContext>("account", "db"); | ||
| builder.AddAzureBlobClient("blobs"); | ||
| 
     | 
||
| var app = builder.Build(); | ||
| 
     | 
||
| app.MapDefaultEndpoints(); | ||
| 
     | 
||
| app.MapGet("/", () => | ||
| { | ||
| return Results.Content(""" | ||
| <html> | ||
| <body> | ||
| <ul> | ||
| <li><a href="/blobs">Blobs</a></li> | ||
| <li><a href="/cosmos">Cosmos</a></li> | ||
| </ul> | ||
| </body> | ||
| </html> | ||
| """, | ||
| "text/html"); | ||
| }); | ||
| 
     | 
||
| app.MapGet("/blobs", async (BlobServiceClient bsc) => | ||
| { | ||
| var container = bsc.GetBlobContainerClient("mycontainer"); | ||
| await container.CreateIfNotExistsAsync(); | ||
| 
     | 
||
| var blobNameAndContent = Guid.NewGuid().ToString(); | ||
| await container.UploadBlobAsync(blobNameAndContent, new BinaryData(blobNameAndContent)); | ||
| 
     | 
||
| var blobs = container.GetBlobsAsync(); | ||
| 
     | 
||
| var blobNames = new List<string>(); | ||
| 
     | 
||
| await foreach (var blob in blobs) | ||
| { | ||
| blobNames.Add(blob.Name); | ||
| } | ||
| 
     | 
||
| return blobNames; | ||
| }); | ||
| 
     | 
||
| app.MapGet("/cosmos", async (TestCosmosContext context) => | ||
| { | ||
| await context.Database.EnsureCreatedAsync(); | ||
| 
     | 
||
| context.Entries.Add(new EntityFrameworkEntry()); | ||
| await context.SaveChangesAsync(); | ||
| 
     | 
||
| return await context.Entries.ToListAsync(); | ||
| }); | ||
| 
     | 
||
| app.Run(); | ||
| 
     | 
||
| public class Entry | ||
| { | ||
| [JsonProperty("id")] | ||
| public string? Id { get; set; } | ||
| } | ||
| 
     | 
||
| public class TestCosmosContext(DbContextOptions<TestCosmosContext> options) : DbContext(options) | ||
| { | ||
| public DbSet<EntityFrameworkEntry> Entries { get; set; } | ||
| } | ||
| 
     | 
||
| public class EntityFrameworkEntry | ||
| { | ||
| public Guid Id { get; set; } = Guid.NewGuid(); | ||
| } | ||
| 
     | 
        
          
          
            14 changes: 14 additions & 0 deletions
          
          14 
        
  playground/AzureAppService/AzureAppService.ApiService/Properties/launchSettings.json
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:5193", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } | 
        
          
          
            8 changes: 8 additions & 0 deletions
          
          8 
        
  playground/AzureAppService/AzureAppService.ApiService/appsettings.Development.json
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } | 
        
          
          
            9 changes: 9 additions & 0 deletions
          
          9 
        
  playground/AzureAppService/AzureAppService.ApiService/appsettings.json
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } | 
        
          
          
            25 changes: 25 additions & 0 deletions
          
          25 
        
  playground/AzureAppService/AzureAppService.AppHost/AzureAppService.AppHost.csproj
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
                
      
                  davidfowl marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>$(DefaultTargetFramework)</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireHost>true</IsAspireHost> | ||
| <UserSecretsId>9dc69458-f2b4-4306-9dc5-f7b8e398a3a9</UserSecretsId> | ||
| </PropertyGroup> | ||
| 
     | 
||
| <ItemGroup> | ||
| <Compile Include="..\..\KnownResourceNames.cs" Link="KnownResourceNames.cs" /> | ||
| </ItemGroup> | ||
| 
     | 
||
| <ItemGroup> | ||
| <AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.AppService" /> | ||
| <AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.CosmosDB" /> | ||
| <AspireProjectOrPackageReference Include="Aspire.Hosting.Azure.Storage" /> | ||
| <AspireProjectOrPackageReference Include="Aspire.Hosting.AppHost" /> | ||
| 
     | 
||
| <ProjectReference Include="..\AzureAppService.ApiService\AzureAppService.ApiService.csproj" /> | ||
| </ItemGroup> | ||
| 
     | 
||
| </Project> | ||
        
          
          
            55 changes: 55 additions & 0 deletions
          
          55 
        
  playground/AzureAppService/AzureAppService.AppHost/Program.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| 
     | 
||
| using Aspire.Hosting.Azure; | ||
| using Azure.Provisioning.Storage; | ||
| 
     | 
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
| 
     | 
||
| builder.AddAppServiceEnvironment("infra"); | ||
| 
     | 
||
| // Testing secret parameters | ||
| var param = builder.AddParameter("secretparam", "fakeSecret", secret: true); | ||
| 
     | 
||
| // Testing kv secret refs | ||
| var cosmosDb = builder.AddAzureCosmosDB("account") | ||
| .RunAsEmulator(c => c.WithLifetime(ContainerLifetime.Persistent)); | ||
| 
     | 
||
| cosmosDb.AddCosmosDatabase("db"); | ||
| 
     | 
||
| // Testing managed identity | ||
| var storage = builder.AddAzureStorage("storage") | ||
| .ConfigureInfrastructure(infra => | ||
| { | ||
| var storage = infra.GetProvisionableResources().OfType<StorageAccount>().Single(); | ||
| storage.AllowBlobPublicAccess = false; | ||
| }) | ||
| .RunAsEmulator(c => c.WithLifetime(ContainerLifetime.Persistent)); | ||
| var blobs = storage.AddBlobs("blobs"); | ||
| 
     | 
||
| // Testing projects | ||
| builder.AddProject<Projects.AzureAppService_ApiService>("api") | ||
| .WithExternalHttpEndpoints() | ||
| .WithReference(blobs) | ||
| .WithRoleAssignments(storage, StorageBuiltInRole.StorageBlobDataContributor) | ||
| .WithReference(cosmosDb) | ||
| .WithEnvironment("VALUE", param) | ||
| .WithEnvironment(context => | ||
| { | ||
| if (context.Resource.TryGetLastAnnotation<AppIdentityAnnotation>(out var identity)) | ||
| { | ||
| context.EnvironmentVariables["AZURE_PRINCIPAL_NAME"] = identity.IdentityResource.PrincipalName; | ||
| } | ||
| }); | ||
| 
     | 
||
| #if !SKIP_DASHBOARD_REFERENCE | ||
| // 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 | ||
| // or build with `/p:SkipDashboardReference=true`, to test end developer | ||
| // dashboard launch experience, Refer to Directory.Build.props for the path to | ||
| // the dashboard binary (defaults to the Aspire.Dashboard bin output in the | ||
| // artifacts dir). | ||
| builder.AddProject<Projects.Aspire_Dashboard>(KnownResourceNames.AspireDashboard); | ||
| #endif | ||
| 
     | 
||
| builder.Build().Run(); | 
        
          
          
            44 changes: 44 additions & 0 deletions
          
          44 
        
  playground/AzureAppService/AzureAppService.AppHost/Properties/launchSettings.json
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:15687;http://localhost:15688", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:16167", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:17317", | ||
| "ASPIRE_SHOW_DASHBOARD_RESOURCES": "true" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15688", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16167", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:17318", | ||
| "ASPIRE_SHOW_DASHBOARD_RESOURCES": "true", | ||
| "ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true" | ||
| } | ||
| }, | ||
| "generate-manifest": { | ||
| "commandName": "Project", | ||
| "launchBrowser": true, | ||
| "dotnetRunMessages": true, | ||
| "commandLineArgs": "--publisher manifest --output-path aspire-manifest.json", | ||
| "applicationUrl": "http://localhost:15888", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16157" | ||
| } | ||
| } | ||
| } | ||
| } | 
        
          
          
            39 changes: 39 additions & 0 deletions
          
          39 
        
  playground/AzureAppService/AzureAppService.AppHost/account.module.bicep
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| @description('The location for the resource(s) to be deployed.') | ||
| param location string = resourceGroup().location | ||
| 
     | 
||
| resource account 'Microsoft.DocumentDB/databaseAccounts@2024-08-15' = { | ||
| name: take('account-${uniqueString(resourceGroup().id)}', 44) | ||
| location: location | ||
| properties: { | ||
| locations: [ | ||
| { | ||
| locationName: location | ||
| failoverPriority: 0 | ||
| } | ||
| ] | ||
| consistencyPolicy: { | ||
| defaultConsistencyLevel: 'Session' | ||
| } | ||
| databaseAccountOfferType: 'Standard' | ||
| disableLocalAuth: true | ||
| } | ||
| kind: 'GlobalDocumentDB' | ||
| tags: { | ||
| 'aspire-resource-name': 'account' | ||
| } | ||
| } | ||
| 
     | 
||
| resource db 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2024-08-15' = { | ||
| name: 'db' | ||
| location: location | ||
| properties: { | ||
| resource: { | ||
| id: 'db' | ||
| } | ||
| } | ||
| parent: account | ||
| } | ||
| 
     | 
||
| output connectionString string = account.properties.documentEndpoint | ||
| 
     | 
||
| output name string = account.name | 
        
          
          
            15 changes: 15 additions & 0 deletions
          
          15 
        
  playground/AzureAppService/AzureAppService.AppHost/api-identity.module.bicep
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| @description('The location for the resource(s) to be deployed.') | ||
| param location string = resourceGroup().location | ||
| 
     | 
||
| resource api_identity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = { | ||
| name: take('api_identity-${uniqueString(resourceGroup().id)}', 128) | ||
| location: location | ||
| } | ||
| 
     | 
||
| output id string = api_identity.id | ||
| 
     | 
||
| output clientId string = api_identity.properties.clientId | ||
| 
     | 
||
| output principalId string = api_identity.properties.principalId | ||
| 
     | 
||
| output principalName string = api_identity.name | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.