- 
                Notifications
    You must be signed in to change notification settings 
- Fork 715
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
Changes from 8 commits
f601838
              75754d0
              d377bda
              de11dd4
              2517e25
              8584b0c
              c12e359
              6990e1b
              70ea39b
              bca9076
              94ef997
              d1f17a4
              655962f
              964202c
              b2cceb5
              770945d
              2ed723d
              3282b01
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| } | ||
| 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> | 
| 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(); | ||
| } | ||
|  | 
| 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" | ||
| } | ||
| } | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } | 
| 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> | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|  | ||
| #pragma warning disable ASPIREACADOMAINS001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
|         
                  davidfowl marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| 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(); | ||
| 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" | ||
| } | ||
| } | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|  | ||
| <PropertyGroup> | ||
| <TargetFramework>$(DefaultTargetFramework)</TargetFramework> | ||
| <IsPackable>true</IsPackable> | ||
| <PackageTags>aspire integration hosting azure</PackageTags> | ||
|          | ||
| <Description>Azure app service resource types for .NET Aspire.</Description> | ||
| <PackageIconFullPath>$(SharedDir)Azure_256x.png</PackageIconFullPath> | ||
| 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. Does app service have its own icon? | ||
| <SuppressFinalPackageVersion>true</SuppressFinalPackageVersion> | ||
| </PropertyGroup> | ||
|  | ||
| <ItemGroup> | ||
| <Compile Include="$(SharedDir)BicepFunction2.cs" Link="Provisioning\Utils\BicepFunction2.cs" /> | ||
| </ItemGroup> | ||
|  | ||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Provisioning.AppService" /> | ||
| <PackageReference Include="Azure.Provisioning.ContainerRegistry" /> | ||
| <ProjectReference Include="..\Aspire.Hosting.Azure\Aspire.Hosting.Azure.csproj" /> | ||
| <ProjectReference Include="..\Aspire.Hosting.Azure.ContainerRegistry\Aspire.Hosting.Azure.ContainerRegistry.csproj" /> | ||
| </ItemGroup> | ||
|  | ||
| </Project> | ||
Uh oh!
There was an error while loading. Please reload this page.