diff --git a/src/Aspire.Hosting.Azure.AppService/README.md b/src/Aspire.Hosting.Azure.AppService/README.md new file mode 100644 index 00000000000..9557ad3ace6 --- /dev/null +++ b/src/Aspire.Hosting.Azure.AppService/README.md @@ -0,0 +1,88 @@ +# Aspire.Hosting.Azure.AppService library + +Provides extension methods and resource definitions for a .NET Aspire AppHost to configure Azure App Service. + +## Getting started + +### Prerequisites + +- Azure subscription - [create one for free](https://azure.microsoft.com/free/) + +### Install the package + +In your AppHost project, install the .NET Aspire Azure App Service Hosting library with [NuGet](https://www.nuget.org): + +```dotnetcli +dotnet add package Aspire.Hosting.Azure.AppService +``` + +## Usage example + +In the _AppHost.cs_ file of `AppHost`, add an Azure App Service Environment and publish your project as an Azure App Service website: + +```csharp +var builder = DistributedApplication.CreateBuilder(args); + +var appServiceEnvironment = builder.AddAzureAppServiceEnvironment("env"); + +builder.AddProject("webapp") + .WithExternalHttpEndpoints() + .PublishAsAzureAppServiceWebsite((infrastructure, site) => + { + // Configure the App Service website + site.SiteConfig.IsWebSocketsEnabled = true; + }); +``` + +## Azure App Service constraints + +When deploying to Azure App Service, the following constraints apply: + +- **External endpoints only**: App Service only supports external endpoints. All endpoints must be configured using `WithExternalHttpEndpoints()`. +- **HTTP/HTTPS only**: Only HTTP and HTTPS endpoints are supported. Other protocols are not supported. +- **Single endpoint**: App Service supports only a single target port. Resources with multiple external endpoints with different target ports are not supported. + +### Publishing compute resources to Azure App Service + +The `PublishAsAzureAppServiceWebsite` extension method is used to configure a compute resource (such as a project) to be published as an Azure App Service website when deploying to Azure. This method allows you to customize the App Service website configuration using the Azure Provisioning SDK. + +```csharp +builder.AddProject("api") + .WithHttpEndpoint() + .WithExternalHttpEndpoints() + .PublishAsAzureAppServiceWebsite((infrastructure, site) => + { + // Customize the App Service website settings + site.SiteConfig.IsWebSocketsEnabled = true; + site.SiteConfig.MinTlsVersion = SupportedTlsVersions.Tls1_2; + }); +``` + +### Adding an Azure App Service Environment + +The Azure App Service Environment resource creates the underlying infrastructure needed to host your applications, including: + +- An Azure App Service Plan +- An Azure Container Registry for storing container images +- A managed identity for accessing the container registry +- Optionally, the Aspire Dashboard as an Azure App Service website + +```csharp +var appServiceEnvironment = builder.AddAzureAppServiceEnvironment("env"); +``` + +By default, the Aspire Dashboard is included in the App Service Environment. To disable the dashboard, use the `WithDashboard` extension method: + +```csharp +var appServiceEnvironment = builder.AddAzureAppServiceEnvironment("env") + .WithDashboard(enable: false); +``` + +## Additional documentation + +* https://learn.microsoft.com/azure/app-service/ +* https://github.com/dotnet/aspire/tree/main/src/Components/README.md + +## Feedback & contributing + +https://github.com/dotnet/aspire